How to start remote Safari Technology Preview from Selenese Runner Java - selenium

I have here a Selenium Hub and a Selenium Node with Config:
{
"capabilities":
[
{
"browserName": "safari",
"version": "10",
"maxInstances": 1,
"webdriver.safari.driver": "/Applications/Safari\ Technology\ Preview.app/Contents/MacOS/safaridriver"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 1,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "<IP>:4444",
"role": "node",
}
If I try to start a test from a Maven project with the code:
SafariOptions safariOptions = new SafariOptions();
safariOptions.setUseTechnologyPreview(true);
safariOptions.setUseCleanSession(true);
DesiredCapabilities capabilities = DesiredCapabilities.safari();
capabilities.setCapability(SafariOptions.CAPABILITY, safariOptions);
RemoteWebDriver driver = new RemoteWebDriver(
new URL("http://172.31.4.70:4444/wd/hub"), capabilities);
System.out.println(capabilities.toString());
System.out.println(safariOptions.toJson().toString());
driver.manage().window().maximize();
driver.get("https://check24.de/kredit");
//Close the browser
driver.quit();
On the MAC, the Safari Technology Preview starts no problem.
The Selenium Hub log:
14:02:03.874 INFO - Got a request to create a new session: Capabilities [{browserName=safari, safari.options={technologyPreview=true, port=0, cleanSession=true}, version=, platform=MAC}]
14:02:03.898 INFO - Trying to create a new session on test slot {seleniumProtocol=WebDriver, webdriver.safari.driver=/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver, browserName=safari, maxInstances=1, version=10, platform=MAC}
Now I'd like to start that with Selenese Runner Java with
java -jar C:\selenium\selenese-runner.jar --driver remote --remote-url http://<ip>:4444/wd/hub --remote-platform MAC --remote-browser "safari" --define "safari.options={technologyPreview=true, port=0, cleanSession=true}" --screenshot-on-fail C:\selenium\screenshot --max-time 600 --baseurl %1 %2
The log on the Seleniu Hub is the same:
14:05:26.088 INFO - Got a request to create a new session: Capabilities [{browserName=safari, safari.options={technologyPreview=true, port=0, cleanSession=true}, version=, platform=MAC}]
14:05:26.102 INFO - Trying to create a new session on test slot {seleniumProtocol=WebDriver, webdriver.safari.driver=/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver, browserName=safari, maxInstances=1, version=10, platform=MAC}
But a Safari (NOT Technology Preview) instante starts on the Selenium Node.
The different is that one send the safari.option with safariOption Class and one send it with plain text.
I cannot understand why there is defferent.
Have you any Idea?
Thanks!
Lian Shen

Related

Cannot execute protractor tests using headless chrome on Selenium Grid nodes

I'm using Selenium server 3.8.1, with the hub and 2 nodes.
The hub and each node are executed on different machines.
Currently, I can launch the tests and they're working fine. But, I'm not able to make the headless mode run.
My config JSON only contains the capabilities object.
{
"capabilities":
[{
"browserName": "chrome",
"maxInstances": 3,
"seleniumProtocol": "WebDriver",
"chromeOptions": {
"args": [
"--headless",
"--disable-gpu",
"--window-size=1920x1080"]
}}]
}
I launch the selenium nodes using a .bat that contains the following command:
"C:\Program Files\Java\jre1.8.0_181\bin\java" -jar C:\jobs\selenium-node\selenium-server-standalone-3.8.1.jar -role node -hub http://172.16.0.5:5555/grid/register -port 5558 -nodeConfig config.json -maxSession 3
The selenium node works fine and appears on the selenium grid UI. Also, the capabilities of the chrome driver include the --headless and other parameters:
....
capabilities: Capabilities {browserName: chrome, chromeOptions: {args: [--headless, --disable-gpu, --window-size=1920x1080]}, maxInstances: 3, platform: XP, se:CONFIG_UUID: cdc21610-4c47-4d23-9478-a20..., seleniumProtocol: WebDriver}
....
On the protractor.conf file I have these capabilities, that work when I run the tests locally.
seleniumAddress:'http://172.16.0.5:5555/wd/hub',
getPageTimeout: 120000,
allScriptsTimeout: 120000,
ignoreUncaughtExceptions: true,
chromeOnly:true,
directConnect: false,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
"javascriptEnabled": true,
"acceptSslCerts": true,
"browserName": "chrome",
"chromeOptions": {
"args": [ "--headless", "--disable-gpu", "--window-size=1920,1080"]
}
},
But, when I launch the tests, the chrome driver isn't executed on headless mode. Works fine, but the different windows keep appearing.
Environment details:
chromedriver version: 2.36.540470
chrome version: 69.0.3497.100
As per your question/comment update you are using:
chromedriverVersion: '2.36.540470, chrome version' => '69.0.3497.100'
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.36
Release Notes of chromedriver=2.36 clearly mentions the following :
Supports Chrome v63-65
You are using chrome=69.0
Release Notes of ChromeDriver v2.42 clearly mentions the following :
Supports Chrome v68-70
So there is a clear mismatch between the ChromeDriver v2.36 and the Chrome Browser v69.0
Solution
Upgrade Selenium to current levels Version 3.14.0.
Upgrade ChromeDriver to current ChromeDriver v2.42 level.
Keep Chrome version between Chrome v68-70 levels. (as per ChromeDriver v2.42 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.

'Connection refused! Is selenium server started?\n' while running Nightwatch.js tests against Selenium Grid

I use Nightwatch-Cucumber based on Nightwatch.js to automate my tests. And now I want to use Selenium Grid with a Selenium hub and several Selenium nodes to execute my tests.
These are my current dependencies I actually use:
"devDependencies": {
"chromedriver": "2.37.0",
"cucumber": "3.0.2",
"geckodriver": "1.11.0",
"nightwatch": "0.9.19",
"nightwatch-cucumber": "9.0.0",
"selenium-server-standalone-jar": "3.9.1",
},
And this is my nightwatch.conf.js:
const config = {
globals_path: "globals.js",
output_folder: "reports",
custom_commands_path: "commands",
// custom_assertions_path: 'assertions',
live_output: false,
page_objects_path: "pageobjects",
disable_colors: false,
selenium: {
start_process: true,
server_path: seleniumServer.path,
host: "127.0.0.1",
port: 4444
},
test_settings: {
default: {
launch_url: "http://mywebsite.com"
},
firefox_grid: {
selenium_host: "127.0.0.1",
selenium_port: 4444,
desiredCapabilities: {
browserName: "firefox"
}
selenium: {
start_process: false
}
}
}
};
module.exports = config;
So, and these are the steps I executed to realize everything:
1. Start the Selenium Hub on localhost
java -jar selenium-server-standalone-3.9.1.jar -port 4444 -role hub
2. Start the Selenium Node on localhost
java -jar selenium-server-standalone-3.9.1.jar -port 5555 -role node
3. Start the Nightwatch tests
./node_modules/.bin/nightwatch --env firefox_grid --tag=myCucumberTag
Current result:
I get an error while executing the Nightwatch tests and I don't know why. It looks like this:
{ Error: Unhandled "error" event. ([object Object])
at ClientManager.emit (events.js:185:19)
at Nightwatch.<anonymous> (/Users/GRme/projects/Aservo/DP/lcm2/testautomation/end2end-web-tests/node_modules/nightwatch/lib/runner/clientmanager.js:68:10)
at Object.onceWrapper (events.js:316:30)
at emitOne (events.js:115:13)
at Nightwatch.emit (events.js:210:7)
at HttpRequest.<anonymous> (/Users/GRme/projects/Aservo/DP/lcm2/testautomation/end2end-web-tests/node_modules/nightwatch/lib/index.js:501:10)
at emitThree (events.js:135:13)
at HttpRequest.emit (events.js:216:7)
at IncomingMessage.<anonymous> (/Users/GRme/projects/Aservo/DP/lcm2/testautomation/end2end-web-tests/node_modules/nightwatch/lib/http/request.js:172:16)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1057:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
context:
{ message: 'Connection refused! Is selenium server started?\n',
data: { value: [Object], status: 33 } } }
The request to the Selenium hub seems to be successful from Nightwatch:
21:50:52.393 INFO - Got a request to create a new session: Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true}
21:50:52.399 INFO - Trying to create a new session on test slot {seleniumProtocol=WebDriver, se:CONFIG_UUID=037e48a7-b5bc-44f2-a25b-e85c752095a7, browserName=chrome, maxInstances=5, platformName=MAC, platform=MAC}
And the request also was navigated to the Selenium node:
2018-05-03 21:50:52.418:INFO:osjshC.ROOT:qtp1300393335-22: org.openqa.selenium.remote.server.WebDriverServlet-49d904ec: Initialising WebDriverServlet
21:50:52.450 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession#31a65f95
21:50:52.454 INFO - /session: Executing POST on /session (handler: BeginSession)
21:50:52.546 INFO - Capabilities are: Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true}
21:50:52.548 INFO - Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
So, what I'm doing wrong and how can I fix it? Is it maybe a problem with the Nightwatch.js and/or Selenium Server Standalone Version?
This error message...
message: 'Connection refused!
...implies that the Selenium Grid Node was unable to initiate/spawn a new WebClient i.e. Web Browsing session.
Your main issue is in the command being used to start / initialize Selenium Grid Node. The Selenium Grid Node should be started with the desired WebDriver variant as an argument as follows :
Start the Selenium Grid Hub (default on port 4444):
java -jar selenium-server-standalone-3.9.1.jar -role hub
Start the Selenium Grid Node (default on port 5555):
java -Dwebdriver.chrome.driver=C:/path/to/chromedriver.exe -jar selenium-server-standalone-3.9.1.jar -role node -hub http://localhost:4444/grid/register
You can find a similar detailed discussion in Connection refused! Is selenium server started nightwatch on edge

Launch Safari on Mac node from Windows PC with Selenium RemoteWebDriver and Grid

I'm trying to fire off a test to my iMac from my Windows PC.
I have downloaded and installed the webdriver addon for Safari and I have established a connection to my Windows based Selenium Grid hub.
When I try to run my test I receive an error for an OperaDriver:
org.openqa.selenium.WebDriverException: The best matching driver provider org.openqa.selenium.opera.OperaDriver can't create a new driver instance for Capabilities [{browserName=safari, safari.options={port=0, cleanSession=true}, version=9, platform=MAC}]
Current Setup:
Windows PC:
java -jar selenium-server-standalone-2.53.0.jar -role hub -port 4445
Mac:
java -jar selenium-server-standalone-2.53.0.jar -role node -nodeConfig node1Config.json
node1Config:
{
"capabilities": [
{
"browserName": "safari",
"acceptSslCerts": true,
"javascriptEnabled": true,
"takeScreenshot": false,
"browser-version": "9",
"platform": "MAC",
"maxInstances": 5,
"cleanSession": true
}
],
"configuration": {
"_comment": "Configuration for Node",
"cleanUpCycle": 2000,
"timeout": 30000,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"port": 5568,
"hubHost": "MyNetworkIpWasHere",
"register": true,
"hubPort": 4445,
"maxSessions": 5
}
}
Java to launch test:
DesiredCapabilities capabilities = DesiredCapabilities.safari();
capabilities.setPlatform(Platform.MAC);
capabilities.setBrowserName("safari");
capabilities.setVersion("9");
webDriver = new RemoteWebDriver(new URL("http://myipwashere:4445/wd/hub"), capabilities);
Edit: There are 5 safari nodes available on my grid, none are being used.
I must be overlooking something, any help would be greatly appreciated!
Thanks in advance.
After much trial and error, the URL being passed to the remotewebdriver was incorrect only for Safari. Hopefully this will help someone that has a similar problem in the future.
Thanks RemcoW for all of your help.

WebDriver grid configuration throws error

I have the following setup:
I am running a grid hub on my local pc with the following config:
java -jar selenium-server-standalone-2.42.0.jar -role hub -grid1Yml grid_configuration.yml
the config looks like this:
hub:
port: 4444
remoteControlPollingIntervalInSeconds: 180
sessionMaxIdleTimeInSeconds: 300
newSessionMaxWaitTimeInSeconds: 600
environments:
- name: "Firefox on Windows"
browser: "*firefox"
...
I am starting the node via
java -jar selenium-server -standalone-2.42.0.jar -role node -hub http://localhost:4444/grid/register -port 8888 -browser "browserName=Firefox on windows,maxInstances=1,version=1,platform=WINDOWS"
My Test setup looks like this:
public static void main(String[] args) throws MalformedURLException {
System.setProperty("webdriver.ie.driver","C:\\IEDriverServer.exe");
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setBrowserName("*firefox");
RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL("http://127.0.0.1:4444" + "/wd/hub"), cap);
}
If i run my test i get the following error:
Exception in thread "main" org.openqa.selenium.WebDriverException: Error forwarding
the new session webdriver new session JSON response body did not contain a session ID
Command duration or timeout: 946 milliseconds
Build info: version: '2.41.0', revision: '3192d8a6c4449dc285928ba024779344f5423c58', time: '2014-03-27 11:29:39'
System info: host: 'CL-CNU416C97F', ip: '10.11.112.158', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_55'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
In the webdriver node i get the important error:
Exception: The path to the driver executable must be set by the webdriver.ie.driver system property...
I have set this property via java and in my windows environment. I do not know why i am still getting this error message.
UPDATE
If i use the grid2 config file (json), how is it possible to set an individual browser by name on each host.
Example:
hub:
port: 4444
remoteControlPollingIntervalInSeconds: 180
sessionMaxIdleTimeInSeconds: 300
newSessionMaxWaitTimeInSeconds: 600
environments:
- name: "MyFireFox on MyMachine1"
browser: "*firefox"
- name: "MyFireFox on MyMachine2"
browser: "*firefox"
If i use this hub config i can start a node by saying it is a "MyFireFox on MyMachine1" Browser. The attribute browser is telling webdriver to use Firefox on the system
If i now use the grid2 config json, i have the following
{
"capabilities":
[
{
"browserName": "MyFireFox on MyMachine1",
"platform": "WINDOWS",
"maxInstances": 1
},
but this will not work, because i think the browserName is what browser was in grid1 config.
this is config from my .bat files. also, why do you change your node port to 8888 ? try to remove '-port 8888' and check again
for hub:
java -jar path_to_selenium-server-standalone-2.41.0.jar -role hub
for node:
java -jar path_to_selenium-server-standalone-2.41.0.jar -role node -hub http://localhost:4444/grid/register -browser browserName=firefox, platform=WINDOWS
here is my json and bat file which 100% works
{
"capabilities":
[
{
"browserName": "firefox",
"platform": "WINDOWS",
"maxInstances": 1
},
{
"browserName": "internet explorer",
"version": "10",
"platform": "WINDOWS",
"maxInstances": 1
}
],
"configuration":
{
"nodeTimeout":120,
"port":5555,
"hubPort":4444,
"hubHost":"192.168.3.104",
"nodePolling":2000,
"registerCycle":10000,
"register":true,
"cleanUpCycle":2000,
"timeout":30000,
"maxSession":1
}
}
and bat to start node from json
java -jar selenium-server-standalone-2.41.0.jar -role node -nodeConfig nodeConfig_win7.json
also in system PATH you should add path to folder with drivers for browsers

Error while registering node in selenium grid

I am getting below error while starting node for selenium grid-
Default driver org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}]
does not match with current platform: MAC
My local system that is hub contains MAC and FIREFOX
Below the configuration of my node(VM).My scripts are on my local machine that is hub-
{
"class": "org.openqa.grid.common.RegistrationRequest",
"capabilities": [
{
"seleniumProtocol": "WebDriver",
"browserName": "firefox",
"version": "25.0.1",
"maxInstances": 1,
"platform" : "LINUX"
}
],
}
Please suggest needful.
There might be two obvious errors:
In your code, you state Platform as Linux but you are running on MAC
The same might be on the node setup. If you run node on mac and then request for Internet Explorer on Windows, it will be simply skipped, hence there is no node running on Windows...