how to use chrome options in protractor framework? - selenium

I want to use this code in protractor framework
setPageLoadStrategy(org.openqa.selenium.PageLoadStrategy.NONE);
setExperimentalOption("debuggerAddress", "127.0.0.1:12633");
Please help me in that.
like
capabilities: {
'browserName': 'chrome',
"chromeOptions": {
setExperimentalOption:'debuggerAddress=127.0.0.1:12633'
}
},
how can we do like that ??

You can try like this. If you want the list of all configurations for protractor check here on official docs.
capabilities: {
browserName: 'chrome',
pageLoadStrategy :'normal',
chromeOptions: {
args: [ "--headless",
"--disable-gpu",
"--window-size=800,600",
"--debuggerAddress=127.0.0.1:12633" ]
}
}
You can try like this. But I found that this capability does not present in chrome browser
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['todo-spec.js'],
capabilities: {
'browserName': 'firefox',
'moz:firefoxOptions': {
'binary': '/opt/bin/firefox',
'args': ['--verbose'],
'pageLoadStrategy' :'normal'
}
}
};

Related

Protractor tests with Muliple browsers got failed at startup

I am trying to run e2e tests for chrome and firefox and I am unable to load the chrome browser with following configuration ,any comment is much appreciated , thanks
var HtmlReporter = require('protractor-beautiful-reporter');
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [ **some spec**
],
multiCapabilities: [{
"browserName": "firefox"
},
{
"browserName": "chrome",
}
],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 180000
},
allScriptsTimeout: 200000,
onPrepare: function () {
browser.manage().timeouts().implicitlyWait(20000);
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: 'test-result',
preserveDirectory: false,
takeScreenShotsOnlyForFailedSpecs: true,
screenshotsSubfolder: 'images'
}).getJasmine2Reporter());
}
};
try directConnect: true instead of using seleniumAddress: http://localhost:4444/wd/hub
or make sure your grid server is up and running and also selenium server is up and running
command to start selenium server webdriver-manager start

WebdriverIO: Not able to access browser capabilities when using multiRemote

I have setup up my wdio.conf.js to use multiple browsers in my tests as described on the WebdriverIO website. (the capabilities are defined as an object, if using multiremote feature)
In my spec file, when I try to perform an action, such as MyFirefoxBrowser.url('https://myUrl') ... (what is happening?)
!Note: When I refer to the browser object directly, both Chrome and Firefox instances are spawned, as expected.
I have tried referring the wdio.conf.js file inside my spec file using require, but it didn't work.
Spec file (.js):
describe('webdriver.io page', () => {
it('should have the right title', () => {
myFirefoxBrowser.url('https://webdriver.io');
const title = myFirefoxBrowser.getTitle()
assert.strictEqual(title, 'WebdriverIO ยท Next-gen WebDriver test framework for Node.js')
});
});
Capabilities (as defined in the wdio.conf.js):
capabilities: {
myChromeBrowser: {
capabilities: {
browserName1: 'chrome'
}
},
myFirefoxBrowser: {
capabilities: {
browserName: 'firefox'
}
}
},
Error:
ReferenceError: mychromeBrowser is not defined
Expected Results: Only the Firefox browser should navigate to the requested url.
myChromeBrowser != mychromeBrowser. Check this. Also not sure what do you want to do with this. browser is object for every browser and if you want to decide on type of it, you can via browser.capabilities
and you will get object
{ acceptInsecureCerts: false,
browserName: 'chrome',
browserVersion: '78.0.3904.97',
chrome:
{ chromedriverVersion:
'78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-heads/3904#{#800})',
userDataDir: '/tmp/.com.google.Chrome.Ihm6cA' },
'goog:chromeOptions': { debuggerAddress: 'localhost:45423' },
networkConnectionEnabled: false,
pageLoadStrategy: 'normal',
platformName: 'linux',
proxy: {},
setWindowRect: true,
strictFileInteractability: false,
timeouts: { implicit: 0, pageLoad: 300000, script: 30000 },
unhandledPromptBehavior: 'dismiss and notify' }
You should use browser.
capabilities should be defined as an array
// wdio.conf.js
exports.config = {
// ...
capabilities: [{
browserName: 'firefox'
}, {
browserName: 'chrome',
// ...
proxy: {
proxyType: "manual",
httpProxy: "corporate.proxy:8080",
socksUsername: "codeceptjs",
socksPassword: "secret",
noProxy: "127.0.0.1,localhost"
},
// ...
}],
// ...
}
Late to the party, I think you have a typo. It should be browserName in capabilities.myChromeBrowser and not browserName1. Otherwise the code should do as you want.
capabilities:
{
myChromeBrowser: {
capabilities: {
browserName: 'chrome'
}
},
myFirefoxBrowser: {
capabilities: {
browserName: 'firefox'
}
}
},

Protractor 5.3.0 incompatible with firefox52 and IE11

The versions of the relevant modules:
Selenium-Webdriver: 3.6.0
Protractor: 5.3.0
Firefox: 52.7.2 (32-bit)
IE11
My protractor scripts work smoothly with chrome 65.0.3325.181 (Official Build) (64-bit).
The protractor.conf.js:
exports.config = {
directConnect: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'jasmine',
// Spec patterns are relative to the current working directory when
// protractor is called.
suites: {
spec: ['spec/full/example_spec.js']
},
multiCapabilities: [
// {
// browserName: 'chrome',
// chromeOptions: {
// args: ['disable-infobars']
// }
// },
{
'browserName': 'internet explorer',
},
// { browserName: 'firefox' }
],
maxSessions: 1,
}
Is it a bug of the protractor 5.3.0?

Run Firefox in headless mode using Protractor config

I have this in my Protractor config:
multiCapabilities: [
{
browserName: 'firefox',
firefoxOptions: {
args: ['-headless']
},
'moz:firefoxOptions': {
args: ['-headless']
}
}
]
unfortunately, when I launch Protractor, Firefox still runs in a headful mode. How to the heck do I tell Firefox to as headless?
I know that at the command line, the -headless option should work so.
I guess, you are missing extra hypen (-) in your config.
multiCapabilities: [
{
browserName: 'firefox',
firefoxOptions: {
args: ['--headless']
},
'moz:firefoxOptions': {
args: [ '--headless' ]
}
}
]
Also your browser version should be greater than 56.

How to disable custom protocol handler for protractor?

I have a Protractor test suite for an application that uses a custom protocol handler to pass messages out of an iOS web view.
When testing it with protractor, how do I prevent the custom window.location = "app://doThing"; message from breaking my tests? It shows the "Open xdg-open?" popup and doesn't continue with tests.
My protractor configuration looks like this:
exports.config = {
...,
multiCapabilities: [ {
browserName: 'chrome',
chromeOptions: {
args: [ '--lang=en', '--window-size=1024x768' ]
},
specs: 'test-*.js',
} ]
};
I achieved this in Chrome 60 by setting the preferences inside the chromeOptions block.
exports.config = {
...,
multiCapabilities: [ {
browserName: 'chrome',
chromeOptions: {
args: [ '--lang=en', '--window-size=1024x768' ],
// Replace "app" with your app's custom scheme.
prefs: {
protocol_handler: {
excluded_schemes: {
"app": true
}
}
},
},
specs: 'test-*.js',
} ]
};
Before Chrome 60, I enforced a profile folder for the Chrome runner. You can do that by having a folder named "/chrome-profile" in the Chrome docker container for example, and adding one file in it named "Default State" with the following content:
{
"protocol_handler": {
"excluded_schemes": {
"app": true
}
}
}
And after that, setting the Chrome user-data-dir flags as such:
exports.config = {
...,
multiCapabilities: [{
'browserName': 'chrome',
'chromeOptions' : {
args: ['--lang=en',
'--window-size=1024,768',
'--user-data-dir=/chrome-profile/']
},
specs: ['test-*.js']
}]
};