Firefox and Edge capabilities settings for deactivating images - WDIO - selenium-webdriver

This bounty has ended. Answers to this question are eligible for a +100 reputation bounty. Bounty grace period ends in 12 hours.
Asmoun wants to draw more attention to this question.
I want to run cross browsing testing instead of only one browser (Chrome) for configuring Chrome to run headless and deactivate images i use the following in wdio.conf.js file :
browserName: 'chrome',
'goog:chromeOptions': {
args: chrome_args,
prefs: {
"profile.managed_default_content_settings.geolocation": 2,
"profile.managed_default_content_settings.images": 2
}
},
what's the equivalent of that for firefox and Edge ?

The equivalent for Firefox is
browserName: 'firefox',
'moz:firefoxOptions': {
args: ['-headless'],
args: firefox_args,
prefs: {
"geo.enabled": false,
"permissions.default.image": 2
},
"windowSize": "1024x768"
},
The equivalent for Edge is
browserName: 'MicrosoftEdge',
'ms:edgeOptions': {
args: ['-headless'],
args: edge_args,
prefs: {
"geolocation": 2,
"images": 2
},
windowSize: "1280x1024"
},

Related

How to make Chromdriver run in circleci?

In my react project I am using nightwatch for testing. After nightwatch version upgrade from 1.7 -> 2.0 everything is working fine locally(As a side comment everything was working fine on previous 1.7 version as well and had same config I wrote below), but once I push my changes I see that tests are failing in circleci and main reason is that chromdriver can't start. Those are errors I see:
Failed to connect to ChromeDriver on localhost with port 9515
WebDriverError: An error occurred while creating a new ChromeDriver session: [WebDriverError] unknown error: Chrome failed to start: exited abnormally
This is my nightwatch config:
const chrome = require('chromedriver');
module.exports = {
src_folders: ['./tests/e2e/specs'],
test_settings: {
default: {
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: [
'--no-sandbox',
'--headless',
],
mobileEmulation: {
'deviceName': 'iPhone 6/7/8',
},
},
},
filter: '**/*.spec.js',
},
},
webdriver: {
port: 9515,
server_path: chrome.path,
start_process: true,
},
};
Any thoughts?
Thank you!

webdriverIO test on sauceLabs is not working for firefox

I am trying to run a wdio-test on saucelabs for chrome, IE and firefox.
test works fine for chrome and IE, however it fails for firefox with :
Infrastructure Error -- The Sauce VMs failed to start the browser or device.
I am using lastest version of wdio and sauce service:
"devDependencies": {
"#wdio/cli": "^6.1.5",
"#wdio/cucumber-framework": "^6.1.1",
"#wdio/local-runner": "^6.1.5",
"#wdio/sauce-service": "^6.1.0",
"#wdio/spec-reporter": "^6.1.5",
"#wdio/sync": "^6.1.5",
"chromedriver": "^81.0.0",
"wdio-chromedriver-service": "^6.0.2"
}
my browser config:
capabilities: [
{
maxInstances: 3,
browserName: "chrome",
browserVersion: "latest"
},
{
maxInstances: 3,
browserName: "firefox",
browserVersion: "latest",
platform: "windows 10",
"sauce:options": {
seleniumVersion: "3.14.0",
},
},
{
maxInstances: 3,
browserName: "internet explorer",
browserVersion: "latest"
},
],
This is an issue with how WebdriverIO and Sauce Labs handle W3C browser options. You do need to provide a sauce:options capability to use recent versions of Firefox, which would look like this:
capabilities: {
maxInstances: 3,
browserName: 'firefox',
platformName: 'Windows 10',
browserVersion: 'latest',
'sauce:options':
{'seleniumVersion': '3.14.0'}
}
The sauce:options specifies Sauce-only capabilities, such as which version of Selenium WebDriver to use in this case.
I was able to fix it.
In order for the W3C-compliant Selenium capabilities and protocol to work, all non-standard capabilities need to be defined inside the "sacue:options" block. This includes the "build" capability. Also, to specify a platform, the capability name has been changed from "platform" to "platformName". So the capabilities should look like this:
capabilities: {
browserName: 'firefox',
platformName: 'Windows 10',
browserVersion: 'latest',
'sauce:options':
{
'seleniumVersion': '3.14.0',
'build': buildName()
}
}

Trying to run protractor tests in parallel

I'm trying to run a bunch of tests in parallel using protractor.. it seems that I am using all the configs as I should but something isn't right and the tests are running one after the other in the same browser instance.
my .conf file is as follows:
// Some protractor configs
capabilities: {
browserName: 'chrome',
shardTestFiles: true,
maxInstance: 2,
},
suites: {
sitePersonalizationSanity: '../test/e2e/Sanity/*.js',
},
// Other protractor configs
I'll be glad to hear if I'm doing anything wrong.. thanks.
Your original problem was only with the spelling.
Use:
maxInstances: 2,
Instead of:
maxInstance: 2,
This could be your work around and works fro me.
you can specify the threads
in multicapabilities just mention like this
multiCapabilities: [
{
shardTestFiles: true,
maxInstances: 1,
sequential: true,
browserName: 'chrome',
specs: ['specs/spec1.js','specs/spec2.js','specs/spec3.js']
},
{
shardTestFiles: true,
maxInstances: 1,
sequential: true,
browserName: 'chrome',
specs: ['specs/spec4.js',
'specs/spec5.js',
'specs/spec6.js',
]
}
If you want you can include the maxSessions: 1, count: 1 too .
so that you can restrict the sessions
you can group the similar processing test cases together.
Hope this helps.
Kindly up-vote or select as correct answer if it works good.

Protractor - run specific test as mobile device

I have a feature that acts differently for mobile web / desktop. My media query is running on device-width, for example:
#media only screen and (max-device-width: 1024px) {
...
}
This means that I cannot just change browser size (it will not work):
browser.manage().window().setSize(320, 480);//will not be affected by 'device-size' media query
I found an option to change chromeOptions on device capabilities. I tried using this with multiCapabilities:
'use strict';
var config = require('infra-gruntfile/protractor-conf').config;
// old capabilities
// config.capabilities = {
// browserName: 'chrome'
// };
config.multiCapabilities =
[
{
browserName: 'chrome',
name: 'Unnamed Job',
count: 1,
shardTestFiles: false,
maxInstances: 10,
chromeOptions: {
'mobileEmulation': {
'deviceName': 'Apple iPhone 4'
},
args: [
'incognito',
'disable-extensions'
]
},
loggingPrefs: {
browser: 'ALL'
},
specs: ['app/**/*.mobile.spec.js']
},
{
browserName: 'chrome',
specs: ['!app/**/*.mobile.spec.js']
}
]
module.exports.config = config;
It looks like specs doesn't work (I was trying different spec options) but all of them will run all test on both mobile/non mobile browser. I need the test mobile test to run only on mobile, while all others on regular browser.
Do I have a programatically way of doing this during my test (and not using config)?
What am I doing wrong with my current config? Why isn't specs working for me?
After reading this post I figured out that the problem is that the capability-specific specs are in addition to the main config.specs.
This means I have to remove the defaults arrived from my infrastructure config file, using specs: []
'use strict';
var config = require('infra-gruntfile/protractor-conf').config;
// old capabilities
// config.capabilities = {
// browserName: 'chrome'
// };
config.specs = []; //This line solved my problem!
config.multiCapabilities =
[
{
browserName: 'chrome',
name: 'Unnamed Job',
count: 1,
shardTestFiles: false,
maxInstances: 10,
chromeOptions: {
'mobileEmulation': {
'deviceName': 'Apple iPhone 4'
},
args: [
'incognito',
'disable-extensions'
]
},
loggingPrefs: {
browser: 'ALL'
},
specs: ['app/**/*.mobile.spec.js']
},
{
browserName: 'chrome',
specs: ['!app/**/*.mobile.spec.js']
}
]
module.exports.config = config;

Activating chrome language flags when activating from protractor (selenium)

I'm writing end to end tests with Protractor for an angular website.
We have to support certain languages so I would like to init chrome using the --lang flag and start it with some other language. I searched the web and couldn't find any example to how it can be done.
My only lead was some article I saw and understood that I need to add to Protractor config file the "capabilities" section and there I can define the "args" property.
Then tried to tinker with it but no luck.
Any help will be most welcome.
Thanks,
Alon
How to set Browser language and/or Accept-Language header
exports.config = {
capabilities: {
browserName: 'chrome',
chromeOptions: {
// How to set browser language (menus & so on)
args: [ 'lang=fr-FR' ],
// How to set Accept-Language header
prefs: {
intl: { accept_languages: "fr-FR" },
},
},
},
};
More examples:
intl: { accept_languages: "es-AR" }
intl: { accept_languages: "de-DE,de" }
As it turns out - the answer was in the docs all along.
This is how you do it for chrome and i guess it similar for other browsers:
inside the protractor.conf.js (for Spanish):
capabilities: {
browserName: 'chrome',
version: '',
platform: 'ANY',
'chromeOptions': {
'args': ['lang=es-ES']}
}

Resources