Selenium + Mink + Chrome: "Could not open connection" error - selenium

I'm not new to setting up Selenium and Mink, but it always seems to be a hassle. This time I'm trying to get it set up in an ubuntu docker container and I am running into the following error:
Could not open connection: Unable to create new service: ChromeDriverService
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'a75b4026b8e5', ip: '172.20.0.6', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.60-linuxkit-aufs', java.version: '1.8.0_161'
Driver info: driver.version: unknown (Behat\Mink\Exception\DriverException)
I can tell that Mink is hitting the Selenium to some degree, since the Selenium server outputs the following immediately before Behat reports the above error:
2018-01-30 16:13:49.870:INFO:osjshC.ROOT:qtp1156060786-12: org.openqa.selenium.remote.server.WebDriverServlet-10bbd20a: Initialising WebDriverServlet
16:13:49.988 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession#4b4945b7
16:13:50.006 INFO - /session: Executing POST on /session (handler: BeginSession)
16:13:50.168 INFO - Capabilities are: Capabilities {browser: chrome, browserName: chrome, ignoreZoomSetting: false, marionette: true, name: Behat feature suite, tags: [a75b4026b8e5, PHP 5.6.31]}
16:13:50.171 INFO - Capabilities {browser: chrome, browserName: chrome, ignoreZoomSetting: false, marionette: true, name: Behat feature suite, tags: [a75b4026b8e5, PHP 5.6.31]} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
16:13:50.302 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession#5a608e4b
16:13:50.303 INFO - /session: Executing POST on /session (handler: BeginSession)
16:13:50.306 INFO - Capabilities are: Capabilities {browser: chrome, browserName: chrome, ignoreZoomSetting: false, marionette: true, name: Behat feature suite, tags: [a75b4026b8e5, PHP 5.6.31]}
16:13:50.307 INFO - Capabilities {browser: chrome, browserName: chrome, ignoreZoomSetting: false, marionette: true, name: Behat feature suite, tags: [a75b4026b8e5, PHP 5.6.31]} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Any idea what setting I have wrong?
Here's my setup:
Version of the chromedriver I installed:
https://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip
Version of Chrome I have installed via the apt-get install google-chrome-stable command:
Google Chrome 64.0.3282.119
Java version that's installed:
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
How I started selenium:
xvfb-run --server-args="-screen 0, 1366x768x24" java -Dwebdriver.chrome.driver="usr/bin/chromedriver" -jar selenium-server-standalone-3.8.1.jar &
composer.json:
...
"require-dev": {
"behat/behat": "^3.1",
"behat/mink": "^1.7",
"behat/mink-extension": "^2.2",
"behat/mink-goutte-driver": "^1.2",
"behat/mink-selenium2-driver": "^1.3",
...
},
behat.yml:
extensions:
Behat\MinkExtension:
goutte: ~
base_url: http://localhost/myapp/
browser_name: chrome
javascript_session: selenium2
default_session: goutte
selenium2:
wd_host: "http://127.0.0.1:4444/wd/hub"
capabilities:
marionette: true
browser: chrome
version: 2.9

Related

LocalFileDetector can't find uploaded files in Selenium Grid tests

I'm using Selenium Grid to run some automated tests that always worked locally. I've created a RemoteWebDriver object, and used remoteDriver.setFileDetector(new LocalFileDetector()) to activate the local file detector. All of the pages I can find list this as the only solution, as if nothing can possibly go wrong with it.
In summary, selenium is definitely uploading the files from my local Windows filesystem, to Selenium Grid running on Linux. GeckoDriver can find it just fine, but ChromeDriver says it's not found:
invalid argument: File not found : /tmp/41dd2016f9974950127c20f7d25df461/upload7388365119198958794file/hasThemesWithImages.zip
(Session info: headless chrome=109.0.5414.74)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'PAX-314945', ip: '192.168.50.241', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.16.1'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 109.0.5414.74, chrome: {chromedriverVersion: 109.0.5414.74 (e7c5703604da..., userDataDir: /tmp/.org.chromium.Chromium...}, goog:chromeOptions: {debuggerAddress: localhost:39795}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true, webdriver.remote.sessionid: 41dd2016f9974950127c20f7d25...}
Session ID: 41dd2016f9974950127c20f7d25df461
If I ssh to the remote host while it's still running, and type ls -l and paste in that long pathname, then I see the file is present. It's the correct size, and has global read permissions. I can even examine the zip contents. And yet, chromedriver gives the error above.
I started the grid server with a very simple java -jar selenium-server-standalone-3.141.59.jar command, with no other options, and am using Chromium in headless mode.
I have tried starting Chromium with and without --no-sandbox and --disable-dev-shm-usage as command line options.
I'm using Geb 3.4.1 and Groovy 2.x on the client side, and it looks like I'm doing everything correctly. I tried a few different tests that worked locally before, and added some logging in the test to confirm that driver.getFileDetector() returned the LocalFileDetector instance. Here is the relevant portion of my GebConfig.groovy file:
def remoteWebDriver(Capabilities capabilities) {
URL hubUrl = new URL("http://192.168.1.5:4444/wd/hub")
new RemoteWebDriver(hubUrl, capabilities)
}
FirefoxProfile myFirefoxProfile() {
// omitted; I hope it's not important.
}
environments {
gridFirefox { // file uploads work
driver = {
println "creating a RemoteDriver"
FirefoxOptions opts = new FirefoxOptions()
opts.addArguments("--headless")
opts.profile = myFirefoxProfile()
RemoteWebDriver remoteDriver = remoteWebDriver(opts)
remoteDriver.setFileDetector(new LocalFileDetector())
remoteDriver
}
}
gridChrome { // file uploads don't work
driver = {
println "creating a Chrome RemoteDriver"
ChromeOptions chrome_options = new ChromeOptions()
chrome_options.addArguments("--window-size=1600,1100")
chrome_options.addArguments('--headless')
//chrome_options.addArguments('--no-sandbox')
//chrome_options.addArguments('--disable-dev-shm-usage')
RemoteWebDriver remoteDriver = remoteWebDriver(chrome_options)
remoteDriver.setFileDetector(new LocalFileDetector())
remoteDriver
}
}
}

Selenium Grid Driver.Version Unknown

I know that this question is asked many times and the answers helped me once.
I used to start as an experiment a Selenium Grid Hub on my local machine and an Node on an other machine. Both were started using parameters on the command line. I was able to start a test so the configuration worked.
Since I do not want to run the hub on my local machine I started is on the same machine as the node but now using JSON config files.
Now I get the WebDriverException: Error forwarding the new session cannot find ... giving the driver.version: unknown error.
I am sure that I pass the version so the error leaves me puzzled.
The node is according to the hub's out put correctly registered. The nodeconfig JSON is:
{
"capabilities":
[
{
"browserName": "chrome",
"maxInstances": 5,
"seleniumProtocol": "WebDriver",
"version": 93,
"platform": "WIN10"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "http://localhost:4444",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}
The console output in Eclipse shows this error description:
Caused by: org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless, --window-size=1920,955, --ignore-certificate-errors, --disable-gpu], extensions: []}, platform: WIN10, version: 93}
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'XXXXXXXXXX', ip: 'ipx.xxx.xxx.xxx', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_302'
Driver info: driver.version: unknown
The hub show following:
ipy.yyy.yyy.yyy INFO [RequestHandler.process] - Got a request to create a new session: Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless, --window-size=1920,955, --ignore-certificate-errors, --disable-gpu], extensions: []}, platform: WIN10, version: 93}
ipy.yyy.yyy.yyy INFO [RequestHandler.process] - Error forwarding the new session cannot find : Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless, --window-size=1920,955, --ignore-certificate-errors, --disable-gpu], extensions: []}, platform: WIN10, version: 93}
org.openqa.grid.common.exception.CapabilityNotPresentOnTheGridException: cannot find : Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless, --window-size=1920,955, --ignore-certificate-errors, --disable-gpu], extensions: []}, platform: WIN10, version: 93}
The Chrome version on the node is 93.0.4577.82. Do I need to spell this out?
Can anyone give me a clue how to solve this?
All examples on the net are showing version numbers like 93.0 or 93 .
So yes, I had to spell it out like 93.0.4577.82

Protractor e2e tests using selenium are not running on IE11 | TimeOut issue

I am trying to run protractor e2e tests on IE11. tests are failing with timeout error.
[Test Error Output]
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
[19:03:47]
[should not allow Clifton to create a sub-folder inside a folder previously created by Emmett] Failed: JavaScript error in async script. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.29 seconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: '', ip: '10.50.10.158', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_79'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=1, ignoreZoomSetting=false, enablePersistentHover=false, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true, ie.enableFullPageScreenshot=true, unexpectedAlertBehaviour=dismiss, ie.fileUploadDialogTimeout=3000, ie.forceShellWindowsApi=false, version=11, pageLoadStrategy=normal, ignoreProtectedModeSettings=false, requireWindowFocus=true, initialBrowserUrl=http://localhost:48570/, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=}]
I tried below this as mentioned in different blogs or post /issue links
Increase the test case time out from protractor e2e configuration.
Updating the protractor and selenium IE driver version.
Adding IE specific configuration setting in e2e configuration. e.g
capabilities: {
elementScrollBehavior: 1,
browserName: 'chrome',
// IE specific, enables modifier keys (eg. CTRL+CLICK)
requireWindowFocus: true,
// If this is set to be true, specs will be sharded by file (i.e. all
// files to be run by this set of capabilities will run in parallel).
// Default is false.
shardTestFiles: false,
// Maximum number of browser instances that can run in parallel for this
// set of capabilities. This is only needed if shardTestFiles is true.
// Default is 1.
maxInstances: 1,
loggingPrefs: {
//this is a chrome specific setting - no effect on other browser runs
performance: "OFF"
},
nativeEvents: false,
unexpectedAlertBehaviour: 'accept',
ignoreProtectedModeSettings: true,
enablePersistentHover: true,
requireWindowFocus: true,
ignoreZoomSetting: true,
INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS: true
}
Configuring the IE browser settings as recommended in the below link http://elgalu.github.io/2014/run-protractor-against-internet-explorer-vm/#
Protractor test in IE
Using browser.driver.get() instead of browser.get() as mentioned in link: https://github.com/angular/protractor/issues/4268
Is their any limitations running protractor e2e tests on IE11 ?

Firefox 57 does not load geckoservice in Selenium during end-to-end testing

I am trying to load Firefox to test my web application using selenium. I am getting SessionNotCreatedError: Unable to create new service: GeckoDriverService error when I specify firefox in the capabilities. Here is how it looks like:
var config = {
sauceUser: process.env.SAUCE_USERNAME,
sauceKey: process.env.SAUCE_ACCESS_KEY,
framework: 'jasmine2',
capabilities: {
browserName: 'firefox',
version: '57.0',
'screenResolution': '1920x1440'
},
specs: [
'*.spec.js'
],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 300000,
print: function() {}
},
params: {
defaultTimeout: 15000
}
};
Here are details of my environment:
OS: Ubuntu 16.04 LTS 64bit
Firefox: Quantum 57 64 bit
Selenium: 3.7.1
webdriver-manager: 12.0.6
gecko driver: 0.19.1
Protractor: 5.2.0
When I ran my protractor End-to-End test cases it throws this error:
[13:14:58] E/launcher - SessionNotCreatedError: Unable to create new service: GeckoDriverService
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:36.161Z'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '4.10.0-38-generic', java.version: '1.8.0_151'
Driver info: driver.version: unknown
at Object.checkLegacyResponse (/home/dev/node_modules/selenium-webdriver/lib/error.js:546:15)
at parseHttpResponse (/home/dev/node_modules/selenium-webdriver/lib/http.js:509:13)
at doSend.then.response (/home/dev/node_modules/selenium-webdriver/lib/http.js:441:30)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
From: Task: WebDriver.createSession()
at Function.createSession (/home/dev/node_modules/selenium-webdriver/lib/webdriver.js:769:24)
at Function.createSession (/home/dev/node_modules/selenium-webdriver/firefox/index.js:521:41)
at createDriver (/home/dev/node_modules/selenium-webdriver/index.js:170:33)
at Builder.build (/home/dev/node_modules/selenium-webdriver/index.js:632:16)
at Local.getNewDriver (/home/dev/node_modules/protractor/built/driverProviders/driverProvider.js:53:33)
at Runner.createBrowser (/home/dev/node_modules/protractor/built/runner.js:195:43)
at q.then.then (/home/dev/node_modules/protractor/built/runner.js:339:29)
at _fulfilled (/home/dev/node_modules/protractor/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/home/dev/node_modules/protractor/node_modules/q/q.js:863:30)
at Promise.promise.promiseDispatch (/home/dev/node_modules/protractor/node_modules/q/q.js:796:13)
[13:14:58] E/launcher - Process exited with error code 199
I tried using updated versions of selenium and gecko driver but that did not help either.
I added marionette: true but still getting the same error. I also tried "javascriptEnabled": true, "acceptSslCerts": true but with no success.
It work for me when using geckodriver#1.10.0 and Firefox 57.0 (64 bits).

Unable to find page elements with Behat / Mink using Selenium 3.5.x

I am working on setting up behavioral tests for our current website. I have used Behat in the past with Selenium standalone server and now have updated to the latest Behat 3 and Selenium 3.5. I am having a multitude of issues though. Using Selenium 3.5 I cannot get xpath selectors to work at all. It is not able to find elements by id, name, class etc. With Selenium 3.4.x it seems to work fine but I cannot get button presses to work. I receive this error:
Then I click button "loginBtn" # FeatureContext::iClickButton()
mouseMoveTo
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'matt-VirtualBox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-59-generic', java.version: '1.8.0_131'
Driver info: driver.version: RemoteWebDriver (WebDriver\Exception\UnknownCommand)
This seems to be something that was fixed in 3.5.x with enablePassThrough set to true. Here is my behat.yml configuration.
default:
suites:
default:
contexts:
- FeatureContext:
screenshots_path: '%paths.base%/screenshots/firefox/'
extensions:
Behat\MinkExtension:
base_url: 'http://localhost:8080/customer_portal/'
default_session: selenium2
browser_name: 'firefox'
selenium2:
browser: 'firefox'
capabilities:
browserName: 'firefox'
browser: 'firefox'
version: ''
wd_host: 'localhost:5555/wd/hub'
And inside of my composer.json file
{
"require": {
"behat/behat": "3.*#stable",
"behat/mink": "1.7.*#stable",
"behat/mink-selenium2-driver": "#stable",
"behat/mink-goutte-driver": "#stable",
"behat/mink-extension": "#stable",
"phpmd/phpmd" : "#stable"
},
"config": {
"bin-dir": "bin/"
}
}
I am using Firefox 55 and geckodriver v18. Has anyone successfully configured selenium to work with Behat 3 and Firefox?
It seems to be an issue from Selenium. I also have the issue when working with FF and could not get the Element clicked.
mouseMoveTo error is well known issue when using selenium3. This error happens only for firefox browser with gecko driver. To fix this issue you can use chrome or update the MinkSelenium2Driver library. Should be master branch of MinkSelenium2Driver which requires behat/mink: ~1.7#dev. Here is the point of the problem MinkSelenium2Driver So if its ok for you to use all the latest behat versions, then composer.json could looks like this:
"require": {
"behat/behat": "v3.3.1",
"behat/mink": "v1.7.1",
"behat/mink-extension": "v2.2",
"behat/mink-selenium2-driver": "dev-master",
}