Mink with Selenium2 : how to connect to selenium server? - selenium-webdriver

i'm trying to configure Behat tests with selenium server.
my behat.yml is:
default:
paths:
features: features
bootstrap: %behat.paths.features%/bootstrap
extensions:
Behat\MinkExtension\Extension:
base_url: 'http://prog.easyhospi.itg.crmsante.com/'
default_session: 'selenium2'
browser_name: 'firefox'
selenium2:
wd_host: 'http://127.0.0.1:5555/wd/hub'
capabilities: { "browser": "firefox", "version": "29"}
i ran selenium server this way:
java -jar selenium-server-standalone-2.41.0.jar -role hub
and then:
java -jar selenium-server-standalone-2.25.0.jar -role node -hub http://localhost:4444/grid/register -browser browserName=firefox,version=29,maxInstances=1
I have got the error message "Could not open connection"
What is missing?

Capabilities of at least one node need to match capabilities requested from behat. Last time I used selenium grid, I needed to set the version to an empty string, otherwise selenium could not match the browser version:
# behat.yml
default:
extensions:
Behat\MinkExtension\Extension:
selenium2:
capabilities:
version: ''
Note that you don't need to run grid. In most cases it's sufficient to run selenium as a standalone server (this way no capabilities need to be configured):
java -jar selenium-server-standalone-2.25.0.jar

Ok, sorry for that post, but Curl was missing... didn't see that requirement in the doc.
you are right, selenium grid is not needed, but my behat.yml matches: if i don't specify "default_session: 'selenium2'", i have an error about goutte.
thanks.

Related

Automation test chromium edge

I try to run selenium test with chromium edge version 79.0.309.56.
This is the code for the test but I got an error
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: unrecognized Chrome version: Edg/79.0.309.56
the code is:
System.setProperty("webdriver.edge.driver", "<path to driver>\\msedgedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("<path to browser>\\msedge.exe");
DesiredCapabilities m_capability = DesiredCapabilities.edge();
m_capability.merge(chromeOptions);
EdgeOptions edgeOptions = new EdgeOptions().merge(chromeOptions);
try{
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://<ip>:80/wd/hub"), m_capability);
driver.get("http://www.google.com");
} catch (MalformedURLException e) {
e.printStackTrace();
}
I didn't find a solution for this error.
Thanks
What version of selenium server and Microsoft Edge (Chromium) driver are you using? I use selenium-server-standalone-3.141.59.jar and Microsoft Edge (Chromium) driver 79.0.309.43 and the code can work well when automating Microsoft Edge (Chromium) 79.0.309.56.
How do you launch the hub and the node? You could refer to my steps below:
Launch a hub: using the command prompt, navigate to the path of selenium server, then type on the command prompt:
java -jar selenium-server-standalone-3.141.59.jar -role hub -maxSession 10 -port 4444
Launch a node: navigating to the same path and type on the command prompt:
java -Dwebdriver.chrome.driver="your\path\to\webdriver\msedgedriver.exe" -jar selenium-server-standalone-3.141.59.jar -role webdriver -hub http://<your_ip>:4444/grid/register -port 3333
After launching successfully, run the code you providing and the Capabilities will show on the command prompt like this:
INFO [ActiveSessionFactory.apply] - Capabilities are: {
"browserName": "chrome",
"goog:chromeOptions": {
"args": [
],
"binary": "C:\\Program Files (x86)\\Microsoft\\Edge Beta\\Application\\msedge.exe",
"extensions": [
]
},
"platform": "WINDOWS",
"version": ""
}
Reference: Selenium Grid Tutorial: Hub & Node (with Example)

How to specify "binary" path for remote chromedriver in codeception?

I'm trying to use a remote chromedriver with codeception. I'm currently able to connect to the chromedriver, because if I don't start it, I get a different error (after a long timeout). However, the chromedriver isn't able to start chrome on that windows VM because it's not installed in the path it's searching it for. I tried to override it but can't find the way to setup codeception for that options.
Here's what I tried in my acceptance.suite.yml:
WebDriver:
host: 10.0.15.15
port: 9515
url: 'http://www.box.dev'
browser: 'chrome'
capabilities:
binary: "C:\\\\Program Files (x86)\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe"
I tried a couple variations over the binary format with \ \ \\ \\ and /. Chrome just don't show up... There isn't much "output" from the chromedriver so I'm going a little bit blind on that...
The chromedriver should run on the host system. You have to start selenium with an option, which says selenium where the chromedriver.exe is located.
java -jar selenium-server-standalone-2.41.0.jar -role node -hub http://www.box.dev:9515/register/grid Dwebdriver.chrome.driver="C:/Users/me/Downloads/chromedriver.exe"
Then you only need to say in your codeception configuration, that you want to use the browser chrome (it should be installed there).
The acceptance.suite.yml that works for me on Windows looks like.
capabilities:
chromeOptions:
args: ["disable-infobars", "headless","disable-gpu", "window-size=1920x1080"]
binary: "C:/Users/***/chrome.exe"

How can I configure the firefox binary location in Protractor?

I am successfully running Protractor tests with Chrome, specifying the path to my chrome binary using the following section in my Protractor configuration:
capabilities: {
// You can use other browsers
// like firefox, phantoms, safari, IE
'browserName': 'chrome',
"chromeOptions": {
binary: 'C:/BuildSoftware/Chrome/Application/chrome.exe',
}
This works.
My Firefox is also installed in a non-standard location.
Is there an equivalent way to specify the binary for Firefox in the protractor config?
UPDATED: See newer answer below: https://stackoverflow.com/a/28313583/800699
It seems you have to start the Selenium Server by yourself with custom arguments for firefox driver.
See Protractor test is not starting on Firefox
More options for firefox driver (including custom firefox binary location) can be found here:
https://code.google.com/p/selenium/wiki/FirefoxDriver
P/S: Browsing the firefox driver source reveals more light:
https://code.google.com/p/selenium/source/browse/javascript/node/selenium-webdriver/firefox/index.js
You can try adding:
"browserName": "firefox",
"firefox_binary": "path/to/custom/firefox",
"binary_": "path/to/custom/firefox"
Protractor now supports setting the firefoxPath directly in the configuration file, when using "direct connect" (i.e., without a selenium server). See the reference config file:
https://github.com/angular/protractor/blob/master/docs/referenceConf.js#L67
Add firefoxPath to the config file, at the top-level. It is a string that should be the path to your firefox binary. You will also need directConnect: true in the config.
For more details (handy to see all the doc that changed at once) check out the change that added this support (in Oct 2014).
It's 2018 and it appears you can set a specific binary argument within the 'moz:firefoxOptions' section of the capabilities like so:
capabilities: {
browserName: 'firefox',
'moz:firefoxOptions': {
args: [...Your args here...],
binary: '/Path/To/Custom/firefox'
}
}
Disclaimer: I ran this with directConnect: true in my protractor config also. I'm not sure if it works if you're passing the command to the Selenium server.
Reference: https://github.com/mozilla/geckodriver/blob/master/README.md#mozfirefoxoptions
I added my custom binary location to PATH variable.
export PATH="/custom-firefox-location:$PATH"
That makes my custom firefox version to be available during the session and when running protractor it uses that.
To elaborate Monkpit's answer which is correct .Below code is worked for me , verified and tested in protractor v 5.4.2 .
Only thing is needed to open the cmd via admin mode to avoid the permission error since I installed Firefox in program files.
capabilities: {
browserName: 'firefox',
'moz:firefoxOptions': {
args: ['--verbose'],
binary: 'C:/Program Files/Mozilla Firefox/firefox.exe'
//Need to start cmd via admin mode to avoid permission error
}
},
Full code
exports.config = {
framework: 'jasmine',
directConnect: false, //Start protractor without start the selenium server using webdriver-manager start. default value is fales
//This is only for chrome and firefox and use drivers instead of selenium server
capabilities: {
browserName: 'firefox',
'moz:firefoxOptions': {
args: ['--verbose'],
binary: 'C:/Program Files/Mozilla Firefox/firefox.exe'
//Need to start cmd via admin mode to avoid permission error
}
},
//set to true So each spec will be executed in own browser instance. default value is false
//restartBrowserBetweenTests: true,
jasmineNodeOpts: {
//Jasmine provides only one timeout option timeout in milliseconds don't add ;
defaultTimeoutInterval: 180000
},
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['src/com/sam/scriptjs/iframes.spec.js']
}

Running Protractor tests on Browserstack Automate

I'm developing an AngularJS app and want to do end-2-end testing with Protractor. I would like to benefit from the suite of test browsers available at Browserstack and run the tests on Browserstack Automate instead of a local Selenium server.
How do I set up a system to run these tests?
NOTE: These instructions are only relevant for Protractor versions older than v3.0. Protractor 3.0 includes built-in support for Browserstack.
Prerequisites
You will need to have node and npm installed. Check your node version with node --version to ensure it is greater than v0.10.0.
Ready?
1. Install Protractor
Use npm to install Protractor globally with:
npm install -g protractor
If you get errors, you might need to run the above command as sudo.
Here's a more detailed tutorial for installing and using Protractor.
2. Install Browserstack Selenium web driver
EDIT: #elgalu pointed out in the comments this step is not necessary. Apparently the BrowserStackLocal tunnel (set up in step 4) is enough.
Following Browserstack's instructions for setting up node.js, install the seleniun web driver:
npm install -g browserstack-webdriver
3. Set up Protractor configuration
Create a protractor.conf.js file (see documentation for BrowserStack's supported capabilities):
exports.config = {
capabilities: {
'browserstack.user' : 'my_user_name',
'browserstack.key' : 'my_secret_key',
// Needed for testing localhost
'browserstack.local' : 'true',
// Settings for the browser you want to test
// (check docs for difference between `browser` and `browserName`
'browser' : 'Chrome',
'browser_version' : '36.0',
'os' : 'OS X',
'os_version' : 'Mavericks',
'resolution' : '1024x768'
},
// Browserstack's selenium server address
seleniumAddress: 'http://hub.browserstack.com/wd/hub',
// Pattern for finding test spec files
specs: ['test/**/*.spec.js']
}
Change your user name and secret key to the ones given on the Browserstack Automate page. If you're logged in to Browserstack, the instructions for setting up node.js will have you user and key substituted in the examples, and you can just copy-paste the javascript from there.
The same page also has a tool for generating the code for different test browser settings.
4. Download and run BrowserStackLocal
Download the BrowserStackLocal binary from the node.js instructions page.
Make the following changes to the command below, and run the binary to open the Browserstack tunnel required for testing.
Change your secret key in the command. Again, your_secret_key will be automatically substituted in the node.js guide, if you're logged in to Browserstack.
Change the port number to match the port you're hosting your AngularJS files at on localhost. The example uses port 3000.
./BrowserStackLocal your_secret_key localhost,3000,0
5. Run the tests
With everything ready for testing, run your tests:
protractor protractor.conf.js
You can watch the test run on Browserstack Automate and even see an updating live screenshot of the test browser.
Protractor from version 3.0.0 onwards has added inbuilt support for BrowserStack.
You simply need to add the following two parameters in your conf.js to launch the test on BrowserStack:
browserstackUser: '<username>'
browserstackKey: '<automate-key>'
Your username and automate key can be found here, after you have logged in to your account.
Hence, lets say you wish to run your test on Chrome 50 / OS X Yosemite, your conf.js should look something like this:
exports.config = {
specs: ['spec.js'],
browserstackUser: '<username>',
browserstackKey: '<automate-key>',
capabilities: {
browserName: 'Chrome',
browser_version: '50.0',
os: 'OS X',
os_version: 'Yosemite'
},
};
If you wish to run tests in parallel on different browser and OS combinations, you can use the multiCapabilities as given below:
exports.config = {
specs: ['spec.js'],
browserstackUser: '<username>',
browserstackKey: '<automate-key>',
multiCapabilities: [
{
browserName: 'Safari',
browser_version: '8.0',
os: 'OS X',
os_version: 'Yosemite'
},
{
browserName: 'Firefox',
browser_version: '30.0',
os: 'Windows',
os_version: '7'
},
{
browserName: 'iPhone',
platform: 'MAC',
device: 'iPhone 5S'
}
]
};
Some helpful links:
Code Generator - Helps you configure the capabilities to test on different various browser and OS combinations especially mobile devices.
Sample Github project for Protractor-BrowserStack - This should help you get started.
Hello! To only run the test against Browserstack, you may need to skip Step 4 from Niko Nyman answer, and in your conf.js you should have something like here's the one that I've used (+ report), then run Step 5:
var HtmlReporter = require('protractor-html-screenshot-reporter');
var reporter=new HtmlReporter({
baseDirectory: './protractor-result', // a location to store screen shots.
docTitle: 'Report Test Summary',
docName: 'protractor-tests-report.html'
});
// An example configuration file.
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://hub.browserstack.com/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome',
'version': '22.0',
'browserstack.user' : 'user_name',
'browserstack.key' : 'user_key',
'browserstack.debug' : 'true'
},
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['./specs/home_page_spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
},
onPrepare: function() {
jasmine.getEnv().addReporter(reporter);
}
};
We just wrote a blog post and open-source modules for this.
http://www.blog.wishtack.com/#!Cross-browser-testing-test-automation-with-Protractor-and-Browserstack/cuhk/554b3b5f0cf27313351f1163
wt-protractor-boilerplate
wt-protractor-runner
wt-protractor-utils

Getting Selenium Going for Use with Protractor for my AngularJS app

I'm building an AngularJS app on Windows. I want to create end-to-end tests with Jasmine. From my understanding, I need protractor to run these kinds of tests. For that reason, I've added the following to my package.json:
"devDependencies": {
...
"grunt-protractor-runner": "0.2.4",
"selenium-webdriver":"2.41.0",
...
}
In my gruntfile.js, I've configured Protractor as such:
grunt.initConfig({
protractor: {
options: {
configFile: "node_modules/protractor/referenceConf.js", // Default config file
keepAlive: true, // If false, the grunt process stops when the test fails.
noColor: false, // If true, protractor will not use colors in its output.
args: {
// Arguments passed to the command
}
},
tests: {
options: {
configFile: "tests/config/e2e.conf.js",
args: {} // Target-specific arguments
}
},
}
});
I'm then running the protractor:tests target. The contents of e2e.conf.js look like the following:
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to the location of the spec file. They may
// include glob patterns.
specs: ['../../tests/e2e/user-tests.e2e.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
}
};
Now, when I run grunt from the command-line, I get an error that says:
Using the selenium server at http://localhost:4444/wd/hub
C:\Projects\MyProject\node_modules\grunt-protractor-runner\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1702
throw error;
^
Error: ECONNREFUSED connect ECONNREFUSED
...
I don't understand why I'm getting this error. I see in the Protractor Getting Started Guide that it expects a selenium standalone server to be running. However, I thought that was the purpose of the Grunt task runner: start the selenium server. I see webdriver-manager in node_modules\grunt-protractor-runner\node_modules\protractor\bin, however, if I change to that directory and run webdriver-manager update from the command-line, I get an error that says:
'webdriver-manager' is not recognized as an internal or external command,
operable program or batch file.
How do I get the selenium piece going so that I can run end-to-end tests with protractor?
Thank you!
Have you tried with "node" command ?
It worked for me :
node .\node_modules\grunt-protractor-runner\node_modules\protractor\bin\webdriver-manager update
This should download for you chromedriver and selenium server. If not, ou can also manually download/extract :
http://selenium-release.storage.googleapis.com/2.40/selenium-server-standalone-2.40.0.jar
https://chromedriver.storage.googleapis.com/2.9/chromedriver_win32.zip
in :
src/test/config/selenium/selenium-server-standalone.jar
src/test/config/selenium/chromedriver.exe
An other thing is that you need to be sure that Chrome is isntalled in :
<WINDOWS_USERS_FOLDER>\<USERNAME>\AppData\Local\Google\Chrome\Application\chrome.exe
First up:
There are many components in there that I don't understand :)
Feel free to add comments to help me improve my answer.
I do know some Selenium so here goes.
seleniumAddress: 'http://localhost:4444/wd/hub',
To me, this line indicates that you are trying to run the Selenium Grid Server.
Here's how to start it: (yes, it needs to be started manually as far as I know)
From a separate console, run the following:
java -jar selenium-server-standalone-2.41.0.jar -role hub
#now wait a few seconds for the hub to start
java -jar selenium-server-standalone-2.41.0.jar -role node -hub http://localhost:4444/grid/register
What did we just do?
Started a hub. This hub is like a test distributor - it receives the requests.
Started a node. (You can start any number of nodes). This node is what will actually conduct the test.
You can verify that this server was started successfully. Just visit the local host link on your browser.
Gotchas:
Check that your firewall is not giving you problems. I've had crippling issues getting started on Windows 7 and finally moved over to Ubuntu (but that's probably just my situation).
Open ports 4444 (for hub), 5555(for node) for both incoming and outgoing connections on Windows Firewall.

Resources