Codeception - Can't connect to Webdriver (Acceptance Test) - selenium

I can access url and create sessions:
http://localhost:4444/wd/hub/static/resource/hub.html
but when i execute ./codecept run i get an error, but i have Selenium Server running:
[ConnectionException] Can't connect to Webdriver at http://127.0.0.1:4444/wd/hub. Please make sure that Selenium Server or PhantomJS is running.
To execute Selenium Server, i used this command:
java -Dwebdriver.gecko.driver=./geckodriver -jar "selenium-server-standalone-3.12.0.jar"
I tried too with IE and Chrome (i have the same problem too):
java -Dwebdriver.chrome.driver=./chromedriver -jar "selenium-server-standalone-3.12.0.jar"
java -Dwebdriver.ie.driver=./IEDriverServer -jar "selenium-server-standalone-3.12.0.jar"
acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- \Helper\Acceptance
config:
WebDriver:
url: 'http://localhost'
browser: firefox
window_size: 820x1000
Codeception Version: 2.4.1
WebDriver Chrome Version: 2.38 (win32)
WebDriver Firefox Version: 0.20.1 (x64)
Chrome Version: 66.0.3359.139 (64-bit)
Firefox Version: Firefox Quantum 60.0 (64-bit)
Windows Version: Windows 8.1 64bit
Selenium Version: 3.12.0

To start Selenium Server you need not require to pass/specify the WebDriver variant and you can start the Selenium Server as follows :
Command :
>java -jar selenium-server-standalone-3.12.0.jar
Console Logs :
C:\Utility\selenium-server-standalone>java -jar selenium-server-standalone-3.12.0.jar
15:28:28.249 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.12.0', revision: '7c6e0b3'
15:28:28.251 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444
2018-05-11 15:28:28.361:INFO::main: Logging initialized #467ms to org.seleniumhq.jetty9.util.log.StdErrLog
15:28:28.860 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
Snapshot of the Resource Hub :
Update
As per the documentation at codeception.com the acceptance.suite.yml should have been as follows :
modules:
enabled:
- WebDriver:
url: 'http://localhost/'
browser: firefox
window_size: 820x1000

Problem fixed. I was using proxy.
For future users with same problem like me, can follow the steps.
First, check if you have proxy defined with this command:
echo %http_proxy%
If return some result, you need set a empty proxy with this command:
set http_proxy=
You need define a proxy always you are opening a new command line.

Related

Invalid --log-level value. Unable to initialize logging. Exiting... error while starting Selenium Grid Node

I have problem with Selenium Grid. Then I try to connect to node, i've got an error on node side.+
U run hub by this way:
java -jar .\selenium-server-standalone-3.141.59.jar -role hub
I run node by this way:
java -jar .\selenium-server-standalone-3.141.59.jar -role node -nodeConfig .\NodeConfig.json
NodeConfig.json:
{
"capabilities":
[
{
"browserName": "chrome",
"platform": "WINDOWS",
"maxInstances": 5,
"chrome_binary":"chromedriver.exe",
"seleniumProtocol": "WebDriver",
"nodeName": "Local Chrome Node"
}
],
"maxSession": 5,
"port": 5555,
"register": true,
"registerCycle": 5,
"hub": "http://localhost:4444",
"webdriver.chrome.driver":"<path to chromedriver.exe>"
"nodeStatusCheckTimeout": 5,
"nodePolling": 5,
"role": "node",
"unregisterIfStillDownAfter": 60,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}
Simplyfied Java code:
DriverService service = null;
ChromeOptions opts = new ChromeOptions();
opts.addArguments("-incognito");
opts.addArguments("--no-sandbox");
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), opts);
On Java side:
A long stacktrace (I think it's not necessary for this problem)
On Node side:
java -jar .\selenium-server-standalone-3.141.59.jar -role node
-nodeConfig .\NodeConfig.json 15:39:56.377 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision:
e82be7d358 15:39:56.513 INFO
[GridLauncherV3.lambda$buildLaunchers$7] - Launching a Selenium Grid
node on port 5555 2019-06-18 15:39:56.921:INFO::main: Logging
initialized #807ms to org.seleniumhq.jetty9.util.log.StdErrLog
15:39:57.200 INFO [WebDriverServlet.] - Initialising
WebDriverServlet 15:39:57.292 INFO [SeleniumServer.boot] - Selenium
Server is up and running on port 5555 15:39:57.293 INFO
[GridLauncherV3.lambda$buildLaunchers$7] - Selenium Grid node is up
and ready to register to the hub 15:39:57.456 INFO
[SelfRegisteringRemote$1.run] - Starting auto registration thread.
Will try to register every 5 ms. 15:39:57.955 INFO
[SelfRegisteringRemote.registerToHub] - Registering the node to the
hub: http://localhost:4444/grid/register 15:39:58.106 INFO
[SelfRegisteringRemote.registerToHub] - The node is registered to the
hub and ready to use 15:40:06.931 INFO [ActiveSessionFactory.apply]
- Capabilities are: { "browserName": "chrome", "goog:chromeOptions": {
"args": [
"-incognito",
"--no-sandbox"
],
"extensions": [
],
"binary": "chromedriver.exe" } } 15:40:06.933 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory
org.openqa.selenium.grid.session.remote.ServicedSession$Factory
(provider: org.openqa.selenium.chrome.ChromeDriverService) Starting
ChromeDriver 75.0.3770.90
(a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770#{#1003})
on port 21040 Only local connections are allowed. Please protect
ports used by ChromeDriver and related test frameworks to prevent
access by malicious code. Starting ChromeDriver 75.0.3770.90
(a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770#{#1003})
on port 9515 Only local connections are allowed. Please protect
ports used by ChromeDriver and related test frameworks to prevent
access by malicious code. Invalid --log-level value. Unable to
initialize logging. Exiting...
On Hub side:
java -jar .\selenium-server-standalone-3.141.59.jar -role hub
15:39:50.884 INFO [GridLauncherV3.parse] - Selenium server version:
3.141.59, revision: e82be7d358 15:39:51.000 INFO [GridLauncherV3.lambda$buildLaunchers$5] - Launching Selenium Grid hub
on port 4444 2019-06-18 15:39:51.425:INFO::main: Logging initialized
#805ms to org.seleniumhq.jetty9.util.log.StdErrLog 15:39:51.831 INFO
[Hub.start] - Selenium Grid hub is up and running 15:39:51.832 INFO
[Hub.start] - Nodes should register to http://%My IP%:4444/grid/register/ 15:39:51.832 INFO [Hub.start] - Clients
should connect to http://%My IP%:4444/wd/hub 15:39:58.105 INFO
[DefaultGridRegistry.add] - Registered a node http://:5555
15:40:06.623 INFO [RequestHandler.process] - Got a request to create a
new session: Capabilities {browserName: chrome, goog:chromeOptions:
{args: [-incognito, --no-sandbox], extensions: []}} 15:40:06.632
INFO [TestSlot.getNewSession] - Trying to create a new session on test
slot {chrome_binary=chromedriver.exe, nodeName=Local Chrome Node,
server:CONFIG_UUID=186192e2-e951-4cef-b527-291aa9c0e2f5,
seleniumProtocol=WebDriver, webdriver.chrome.driver=/chromedriver.exe, browserName=chrome, maxInstances=1,
platformName=WINDOWS, version=75, platform=WINDOWS}
So, how to sole this problem and configure logs on node side (I'd like to made it via .json file)
Analyzing the NodeConfig.json and both Selenium Grid Hub and Selenium Grid Hub logs, there seems to be an issue with the  --no-sandbox argument.
Sandbox
The sandbox library which allows the creation of sandboxed processes that can execute within a very restrictive environment cannot write to disk. Chromium renderers are sandboxed processes.
Solution
Some more information about Selenium client, ChromeDriver / Chrome version would have helped us to debug the issue in a better way. However as you are using Chrome in regular mode (non headless), you may drop the argument --no-sandbox.
tl; dr
Unable to Create Driver Instance for chrome in ubuntu
I just came across this error and fixed it. The "Invalid --log-level value" error is caused by using ChromeDriver as Chrome. Selenium runs ChromeDriver, then ChromeDriver runs Chrome. Chrome recognise "--log-level=0", but not ChromeDriver.
What's happening here is that you try to use ChromeDriver to run ChromeDriver. The reason can be specifying ChromeDriver's path as Chrome. E.g. symbolic link chromedriver as chrome, or ChromeOptions.setBinary(".../chromedriver")

Failed to connect Couldn't register this node: Error sending the registration request: Failed to connect while registering SeleniumGrid Node to Hub

Selenium hub is up and running on Windows desktop, set up Windows VM to be node. Node won't register to hub.
Step 1:
Entered command in Windows Desktop:
java -jar selenium-server-standalone-3.14.0.jar -role hub -port 2222
Output:
`11:11:24.171 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.14.0', revision: 'aacccce0'
11:11:24.175 INFO [GridLauncherV3$2.launch] - Launching Selenium Grid hub on port 2222
11:11:25.108:INFO::main: Logging initialized #2242ms to org.seleniumhq.jetty9.util.log.StdErrLog
11:11:26.832 INFO [Hub.start] - Selenium Grid hub is up and running
11:11:26.832 INFO [Hub.start] - Nodes should register to http://172.20.111.25:2222/grid/register/
11:11:26.832 INFO [Hub.start] - Clients should connect to http://172.20.111.25:2222/wd/hub`
Checked the config page on localhost and saw that it was there.
Step 2:
Entered this into the command line in Windows Virtual Machine:
java -jar selenium-server-standalone-3.14.0.jar -role node -hub http://172.20.111.25:2222/grid/register
Output:
10:18:43.108 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.14.0', revision: 'aacccce0'
10:18:43.155 INFO [GridLauncherV3$3.launch] - Launching a Selenium Grid node on port 18004
2019-06-03 10:18:43.676:INFO::main: Logging initialized #1482ms to org.seleniumhq.jetty9.util.log.StdErrLog
10:18:44.108 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 18004
10:18:44.108 INFO [GridLauncherV3$3.launch] - Selenium Grid node is up and ready to register to the hub
10:18:44.280 INFO [SelfRegisteringRemote$1.run] - Starting auto registration thread. Will try to register every 5000 ms.
10:18:44.280 INFO [SelfRegisteringRemote.registerToHub] - Registering the node to the hub: http://172.20.111.25:2222/grid/register
10:19:06.003 INFO [SelfRegisteringRemote$1.run] - Couldn't register this node: Error sending the registration request: Failed to connect to /172.20.111.25:2222
You were almost there. You need to remove the additional forward slash (i.e. /) at the end of the registration uri while registering the Selenium Grid Node and you can use the following steps:
First of all, to start the Selenium Grid Hub on port 2222 you need to issue the following command:
java -jar selenium-server-standalone-3.14.0.jar -role hub -port 2222
You will find the following logs generated:
16:00:50.746 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.14.0', revision: 'aacccce0'
16:00:50.750 INFO [GridLauncherV3$2.launch] - Launching Selenium Grid hub on port 2222
2019-05-31 16:00:51.392:INFO::main: Logging initialized #1151ms to org.seleniumhq.jetty9.util.log.StdErrLog
16:00:52.139 INFO [Hub.start] - Selenium Grid hub is up and running
16:00:52.141 INFO [Hub.start] - Nodes should register to http://192.168.1.125:2222/grid/register/
16:00:52.141 INFO [Hub.start] - Clients should connect to http://192.168.1.125:2222/wd/hub
Now you can access the Selenium Grid Console through the URL:
http://localhost:2222/grid/console
The console will look like:
Now finally to start the Selenium Grid Node you have to issue the following command:
java -jar selenium-server-standalone-3.14.0.jar -role node -hub http://192.168.1.125:2222/grid/register
You will find the following logs generated:
16:04:48.440 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.14.0', revision: 'aacccce0'
16:04:48.470 INFO [GridLauncherV3$3.launch] - Launching a Selenium Grid node onport 7724
2019-05-31 16:04:48.985:INFO::main: Logging initialized #1059ms to org.seleniumhq.jetty9.util.log.StdErrLog
16:04:49.275 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 7724
16:04:49.275 INFO [GridLauncherV3$3.launch] - Selenium Grid node is up and ready to register to the hub
16:04:49.454 INFO [SelfRegisteringRemote$1.run] - Starting auto registration thread. Will try to register every 5000 ms.
16:04:49.454 INFO [SelfRegisteringRemote.registerToHub] - Registering the node to the hub: http://192.168.1.125:2222/grid/register
16:04:50.355 INFO [SelfRegisteringRemote.registerToHub] - The node is registered to the hub and ready to use
I would suggest to go through the steps mentioned below through which I am successfully able to resolve that issue.
Login to other machine and register it as a node.
Ping IP from both the machines to check whether you're on a same network.
Verify that Windows Defender Firewall should be off to ping machine when you're trying on a same network.
In Node Machine , Download standalone jar and paste in some directory and open cmd from that directory .
Verify whether you're able to check URL in Node machine
Ex: URL : http://xx.xx.xx.xx:4444/grid/console
Run the command :
java -Dwebdriver.chrome.driver="C:\chromedriver.exe" -jar selenium-server-standalone-3.141.59.jar -role webdriver -hub http://xx.xx.xx.xx:4444/grid/register -port 5566
Okay, I believe I fixed this error.
So I started the hub from my desktop: 172.17.248.33
and then I tried to connect the node from my virtual machine: 173.248.137.73 back to my desktop 172.17.248.33.
I knew beforehand that when I started the hub from my desktop and then ran a node on my desktop it would connect.
However, I was under the impression I could start the hub in my desktop 172.17.248.33 and then have my VM node 173.248.137.73 connected to the hub desktop. I am guessing this is not possible with Selenium.
Once I started the hub from my virtual machine and initiated the node command from the same machine, it worked.

selenium server standalone: unable to create a new session with vagrant in headless mode

I am trying to run the selenium server standalone in a vagrant box, with the following command:
java -jar selenium-server-standalone-3.13.0.jar
When I click the 'create session' button at http://lab.local:4444/wd/hub/static/resource/hub.html from my host web browser. I get a unable to create a new session error message.
I ask to create a firefox browser session for which I get the driver located in /usr/local/bin/geckodriver.
Firefox has been installed on the vagrant box with sudo apt install firefox-esr.
Error log detail:
14:52:04.485 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.13.0', revision: '2f0d292'
14:52:04.486 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444
2018-08-09 14:52:04.564:INFO::main: Logging initialized #312ms to org.seleniumhq.jetty9.util.log.StdErrLog
14:52:04.757 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
14:52:15.563 INFO [ActiveSessionFactory.apply] - Capabilities are: {
"browserName": "firefox"
}
14:52:15.568 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.firefox.GeckoDriverService)
1533819135611 geckodriver INFO geckodriver 0.21.0
1533819135614 geckodriver INFO Listening on 127.0.0.1:25541
1533819135880 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.yuusnpGo8Gw6"
1533819136508 Marionette INFO Listening on port 2828
When I run the same executable directly from my host, I get no error and the firefox session is created with success.
I try to run a X server, Xvfb as follow but this does not change anything:
Xvfb :1 -screen 0 1600x1200x16 &
export DISPLAY=:1
java -jar selenium-server-standalone-3.13.0.jar
Problem solved after switching to selenium-server-standalone-3.3.1.jar with geckodriver 0.14.0. Sessions are created with success with this configuration.
source.

Selenium - Chrome binary ignored

I prefer to use old Selenium 2.53.1 with old version of Chromium 52.0 and chromedriver 2.24. I'm running following on Windows 7:
start java -jar selenium-server-standalone-2.53.1.jar -Dwebdriver.chrome.driver=C:\dev\selenium\chromedriver.exe -Dwebdriver.chrome.binary=C:\dev\selenium\chrome-win32\chrome.exe -Dwebdriver.chrome.chrome_binary=C:\dev\selenium\chrome-win32\chrome.exe -Dwebdriver.chrome.capabilities.binary=C:\dev\selenium\chrome-win32\chrome.exe -Dwebdriver.chrome.capabilities.chrome_binary=C:\dev\selenium\chrome-win32\chrome.exe -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=1,binary="C:\dev\selenium\chrome-win32\chrome.exe",chrome_binary="C:\dev\selenium\chrome-win32\chrome.exe" -host 0.0.0.0 -port 4444
As you can see I have tried a lot of variants trying both binary and chrome_binary. But Selenium Server ignores those options and starts a default Chrome Browser. How to make it run the binary I specified C:\dev\selenium\chrome-win32\chrome.exe?
09:22:53.149 INFO - Launching a standalone Selenium Server
Setting system property webdriver.chrome.driver to C:\dev\selenium\chromedriver.exe
Setting system property webdriver.chrome.binary to C:\dev\selenium\chrome-win32\chrome.exe
Setting system property webdriver.chrome.chrome_binary to C:\dev\selenium\chrome-win32\chrome.exe
Setting system property webdriver.chrome.capabilities.binary to C:\dev\selenium\chrome-win32\chrome.exe
Setting system property webdriver.chrome.capabilities.chrome_binary to C:\dev\selenium\chrome-win32\chrome.exe
09:22:53.480 INFO - Java: Oracle Corporation 25.65-b01
09:22:53.480 INFO - OS: Windows 7 6.1 amd64
09:22:53.490 INFO - v2.53.1, with Core v2.53.1. Built from revision a36b8b1
09:22:53.569 INFO - Driver class not found: com.opera.core.systems.OperaDriver
09:22:53.569 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
09:22:53.579 INFO - Driver provider org.openqa.selenium.safari.SafariDriver registration is skipped:
registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform VISTA
09:22:53.579 INFO - Driver class not found: org.openqa.selenium.htmlunit.HtmlUnitDriver
09:22:53.579 INFO - Driver provider org.openqa.selenium.htmlunit.HtmlUnitDriver is not registered
09:22:53.928 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
09:22:53.928 INFO - Selenium Server is up and running
09:22:54.331 INFO - Executing: [new session: Capabilities [{acceptSslCerts=false, browserName=chrome, platform=ANY}]])
09:22:54.345 INFO - Creating a new session for Capabilities [{acceptSslCerts=false, browserName=chrome, platform=ANY}]
Starting ChromeDriver 2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf) onport 4923
Only local connections are allowed.
09:22:55.137 INFO - Done: [new session: Capabilities [{acceptSslCerts=false, browserName=chrome, platform=ANY}]]
Related (unaswered):
How to specify the Chrome binary location via the selenium server standalone command line?
Change your command to something like below
start java -Dwebdriver.chrome.driver=C:\dev\selenium\chromedriver.exe
-Dwebdriver.chrome.binary=C:\dev\selenium\chrome-win32\chrome.exe
-Dwebdriver.chrome.chrome_binary=C:\dev\selenium\chrome-win32\chrome.exe
-Dwebdriver.chrome.capabilities.binary=C:\dev\selenium\chrome-win32\chrome.exe
-Dwebdriver.chrome.capabilities.chrome_binary=C:\dev\selenium\chrome-win32\chrome.exe
-jar selenium-server-standalone-2.53.1.jar -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=1,binary="C:\dev\selenium\chrome-win32\chrome.exe",chrome_binary="C:\dev\selenium\chrome-win32\chrome.exe" -host 0.0.0.0 -port 4444
and try again ? You should put the -D JVM argument before the -jar.
For more information refer here.
Seems using Selenium Grid everything works:
start java -Dwebdriver.server.session.timeout=900 -jar selenium-server-standalone-2.53.1.jar -role hub -host 0.0.0.0 -port 4444
start java -Dwebdriver.chrome.driver=C:\dev\selenium\chromedriver.exe -jar selenium-server-standalone-2.53.1.jar -role node -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=1,chrome_binary="C:\dev\selenium\chrome-win32\chrome.exe" -hub http://127.0.0.1:4444/grid/register -port 5555

seleniumAddress not taking effect in Protractor config

I am having a issue where seleniumAddress is not taking effect in protractor config. I use seleniumAddress: 'http://127.0.0.1:4444/wd/hub' but I see:
[18:52:35] E/launcher - Timed out waiting for the WebDriver server at http://127.0.0.1:47780/hub
The port should be 4444 instead of 47780. Any ideas?
one#development ~/github/drop $ protractor --version
Version 4.0.7