WebdriverIO setting browser language problem for headless chrome browser on linux server - webdriver-io

I am using webdriverio for test automation and I am trying to change my chrome browser configurations via wdio.config.js file. I am running chrome headless browser and locally everything geos fine, but on the linux server it looks like the language setting doesn't take an effect.
An additional detail is that I have 2 jobs in the pipeline (1 for English and one for Netherlands language) but it seems both of them are running in English.
Here are my browser capabilities section:
{
maxInstances: 1,
browserName: 'chrome',
'goog:chromeOptions': {
args: [
'--headless',
'--disable-dev-shm-usage',
'--disable-gpu',
'--window-size=1920,1080',
'--disable-web-security',
'--lang=nl',
'ignore-certificate-errors'
],
},
}

Related

How to run feature files in Safari using WebDriverIO?

I'm using WebDriverIO to automate a web page, I'm able to run my feature files in Chrome but I need them to run in Safari. I'm using a Mojave 10.14.6 device. I've allowed remote automation on safari, and enabled safaridriver from terminal.
My wdio.conf.js capabilities are look like this:
capabilities: [{
maxInstances: 5,
browserName: 'safari'
}]
When I run using chrome it works as spected but in the case of safari I get the following message:
ERROR webdriver: RequestError: connect ECONNREFUSED 127.0.0.1:4444
My package.json looks like this:
"dependencies": {
"#wdio/cli": "^7.5.7"
},
"devDependencies": {
"#wdio/cucumber-framework": "^7.5.3",
"#wdio/local-runner": "^7.5.7",
"#wdio/spec-reporter": "^7.5.7",
"chromedriver": "^90.0.0",
"wdio-chromedriver-service": "^7.0.0"
}
Is there any other configuration I need to add in wdio.conf.js file?
Thanks in advance.
It turns out to be a problem with the port that was being used. After the port was changed from 4444 to the correct value, the issue was solved.

How to run it blocks in parallel in protractor?

My spec file covers 50 different test cases for a specific test scenario. Each test case is covered in individual it block. The spec file takes 2 hrs to execute. I want to categorize it blocks in a way so that they run in parallel in multiple browser instances. For e.g. it should run like (5 it blocks * 10 browser instances) in parallel. I don't want to divide the spec file in different parts. Is there any alternate solution?
When you decide to execute your test cases, use any configuration listed below. Please refer a typical conf.js file and choose any of the configuration in conf.js file.
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'
},
specs: ['spec1.js','spec2.js']
};
Type-1: Single browser instance : start one browser instance at a
time.
example configuration in the conf.js file.
capabilities: {
browserName: 'chrome',
},
specs: ['spec1.js','spec2.js']
The above configuration will launch chrome browser instance and executes all specs one by one
sequestial --> [chrome] --> spec1.js --> spec2.js
Type-2: Different browser instance will launch in parallel and all the
specs which is mensioned in the spec:[] tag will execute in each
browser's instance separately.
example configuration in the conf.js file.
multiCapabilities: [
{ browserName: 'chrome', },
{ browserName: 'firefox', },
],
specs: ['spec1.js','spec2.js','spec3.js']
The above configuration will launch chrome, firefox browsers and executes all specs in each browser instance parallel.
--> [chrome] ---|--> spec1.js --> spec2.js --> spec3.js
|
parallel
|
--> [firefox] ---|--> spec1.js --> spec2.js --> spec3.js
Type - 3: The below configuration will help you to execute different
set of specs in different browser instances.
example configuration in the conf.js file.
multiCapabilities: [
{
browserName: 'chrome',
specs:['spec1.js']
},
{
browserName: 'firefox',
specs:['spec2.js']
},
],
The above configuration will launch chrome, firefox browsers and executes spec1.js in chrome and spec2.js in firefox instances
--> [chrome] ---|--> spec1.js
|
parallel
|
--> [firefox] ---|--> spec2.js
Type - 4: Execute different spec files in parallel with same browser.
Consider you have 5 spec files in your test suit and you want to
execute everything in parallel. The below configuration will help you
to do that.
example configuration in the conf.js file.
capabilities: {
browserName: 'chrome',
specs: [
'spec1.js', 'spec2.js', 'spec3.js' , 'spec4.js' , 'spec5.js'
],
maxInstances : 5,
shardTestFiles: true
}
The above configuration will launch 5 chrome instances and each spec will execute in those 5 chrome instances in parallel.
|-- [instance 1] --|--> spec1.js
|-- [instance 2] --|--> spec2.js
--> [chrome] ---|-- [instance 3] --|--> spec3.js
|-- [instance 4] --|--> spec4.js
|-- [instance 5] --|--> spec5.js
The maxInstances number represents the maximum amount of browser windows that Protractor is allowed to create.
For example, with maxInstances set to 10, a test suite of 200 tests would result in Protractor creating 10 Chrome instances with each instance running 20 tests, whereas without shardTestFiles this would be one Chrome instance running all 200 tests.
You are unable to run "it" blocks parallel from within the same spec file. The alternate solution would be to divide up your spec file such as spec1.js, spec2.js, andspec3.js
You would then add this to your conf.js file
specs:['filePath/spec1.js','filePath/spec2.js','filePath/spec3.js'],
capabilities: {
shardTestFiles: true,
maxInstances: 5 //set this to amount you want running at once
}
The specs param will accept arrays, or you can use wildcards such as filePath/*.js which would run all .js files within that folder (Make sure they are are protractor test cases)
maxInstances will be set to the amount running at once. I find it easier to use headless mode when running multiple instances at once, for chrome the option looks like:
chromeOptions: {
args: ["--headless", "--disable-gpu", "--window-size=1920,1080"]
}

Selenium doesn't start webdriver

versions
"nightwatch": "^0.9.16"
"chromedriver": "^2.30.1"
"selenium-server-standalone-jar": "^3.4.0"
I'm using nightwatch but that sh
I also tried with
I'm using nightwatch to run Selenium in this repo and I've tried with chrome and firefox drivers, no luck on either.
I have selenium standalone and chromedriver packages, and I know the path is right on nightwatch.conf.js:
const jar = require('selenium-server-standalone-jar')
console.log(jar.path) // logs /home/goldylucks/apps/ci-workshop/node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-3.4.0.jar
const chromedriver = require('chromedriver')
console.log(chromedriver.path) // logs /home/goldylucks/apps/ci-workshop/node_modules/chromedriver/lib/chromedriver/chromedriver
'selenium': {
'start_process': true,
'server_path': jar.path,
'log_path': '',
'port': 4444,
'cli_args': {
'webdriver.chrome.driver': chromedriver.path,
'webdriver.ie.driver': '',
},
},
'test_settings': {
'chrome': {
'desiredCapabilities': {
'browserName': 'chrome',
'javascriptEnabled': true,
'acceptSslCerts': true,
},
},
yet when I run the test it times out and hangs:
$ yarn e2e:ui
yarn e2e:ui v0.24.6
$ nightwatch -e chrome
Starting selenium server... started - PID: 12936
[App E2e Ui] Test Suite
===========================
✖ Timed out while waiting for element <body> to be present for 5000 milliseconds. - expected "visible" but got: "not found"
at Object.before (/home/goldylucks/apps/ci-workshop/test/ui/app.e2e-ui.js:9:8)
I tried it with the following combinations:
1. with the express server which serves the app on another terminal
2. without the express server
3. each of the above with chromedriver manually started at another terminal (I really don't think it should matter and that I should do this, just wanted to be thorough ...)
running the chromedriver manually yields the following and hangs:
$ node_modules/chromedriver/lib/chromedriver/chromedriver
Starting ChromeDriver 2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5) on port 9515
Only local connections are allowed.
I also tried running with firefox and it didn't work, which leads me to believe the problem is deeper than the chromedriver, i.e. related to selenium interacting with nightwatch.
I recall this happening a while back. I think it was that a previous instance Selenium had not closed freed port 4444 when shutting down. Try shutting down selenium and restarting.
To do that, open the following webpage manually, in the browser of your choice.
http://localhost:4444/selenium-server/driver?cmd=shutDownSeleniumServer
Then try running the script again as normal.

Create new WebDriver session for each spec file

We have a bunch of e2e protractor tests on jasmine2 framework and recently we started to run them on SauceLabs.
SauceLabs has a restriction that one WebDriver session can not run longer than 30 mins. This makes perfect sense to me, however causes our tests to fail as protractor runs all our tests in a single WebDriver session.
So I'm wondering how can I initiate new WebDriver session, say for each spec file or for each 'describe'? Or there is a solution that protractor can offer out of the box?
Timeout increase is not an option for me.
Many thanks.
I believe that's what you are looking for:
{
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 5
},
Use this in your config.js file and make sure to divide the tests among multiple spec files. I am using this in my tests (an example here), and it is working fine for me.
{
'name': 'Window10 -Chrome-tests',
'browserName': 'chrome',
shardTestFiles: true,
platform: 'Windows 10',
screenResolution: '1376x1032',
maxInstances: 5
},

Setting up selenium grid to use Microsoft edge

Environment:
win10 (build 10240)
Vaadin Testbench 4.1
Selenium 2.53
Drivers for Firefox, Chrome, IE11 and Edge for build 10240
Node and hub
start java -jar c:\users\powder\vaadin-testbench-standalone-4.1.0.jar -role hub
start java -jar c:\users\powder\vaadin-testbench-standalone-4.1.0.jar -role node -Dwebdriver.edge.driver=c:\users\powder\MicrosoftWebDriver.exe
Usage in java code
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(DesiredCapabilities.edge().getBrowserName());
//DesiredCapabilities capabilities = DesiredCapabilities.edge(); Tried as well
capabilities.setCapability("acceptSslCerts", "true");
setDriver(new RemoteWebDriver(new URL(this.remoteHubUrl), capabilities));
getDriver().get("http://www.google.com");
Errormessage
Error forwarding the new session cannot find : Capabilities [{acceptSslCerts=true, browserName=MicrosoftEdge}]
Selenium grid console - edge is missing
Everything is working fine with other browsers, but not with Edge. Any ideas how to fix that?
There are 2 problems here:
First, if you look at the default node config you will notice that only Firefox, Chrome and IE are enabled by default (that's why all you need to use them is specify driver location via a system property). If you want to use any other browser then you need to use your own json config:
{
"capabilities": [
{
"browserName": "MicrosoftEdge",
"platform": "WIN10",
"maxInstances": 1
},
{
"browserName": "firefox",
"platform": "WIN10",
"maxInstances": 5
},
{
"browserName": "chrome",
"platform": "WIN10",
"maxInstances": 5
},
{
"browserName": "internet explorer",
"platform": "WIN10",
"maxInstances": 1
}
],
"hub": "http://selenium-hub-host:4444"
}
and pass it to your command line:
java "-Dwebdriver.edge.driver=c:\path\to\MicrosoftWebDriver.exe" "-Dwebdriver.gecko.driver=c:\path\to\geckodriver.exe" "-Dwebdriver.chrome.driver=c:\path\to\chromedriver.exe" "-Dwebdriver.ie.driver=c:\path\to\IEDriverServer.exe" -jar "c:\path\to\selenium-server-standalone.jar" -role node -nodeConfig "c:\path\to\the\above.json"
(btw: alternatively you can also put the whole config in your command line using multiple -capabilities or -browser params)
This in theory should work. However in practice you will often be hit by the 2nd problem, which is: "sometimes it randomly doesn't work" ;] Initially everything will look fine: your grid will properly report Edge browser capability on the console, it will properly delegate tests to a node containing Edge, the node will properly start Edge browser, however the browser will sometimes freeze on its initial blue screen with e logo and after few seconds you will get some exception on the client side without any meaningful stack-trace nor message (I don't have it saved anywhere to paste here now).
Some people suggested a workaround to start 2 separate nodes on the same machine (on different ports of course) : one only for Edge and second for IE, FF and Chrome. This way it seems to work pretty stable (tested on Edge build 15063 running on win-10 and Selenium-3.4.0)
Additional info:
Apart from the above, Edge driver has few limitations that require specific workarounds in the configuration:
currently only 1 concurrent session is supported by the driver/browser so maxInstances must be set to 1 (kudos to this answer)
the driver must be running in the foreground, so that the browser window can be actually displayed on the desktop. Therefore the node cannot be started as a Windows Service nor from Windows Task Scheduler at startup. The best way to automate starting of the node is to configure auto-login and add a batch script starting the node to user's Startup Programs as described in my article
Try putting the -D parameters before the -jar parameter. I had an issue where it thought -Dwebdriver..... was a parameter to selenium itself instead of java.