How to setup custom browser versions for selenium grid? - selenium

Setup
We have a selenium grid where all nodes are completely identical except one. All the identical nodes run windows 10, have basic chrome, IE, edge browsers, and run on MST. The exception runs IE, chrome, and edge, but they are set to look like it is in the UK, and runs GMT+0 most of the year (except DST of course then it runs BST). This changes date formats and such and is used to test that dates are formatted properly and that documents on our system reflect accurate times in their own timezone. The browsers on the UK node all have custom browser versions declared in their node_XXXX.json file for selenium grid.
Issue
We lost our hub server a while back, and after rebuilding we can no longer get the IE, EDGE, and Firefox browsers to work on the UK server. We used to use custom browser versions for the Uk browsers eg: instead of "version":11 it is "version":"11.eu" to denote that we wanted to run on the special server. Chrome works fine with this model. However, IE is giving an error:
OpenQA.Selenium.WebDriverException : Error forwarding the new session cannot find : Capabilities {browserName: internet explorer, browserVersion: 11.eu, platformName: windows, se:ieOptions: {enablePersistentHover: true, ie.ensureCleanSession: true, nativeEvents: true}}
Attempted Solutions
We have already tried to change the version number (It used to say 9.eu, legacy from when we were running IE9). We have also tried "updating" IE to version 11 again. Nothing has worked or allowed the driver to connect.
Question
How do we get our UK IE browser to work on the selenium grid again? We have many tests failing simply because they cannot connect to a driver instance. Any help would be appreciated, thanks!
Reference
For reference, here is our node_XXXX.json file:
{
"capabilities": [
{
"seleniumProtocol": "WebDriver",
"browserName": "firefox",
"maxInstances": 1,
"version": "17.eu",
"platform": "WINDOWS"
},
{
"seleniumProtocol": "WebDriver",
"browserName": "internet explorer",
"maxInstances": 1,
"version": "11.eu",
"platform": "windows"
},
{
"seleniumProtocol": "WebDriver",
"browserName": "chrome",
"maxInstances": 1,
"version": "77.eu",
"platform": "WINDOWS"
}
],
"loadedFromFile":
"node_5555.json",
"proxy": "com.groupon.seleniumgridextras.grid.proxies.SetupTeardownProxy",
"servlets": [],
"maxSession": 3,
"port": 5555,
"register": true,
"unregisterIfStillDownAfter": 10000,
"hubPort": 4444,
"hubHost": "test-slum01.ndtest.local",
"registerCycle": 5000,
"nodeStatusCheckTimeout": 10000,
"custom": {},
"downPollingLimit": 0
}
And this is the code that calls the remote web driver:
case "iehta9UK":
var ieUkOptions = new InternetExplorerOptions();
ieUkOptions.EnsureCleanSession = true;
ieUkOptions.BrowserVersion = "11.eu";
return IS_REMOTE_RUN ? CreateRemoteWebDriver(ieUkOptions) : new InternetExplorerDriver(ieUkOptions);
This is the strictly US IE code that works fine:
case "IE":
case "ie":
case "InternetExplorer":
case "iehta11":
var ieOptions = new InternetExplorerOptions();
ieOptions.EnsureCleanSession = true;
return IS_REMOTE_RUN ? CreateRemoteWebDriver(ieOptions) : new InternetExplorerDriver(ieOptions);

Aha! We figured it out. We had made the changes to the node_XXXX.json file shown above, but had not restarted the selenium grid service.
Make sure you restart the server after making changes to the json file for them to take affect.

Related

How to Run Parallel Appium Test With Selenium Grid Only By Specifying Platform

I am running parallel robot framework Appium tests using pabot. Below are my config files:
configDevice1.json
{
"capabilities":[
{
"platformName": "Android",
"platformVersion": "9.0",
"browserName": "Android-Huawei-Matepad",
"deviceName": "Huawei Matepad",
"udid": "902xxxxxxx",
"appActivity":"com.app.MainActivity",
"appPackage":"com.app.preview",
"noReset":false,
"automationName":"uiautomator2",
"groups":"device",
"maxInstances": 1
}
],
"configuration":
{
"url":"http://127.0.0.1:4724/wd/hub",
"cleanUpCycle":2500,
"timeout":30000,
"maxSession": 1,
"register": true,
"registerCycle": 1000,
"hubPort": 4444,
"hubHost": "localhost"
}
}
configDevice2.json
{
"capabilities":[
{
"platformName": "Android",
"platformVersion": "9.0",
"browserName": "Android-Samsung",
"deviceName": "Android Samsung",
"udid": "111xxxxxxx",
"appActivity":"com.app.MainActivity",
"appPackage":"com.app.preview",
"noReset":false,
"automationName":"uiautomator2",
"groups":"device",
"maxInstances": 1
}
],
"configuration":
{
"url":"http://127.0.0.1:4724/wd/hub",
"cleanUpCycle":2500,
"timeout":30000,
"maxSession": 1,
"register": true,
"registerCycle": 1000,
"hubPort": 4444,
"hubHost": "localhost"
}
}
I started the two Appium nodes in separate process:
appium --nodeconfig configDevice1.json -p 4723 -bp 5723
appium --nodeconfig configDevice2.json -p 4724 -bp 5724
The parallel test works fine if I define the udid on the desired capabilities. However, I am looking for a way to run parallel test without having to specify any udid. For instance, I want to run parallel tests on all devices with platform of Android.
When I run the parallel tests only with capabilities of platformName=Android, all tests run only on one device, conflicting each session from another.
I can see Appium is retrieving connected devices, but then only proceed selecting the first device from that list. This happens in both Appium sessions (Hence making tests failure because it tries to override an existing session)
[debug] [ADB] Connected devices: [{"udid":"111xxxxxxx","state":"device"},{"udid":"902xxxxxxx","state":"device"}]
[AndroidDriver] Using device: 111xxxxxxx
Is there anything one can do to make tests parallel on platform information available on Selenium grid nodes?
Thanks!
Silly me. The config.json value set should be platform and version. It works well now!

Selenium: Session externalKey not available

The Selenium Grid Hub I am running displays this error message whenever a Robot Framework automation test (kicked off by a Jenkins job) requests a Chrome browser from the Hub:
Session [(null externalkey)] not available and is not among the last
1000 terminated sessions.
I've spent hours searching and trying proposed solutions with no luck.
Running a Linux server as a Selenium Grid Hub and a windows server as a Selenium Grid Node. Have tried each node with versions 3.0.1, 3.5.3, 3.13.0, and 3.141.59 of the selenium-server-standalone-<version>.jar files. A third server runs Jenkins.
The Hub appears to be config'd properly because this works fine:
http://10.1.10.231:4444/grid/console
I've also run the jar files at the command line with -debug at the end but no further information is displayed. Have also tried -Dselenium.LOGGER.level=WARNING on the "java side" of the command line with no further information displayed than using -debug.
We have another set of servers with the same config that runs just fine.
Anyone have an idea of what this message is indicating?
Nitty-gritty follows.
Grid Hub:
java -jar -Xms1024m -Xmx2048m selenium-server-standalone-3.141.59.jar -role hub -hubConfig ./hub-config.json
hub-config.json:
{
"port": 4444,
"newSessionWaitTimeout": -1,
"servlets" : [],
"withoutServlets": [],
"custom": {},
"capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
"throwOnCapabilityNotPresent": true,
"cleanUpCycle": 5000,
"role": "hub",
"debug": false,
"browserTimeout": 360,
"timeout": 1800
}
Grid Node:
SET CHROMEDRIVER=.\bin\chromedriver_win32-v2.37\chromedriver.exe
SET IEDRIVER=.\bin\IEDriverServer.exe
SET FFDRIVER=.\bin\geckodriver-v0.11.1-win32\geckodriver.exe
START "SeleniumNode" java -Xms1024m -Xmx2048m ^
-Dwebdriver.gecko.driver=%FFDRIVER% ^
-Dwebdriver.ie.driver=%IEDRIVER% ^
-Dwebdriver.chrome.driver=%CHROMEDRIVER% -Dwebdriver.chrome.args="--disable-extensions" ^
-jar .\bin\selenium-server-standalone-3.141.59.jar -role node -nodeConfig .\node-config.json
node-config.json:
{
"capabilities":
[
{
"browserName": "firefox",
"maxInstances": 5,
"platform": "WINDOWS",
"seleniumProtocol": "WebDriver"
},
{
"browserName": "chrome",
"maxInstances": 5,
"platform": "WINDOWS",
"seleniumProtocol": "WebDriver"
},
{
"browserName": "internet explorer",
"maxInstances": 5,
"platform": "WINDOWS",
"seleniumProtocol": "WebDriver"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "http://10.1.10.231:4444",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {},
"browserTimeout": 0,
"timeout": 1800,
"cleanUpCycle": 2000
}
Figured this one out! Hopefully it will help others who have reported this error message and not received a solution.
As is most often the case with an issue like this, especially when there's a known-working setup right beside the broken instance, it was an (embarrassingly) silly config issue. The Robot tests were pointing to this URL to get a browser:
http://10.1.10.75:4444/wd/hub/static/resource/hub.html
and it should have been pointing to this path:
http://10.1.10.75:4444/wd/hub
At least it was an easy fix.

Setting the Firefox profile when using Selenium and Firefox Portable

I'm in a setup, in which I need to use Firefox Portable 38.7.1 for my Selenium tests (version 2.53.0). Everything works fine, but now I need to configure a proxy.
I configured it in the default profile (it gets saved in ${FF_PORTABLE_PATH}/Data/profile/prefs.js)
user_pref("network.proxy.http", "proxyHost");
user_pref("network.proxy.http_port", proxyPort);
user_pref("network.proxy.share_proxy_settings", true);
user_pref("network.proxy.ssl", "proxyHost");
user_pref("network.proxy.ssl_port", 51854);
user_pref("network.proxy.type", 1);
...
When starting the browser manually, this works fine. However, when triggered by Selenium an anonymous profile is created and used, which doesn't have my proxy settings.
I tried to specify the profile when starting the node.
At first I tried using -Dwebdriver.firefox.profile:
java -jar selenium-server-standalone-2.53.0.jar -role node -Dwebdriver.firefox.profile=default
Then I tried to use the default profile as a template using -firefoxProfileTemplate:
java -jar selenium-server-standalone-2.53.0.jar -role node -firefoxProfileTemplate "${FF_PORTABLE_PATH}/Data" -nodeConfig ...
I also created a new profile (using the ProfilistPortable plugin) and specified it on startup of the node (with the webdriver.firefox.profile-parameter).
In all cases the Selenium node opens up Firefox Portable with a "clean" anonymous profile without my proxy settings.
Can anyone help me how to get this setup working with Firefox Portable? I don't really need separate profiles. As long as I can force Selenium to use a profile, which has the proxy configured, I'm fine.
Here's my nodeConfig:
{
"capabilities": [
{
"browserName": "firefox",
"version": "38.7.1",
"firefox_binary": "${FF_PORTABLE_PATH}\\FirefoxPortable.exe",
"platform": "WINDOWS",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
}
],
"configuration": {
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 1,
"port": 5550,
"host": "ip",
"register": true,
"registerCycle": 5000,
"hubHost": "localhost",
"hubPort": 4440
}
}
I use ${FF_PORTABLE_PATH} in the examples above. In reality this (fully qualified) path is hardcoded in all my settings.
I had the same issue. Digging into selenium code I was able to find a solution.
FirefoxBinary binary = new FirefoxBinary(new File(portablePath.trim()));
File profile_dir = new File(portablePath.trim().replace("FirefoxPortable.exe", "/Data/profile"));
fp = new FirefoxProfile(profile_dir);
dc.setCapability(FirefoxDriver.PROFILE, fp);
driver = new FirefoxDriver( binary , fp, dc);

is it possible to run a selenium test using multiple different browsers at once?

I have a suite of tests that involve multiple users logging into a service. We are currently using selenium grid to allow up to 5 sessions being run at once for Firefox and Chrome, however we can only run 1 Internet Explorer session.
one workaround is to create multiple VMs but that's not ideal.
Ultimately I'd like to be able to run multiple IE sessions at once but the preferred solution for now is to use multiple browsers at once.
So:
User A logs into IE8
User B logs into Chrome
User C logs into Firefox
user A communicates with User B&C
is that doable as a feature file? is TestNg the way to go here? we are currently using JUnit
...however we can only run 1 Internet Explorer session
You can configure this yourself. In your nodeConfig.json file, specify something like:
{
"capabilities":
[
{
"browserName": "firefox",
"version": "3.6",
"platform": "WINDOWS",
"maxInstances": 5
},
{
"browserName": "internet explorer",
"version": "8",
"platform": "WINDOWS",
"maxInstances": 5
}
],
"configuration": {
"nodeTimeout":120,
"port":5555,
"hubPort":4444,
"hubHost":"localhost",
"nodePolling":2000,
"registerCycle":10000,
"register":true,
"cleanUpCycle":2000,
"timeout":30000,
"maxSession":XXXXX,
}
}

Setting up a node on a VM

I have my selenium all configured but seem to be having issues getting it to launch the browser on my windows VM. I think it's because I haven't haven't included the correct path to the driver. Currently it stands as...
java -jar .\selenium-server-standalone-2.39.0.jar -role node -port 1001 -hub http://xxx.xxx.xx.xxx:4444/grid/register
After reading online I assumed it's cause I'm missing the following...
-Dwebdriver.ie.driver="C:\selenium\IEDriverServer.exe"
I've tried various different ways to include this path into the above statement but keep getting 'poorly formatted Java property setting (I expect to see '=') -Dwebdriver: Usage: java -jar selenium-server.jar [-interactive] [options]'
if anyone could show me the correct format I'd really appreciate it.
Thanks.
According to documentation, you can use a system property:
System.setProperty("webdriver.ie.driver", "C:\selenium\IEDriverServer.exe")
Of course this path would have be the correct on the remote machine!
If you use Maven for your builds, then the Selenium binary downloader might interest you.
I would suggest running the node and having the node load a .json config file that looks something like this.
{
"capabilities":
[
{
"browserName": "firefox",
"acceptSslCerts": true,
"javascriptEnabled": true,
"takesScreenshot": false,
"firefox_profile": "",
"browser-version": "31",
"platform": "WINDOWS",
"maxInstances": 5
},
{
"browserName": "chrome",
"maxInstances": 5,
"platform": "WINDOWS"
},
{
"browserName": "internetExplorer",
"maxInstances": 1,
"platform": "WINDOWS"
}
],
"configuration":
{
"_comment" : "This is configuration for the grid node 1.",
"cleanUpCycle": 2000,
"timeout": 30000,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"port": 5555,
"host": ip,
"Dwebdriver.chrome.driver=C:\\Selenium\\chromedriver.exe": "",
"Dwebdriver.ie.driver=C:\\Selenium\\IEDriverServer.exe": "",
"register": true,
"hubPort": 4444,
"maxSessions": 5
}
}