I am trying to run tests on specific browser versions using a Dockerized Selenium Grid.
Webdriver implementation:
public static WebDriver get(String mode, String browser, String version) {
WebDriver driver = null;
Map<String, Object> prefs = new HashMap<>();
prefs.put("download.default_directory", Constants.getDownloadpath());
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
options.addArguments("--blink-settings=imagesEnable=false");
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", Constants.getDownloadpath());
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv");
FirefoxOptions option = new FirefoxOptions();
String remoteUrl = "http://localhost:4444/wd/hub";
if (browser.equalsIgnoreCase("chrome")) {
options.addArguments("--blink-settings=imagesEnabled=false");
if (mode.equalsIgnoreCase("remote")) {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setVersion(version);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
try {
driver = new RemoteWebDriver(new URL(remoteUrl), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
} else {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver(options);
}
}
}
The method receives the browser version as an argument. Suppose I have two Chrome versions, v94.0 and v96.0, and I am using the parameters mode="remote", browser="chrome", and version="94.0". However, the tests seem to be running on a random node, even though I’ve specified the version explicitly.
Selenium Grid docker-compose.yml
version: "3"
services:
chrome:
image: selenium/node-chrome:4.1.2-20220217
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
chrome96:
image: selenium/node-chrome:96.0.4664.93
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
chrome94:
image: selenium/node-chrome:94.0-chromedriver-94.0
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
edge:
image: selenium/node-edge:4.1.2-20220217
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
firefox:
image: selenium/node-firefox:4.1.2-20220217
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
firefox42:
image: selenium/node-firefox:4.2.2-20220609
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
selenium-hub:
image: selenium/hub:4.1.2-20220217
container_name: selenium-hub
ports:
- "4442:4442"
- "4443:4443"
- "4444:4444"
Can you help me understand why the tests are not running on the specified browser version, and what I can do to resolve this issue?
Below is a screenshot from the Selenium Grid hub showing the 2 Chrome nodes in question
2
Answers
Added labels and this did the job for me.
The Selenium Grid uses the capabilities specified during the RemoteWebDriver creation to decide which node to route your tests to.
In your case, you have set the version capability which is intended to specify the browser version.
You can add your specific arguments as
NODE_CAPABILITIES
within theenvironment
configuration for your Selenium Chrome Node.So if you pass your arguments as
browserName=chrome
andversion=94.0
when executing your test, if the chrome 94.0 node is set up like so, the hub should route your request to that node, see below: