I am pretty new to these style of tools and I know that there is documentation here:
https://code.google.com/p/selenium/wiki/DesiredCapabilities#Proxy_JSON_Object
However I've tried a couple different ways to configure the user agent for chrome and it doesn't seem to work.
Can anyone provide an example of how I would configure this for protractor using a chrome webdriver?
This is what I have done:
capabilities: {
'browserName': 'chrome',
'chrome-switches' : [{'user-agent' : 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'}]
},
The reference configuration and spec configurations use Chrome by default.
Do they not work for you?
On Oct 2, 2013 7:21 AM, "sheldonhall" [email protected] wrote:
I am pretty new to these style of tools and I know that there is
documentation here:https://code.google.com/p/selenium/wiki/DesiredCapabilities#Proxy_JSON_Object
However I've tried a couple different ways to configure the user agent for
chrome and it doesn't seem to work.Can anyone provide an example of how I would configure this for protractor
using a chrome webdriver?This is what I have done:
capabilities: {
'browserName': 'chrome',
'chrome-switches' : [{'user-agent' : 'Mozilla/5.0 (Linux; U; Android
4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko)
Version/4.0 Mobile Safari/534.30'}]
},—
Reply to this email directly or view it on GitHubhttps://github.com/angular/protractor/issues/138
.
No it didn't
Could you describe _how_ it didn't work?
Sorry I should of been more specific. I meant changing the user agent in chrome to Android 4.2.2 or any mobile agent.
Try this:
capabilities: {
'browserName': 'chrome',
'chrome-switches' : ["--user-agent ='Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'"]
},
Seems that still does not work for me. I set up a quick test below. You can verify by setting your user agent to a mobile device and view techcrunch's website. This is all the test tries to simulate
My settings files :
// The main suite of Protractor tests.
exports.config = {
seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar',
chromeDriver: './selenium/chromedriver',
seleniumAddress: 'http://localhost:4444/wd/hub',
// Spec patterns are relative to this directory.
specs: [
'mobile_redirect_spec.js'
],
capabilities: {
'browserName' : 'chrome',
'chrome-switches' : ["--user-agent='Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'"]
//'chrome-switches' : '--use-mobile-user-agent'
},
//baseUrl: 'http://www.google.com',
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
}
};
//------------------------------------------------------------
//My test: mobile_redirect_spec.js
//----------------------------------------------------
var util = require('util');
describe('access techcrunch.com', function() {
describe('from a non mobile agent', function() {
it('should bring you to the non mobile page', function() {
var ptor = protractor.getInstance();
var driver = ptor.driver;
driver.get('http://www.techcrunch.com/');
ptor.sleep(2000);
expect(driver.getCurrentUrl()).toContain('m.techcrunch.com');
}, 20000);
});
});
This test fails for me. Any idea what I might be doing wrong?
I was just also trying to use 'chrome.switches' capability without any success (tried many permutations like chrome-switches etc) - any progress here? I'd like to switch locale using --lang=XX Chrome command line option.
Finally I got it working using configuration described in thread https://github.com/angular/protractor/issues/138 :
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
args: ['--lang=CS']
}
},
And it looks like the docs are already updated too: https://github.com/angular/protractor/blob/master/docs/browser-setup.md :+1:
Exaclty the example of Buthrakaur is NOT working. The language setting is completely ignored! I can set the frame counter from the docs, but the language always stays at the OS setting.
@AntonTrapp This is a year later, yet, I found this solution (http://stackoverflow.com/questions/26872481/activating-chrome-language-flags-when-activating-from-protractor-selenium)
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" },
},
I didn't need the arg variable.
Hope it helps if someone see this issue
Not sure why the discussion here changed from setting Chrome User Agent to setting the browser language - but I am still not able to set the User Agent in Protractor config.
I have tried chromeOptions: { args: ['--user-agent="test"']} and also 'chrome-switches': ['--user-agent="test"'] - neither have worked.
EDIT: the solution for me was to change chromeOptions to 'goog:chromeOptions' (be sure to add quotes around the property name since it contains a :.
The reason chromeOptions did not work is because I was trying to run my test on a remote Selenium node, and the newer versions of Selenium would not honor user-agent unless it was set using goog:chromeOptions specifically. After adding the goog: prefix, it works on local protractor using chromedriver and it works on remote selenium node.
:tada: