Chrome is not started with selenium and behat - google-chrome

Please help. I use windows to run my tests. I run selenium with chrome driver:
java -Dwebdriver.chrome.driver=chromedriver.exe -jar selenium-server-standalone-3.4.0.jar
My behat_dev.yml :
default:
suites:
default:
mink_session: selenium2
javascript_session: selenium2
extensions:
Behat\MinkExtension:
base_url: http://en.wikipedia.org
default_session : selenium2
javascript_session: selenium2
browser_name : chrome
goutte: ~
selenium2 :
wd_host : http://127.0.0.1:4444/wd/hub
browser: chrome
capabilities: { "browserName": "chrome", "browser": "chrome", "version": "", 'chrome': {'switches':['--no-sandbox']} }
sessions:
default:
selenium2: ~
My scenario :
Feature: Home page
I am on a home page
#javascript
Scenario: Searching for a page with autocompletion
Given I am on "/wiki/Main_Page"
When I fill in "search" with "Behavior Driv"
And I wait for the suggestion box to appear
Then I should see "Behavior-driven development"
The selenium is starting whitout problems, but when I try to run the tests nothing happen. The browser is not open. Please help me !!!!!! Thx in advance and sorry for my english.

You don't have to set wd_host for local run unless you are using a different port.
It should work with some simple config like:
default:
suites:
default:
contexts:
- FeatureContext
extensions:
Behat\MinkExtension:
base_url: 'http://en.wikipedia.org'
selenium2:
browser: chrome
Make sure you keep the indentation in yml, suites is under first default, not at the same level.
For extra verbosity use a -vvv at the end.

Related

Is it possible to --disable-web-security on Travis Chrome?

I am developing a project which requires --disable-web-security for testing. I use Karma with the following settings:
browsers: [
"ch"
],
customLaunchers: {
"ch": {
"base": "Chrome",
"flags": ["--disable-web-security"]
}
},
and
if (process.env.TRAVIS)
options.customLaunchers.ch.flags.push("--no-sandbox");
This works properly on localhost with Chrome v69.0.3497.100 win7 x64.
I am trying to run the same code on Travis (by pushing the changes to GitHub) with the following yml:
language: node_js
node_js:
- "9"
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 5
I guess we are talking about 2 different browsers with the same engine here, since Chromium != Chrome, but I am not sure. Anyways, I got an error message by trying to build on Travis:
Blocked a frame with origin "http://localhost:9876" from accessing a cross-origin frame.
That clearly indicates that web security is enabled. Is there any way to disable web security on Travis?
Solution:
Using Trusty with real Chrome solved it:
language: node_js
node_js:
- "9"
dist: trusty
addons:
chrome: stable
before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 5
According to this documentation you can run Chrome headless by writing the following in your .travis.yml config file
dist: trusty
addons:
chrome: stable
before_install:
- # start your web application and listen on `localhost`
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
As for your Karma configuration file, check this page. It indicates that you have to add one more flag.
For security reasons, Google Chrome is unable to provide sandboxing when it is running in the container-based environment.
To use Chrome in the container-based environment, pass the --no-sandbox flag to the chrome executable.
module.exports = function(config) {
config.set({
browsers: ['Chrome', 'ChromeHeadless', 'ChromeHeadlessNoSandbox'],
// you can define custom flags
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
}
})
}
Be aware that I have Never done this before. I am just pointing you to the correct documentation.

Run behat chrome headless (without selenium?)

I ran Behat test on PhantomJS without issue. I was starting it with this:
bin/phantomjs --webdriver=8643
It works, but I want to run a Chrome headless instead of PhantomJS. To do that I tried this:
google-chrome --headless --remote-debugging-port=8643
But Behat doesn't seem to start anything on this Chrome. I found a lot of docs for Chrome with Selenium but I wanted to know if it's possible to run it like I was running PhantomJS with the Selenium driver, but without Selenium server?
default:
suites:
default:
contexts:
- FeatureContext
- Behat\MinkExtension\Context\MinkContext
extensions:
Behat\MinkExtension:
base_url: 'http://myurl.com/'
sessions:
default:
selenium2:
wd_host: 'http://localhost:8643'
To run your tests on Google Chrome, you will need chromedriver
Then you can use the port chromedriver is listening to (9515 by default) instead of PhantomJs 8643. You don't need Selenium anymore then.
Finally, you pass the --headless flag to chrome so you don't need xfvb.
A config example:
# behat.yml
default:
extensions:
# ...
Behat\MinkExtension:
base_url: 'http://myurl.com/'
sessions:
default:
selenium2:
browser: chrome
# Note: I'm not totally sure you still need the /wd/hub path
wd_host: http://localhost:9515/wd/hub
capabilities:
chrome:
switches:
- "--headless"
More documentation: https://developers.google.com/web/updates/2017/04/headless-chrome
This worked for me on Ubuntu 16.04 LTS
Installed latest version of chromedriver via https://medium.com/caendra-tech/acceptance-tests-with-behat-and-chrome-headless-2824aaa31fd7
Start chromedriver in the background on default port chromedriver &
Update behat.yml to
default:
extensions:
Behat\MinkExtension:
sessions:
default_session:
selenium2:
browser: chrome
wd_host: http://127.0.0.1:9515
capabilities:
chrome:
switches:
- "--headless"
- "--disable-gpu"

Setting up Protractor with Microsoft Edge

I use CucumberJs and Gulp to run my e2e tests; However, I need to run them against Microsoft Edge. When I do gulp protractor, it successfully opens up both Chrome and Firefox, since neither of them require any drivers like IEDriver.exe or EdgeDriver.exe.
Could anyone point me to an article or show the steps below if it's simple on how to set up Protractor with Microsoft Edge?
I'm trying to achieve parallelism by executing my tests on multiple browsers; this is what my config looks like:
exports.config = {
framework: 'cucumber',
shardTestFiles: true,
maxInstances: 2,
multiCapabilities: [
{
'browserName': 'MicrosoftEdge',
'platform': 'windows',
}
},
{
'browserName': 'firefox',
loggingPrefs: {
driver: 'DEBUG',
server: 'INFO',
browser: 'ALL'
}
}],
//more configs here
}
I achieved the config right above, to run protractor e2e tests in parallel, using this article: http://blog.yodersolutions.com/run-protractor-tests-in-parallel/
Also one for IE driver would be just as helpful if you don't know how to set up Edge.
UPDATES:
From this link: https://msdn.microsoft.com/en-us/library/mt188085(v=vs.85).aspx; under the
Enabling WebDriver with Microsoft Edge:
Download a WebDriver language binding of your choice. Currently C# and
Java Selenium language bindings are supported.
I'm not using Java or C#, I am only using Javascript (Protractor); does that mean that the language binding for Javascript currenlty does NOT work for Edge browser?
In other words, we currently cannot automate the Edge browser using Protractor (Javascript)?
Any help much appreciated and I'll update this post if I find anything pertaining to setting up Protractor with Edge, been looking around the web for hours now.
After some struggle, I got Protractor to work on Microsoft Edge on my Windows 10 system.
Note: I'm using the Jasmine2 framework instead of Cucumber, but I believe the steps below should work for Cucumber as well. I'll try with Cucumber later and update here.
Here are the steps:
Get the Microsoft EdgeHTML version number in use in your system. In my case it is 15.15063. Take a note of the release number here. In this case it is 15063.
(Q.: How to get the Microsoft EdgeHTML version number?
A.: Edge browser > ... > Settings > About this app)
download the correct Release of MicrosoftWebDriver.exe from https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
In my case I downloaded Release 15063. If you get the wrong release, then you are likely to run into an error like this error:
"This version of MicrosoftWebDriver.exe is not compatible with the installed version of Windows 10."
place the MicrosoftWebDriver.exe in the folder where the other drivers are like:
C:\Users\yourname\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\selenium\
Adjust your conf.js file. Essentially, this is what conf.js should have:
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: // or multiCapabilities:
{
'browserName': "MicrosoftEdge"
}
start the webdriver-manager like this:
C:\your\path>webdriver-manager start --edge C:\Users\yourname\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\selenium\MicrosoftWebDriver.exe
You are all set to run your Protractor tests on the Edge browser.
Good Luck!
In windows to download the MicrosoftEdge Webdriver for the HTML version >= 18 then follow the below steps
Open Command Prompt, issue the following command and wait until operation gets completed
DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
Open the File Explorer and navigate to C:\Windows\WinSxS and search for MicrosoftWebDriver and it will display two results, copy the webdriver from the amd64_microsoft-webdriver-server-components10.0.18362.1_none and paste it in
/c/Users/Administrator/AppData/Roaming/npm/node_modules/protractor/node_modules/webdriver-manager/selenium
(Note: Using git bash, it's easy to copy the Webdriver)
In the config file of Edge browser, make the following changes
seleniumArgs:['-Dwebdriver.edge.driver=C:\\Users\\Administrator\\AppData\\Roaming\\npm\\node_modules\\protractor\\node_modules\\webdriver-manager\\selenium\\MicrosoftWebDriver.exe'],
capabilities: {
'browserName': 'MicrosoftEdge',
'maxInstances': 1,
'platformName': 'windows',
'nativeEvents': false,
shardTestFiles: true,
},
Open the command prompt, and navigate to project repo and issue the following command to start the edge session
webdriver-manager start --edge "C:\Users\Administrator\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\selenium\MicrosoftWebDriver.exe"
I'm using Angular 9 with Edge 89 within linux
The following config worked for me
exports.config = {
directConnect: true,
chromeDriver: '/path/to/ms-edge/webdriver'
capabilities: {
browserName: 'chrome',
chromeOptions: {
binary: '/usr/bin/microsoft-edge'
}
},
},
Official WebDriver can be found here
Since Edge uses Chromium engine, we can reuse all chrome configs and just replace WebDriver and binary path.
Looks like the Protractor folks are now working on adding Edge support for Protractor. Take a look at the recently opened issue on GitHub.
Download the correct release of EdgeHTML webdriver ( https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ ), then settup the conf.js as:
seleniumArgs: ['-Dwebdriver.edge.driver=C:\\Program Files (x86)\\Microsoft Web Driver\\MicrosoftWebDriver.exe'],
Capabilities: {
'browserName': 'MicrosoftEdge',
'maxInstances': 1,
'platformName': 'windows',
'nativeEvents': false,
}
Now Microsoft Edge is supported on Mac Operating System. So to setup in Mac follow below steps
Download the MicrosoftEdge WebDriver from the following link according to version of the edge browser configured in Mac
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Unzip the folder and copy the Unix executable file to following path
/usr/local/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/MicrosoftWebDriver
In the config file add SeleniumArgs attribute and capabilities
seleniumArgs : ['-Dwebdriver.edge.driver=/usr/local/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/MicrosoftWebDriver'],
capabilities: {
browserName: 'MicrosoftEdge',
platformName: 'Mac OS X',
browserVersion: '79.0.309.65',
maxInstances: 1,
shardTestFiles: true,
elementScrollBehavior: 1,
nativeEvents: false
},
In order to start the web driver with Edge Session, use below command..
java -jar -Dwebdriver.edge.driver=/usr/local/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/MicrosoftWebDriver /Users//Desktop/Project/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.141.59.jar -port 4444
Edge won't work with directconnect: true. Please refer below example.
directConnect: false,
multiCapabilities: [
{​​​​​
browserName: 'chrome',
chromeOptions: {​​​​​
args: ['--disable-popup-blocking'],
}​​​​​
}​​​​​,
{​​​​​
browserName: 'firefox'
}​​​​​,
{​​​​​
browserName: 'MicrosoftEdge'
}​​​​​
],
jvmArgs: [
'-Dwebdriver.chrome.driver=./src/driver/chromedriver_87.0.4280.20.exe',
`-Dwebdriver.edge.driver=${edgeDriver}`,
'-Dwebdriver.gecko.driver=./src/driver/geckodriver-v0.28.0.exe'
],
Use below code outside config if using mac
const edgeDriver =
process.platform === 'darwin'
? './src/driver/edgedriver_mac64_87.0.664.47/msedgedriver'
: './src/driver/msedgedriver.exe';

Testing Behat Scripts in Googlechrome

I am trying to run my scripts using Google chrome ..
In behat.yml
default:
extensions:
Behat\MinkExtension\Extension:
base_url: http://downingtown.calendar.comcast.net/prefs
javascript_session: selenium
browser_name: googlechrome
goutte: ~
selenium: ~
I am running the selenium like
java -jar selenium.jar -Dwebdriver.chrome.driver=D:\mypgms\NewMng\chrome\chromeDriver.exe
But i am getting SSL certificate Error . Then I could not able to proceed further .
1.Am i missing anything ?
2.Can i disable SSL certificate ?
In behat.yml
default:
extensions:
Behat\MinkExtension\Extension:
base_url: http://downingtown.calendar.comcast.net/prefs
javascript_session: selenium2
selenium2:
browser: chrome
goutte: ~
For more information, look at Extension.php

Selenium - codeception - chrome issue

I get the following errors in random when running test on chrome using codeception in selenium server:
WebDriver\Exception\UnknownError: The current platform is not supported: LINUX
WebDriver\Exception\UnknownError: Unable to find executable for product Opera Desktop
WebDriver\Exception\UnknownError: The path to the driver executable must be set by the phantomjs.binary.path capability/system property/PATH variable; for more information, see https://github.com/ariya/phantomjs/wiki. The latest version can be downloaded from http:\//phantomjs.org/download.html
When given firefox, it works fine.
command for running selenium:
java -jar selenium-server-standalone-2.31.0.jar -browser googlechrome
Following is the acceptance.yml content
class_name: WebGuy
modules:
enabled:
- Selenium2
- WebHelper
config:
Selenium2:
url: 'http://www.google.com'
browser: googlechrome
delay: 350
To run codeception with Chrome, use the following acceptance.suite.yml:
class_name: WebGuy
modules:
enabled:
- Selenium2
- WebHelper
config:
Selenium2:
url: 'http://www.google.com'
browser: chrome
delay: 350
Note that i changed your browser in the config from googlechrome to chrome.
Also, start Selenium2 by using this command:
java -Dwebdriver.chrome.driver=./chromedriver -jar selenium-server-standalone-2.31.0.jar
Note that you don't need to specify the browser when starting selenium.
You can download chromedriver here. You should also update your selenium standalone server; you can get the latest version from here.