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

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",
}

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
}
}
}

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 ?

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

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

Selenium GeckoDriver with Protractor: "Failed: Timed out"

My automation test suite uses Selenium WebDriver with Protractor and Jasmine to run against a variety of browsers. When using GeckoDriver to run the tests on Firefox, I am intermittently getting an error message that just says "Failed: Timed out":
. ✓ WHEN I visit the favorites page
. ✓ THEN it should say I havent added anything
F ✗ WHEN I open the inspirations page
- Failed: Timed out
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'admins-MacBook-Pro-3.local', ip: 'fe80:0:0:0:10a7:9b8d:6ff5:f46%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144'
Driver info: driver.version: unknown
F ✗ AND I click on an inspiration preview pane to open an inspiration
I have tried padding it with hard-coded sleep on either side, and I've searched for other errors, but everything else I can find in regards to Protractor timeouts is for other errors that have some kind of a description about what is actually timing out.
Has anyone seen JUST the message "Failed: Timed out" here who can help determine what might be timing out?
As requested, here is the gulp task that kicks off my protractor:
gulp.task('test-frontend-firefox', 'Run feature tests locally', function() {
gulp.src(['test/feature/**/*.spec.js'])
.pipe(protractor({
configFile: __dirname + '/../test/protractor_local_ff.conf.js',
args: ['--baseUrl', 'http://localhost:9099'],
}));
});
And here is protractor_local_ff.conf.js as referenced by the gulp task:
var private_config = require('./private.conf.js');
var golden_config = require('./golden.conf.js');
exports.config = {
params: {
private: private_config,
golden: golden_config,
localhost: true
},
onPrepare: function(){
var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: 'all'}));
},
framework: 'jasmine2',
// seleniumAddress: 'http://hub-cloud.browserstack.com/wd/hub',
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'firefox'
}
};
As you can see, it's set up to be able to run against the hosted app in either browserstack or on my localhost, but the error gets thrown intermittently in either environment.

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).