I am using Protractor with PhantomJS. How can I set the user agent that PhantomJS sends? Can it be different for different tests?
Set the phantomjs.page.settings.userAgent under capabilities:
capabilities: {
"browserName": "phantomjs",
"phantomjs.page.settings.userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 (KHTML, like Gecko) Chrome/15.0.87"
}
Related
I have selenium scripts to run on docker container selenium grid that were written before I join this project. due to the docker I don't have access to view the browser while running the scripts. And when scripts fail its very hard to debug. Can someone help me how to modify the below conf.js file to run my scripts locally for debugging.
Conf.js
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;
const log = require('loglevel');
const util = require('#raven/common-protractor-test-utils');
const { ExpectedConditions } = require('protractor');
require('dotenv').config({ path: '.local.env' })
var testOutputDir = './test_output/';
let peregrineUrl = util.functionalTestBaseUrl(
'https://ea-webapp-int-raven.ocp-nonprod/'
);
let domainName = util.domainName;
exports.config = {
directConnect: true, // Set to true for local testing, or provide a link to a running selenium grid.
specs: ['e2e/**/mailbox-test.js', 'e2e/**/email-dumps-test.js'],
capabilities: {
browserName: 'chrome',
acceptInsecureCerts: true,
'goog:chromeOptions': {
w3c: false,
args: [
'--no-sandbox',
// '--headless',
'--disable-gpu',
'--window-size=1200,1200',
'--allow-insecure-localhost',
'--allow-running-insecure-content',
'--ignore_ssl',
'--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
],
},
},
allScriptsTimeout: 600000,
baseUrl: peregrineUrl,
framework: 'jasmine',
jasmineNodeOpts: {
isVerbose: true,
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 600000,
stackTrace: true
},
onPrepare: async () => {
/* Set Log Level */
log.setLevel('INFO');
log.info('Base URL: ' + peregrineUrl);
log.info('Domain Name: ' + domainName);
browser.ignoreSynchronization = true;
const ec = protractor.ExpectedConditions;
/* Set up the test directory. */
util.mkdirs(testOutputDir);
console.time('Peregrine Load Time');
await browser.get(peregrineUrl);
browser.driver.sleep(3000);
await username_area.sendKeys('rv-peregrine-test-user');
await password_area.sendKeys(process.env.SELENIUM_SERVICE_PASSWORD);
await agree_button.click();
await login_button.click();
},
};
When I try to change directConnect: ture and disable --headless to run locally I am able to see the chrome browser launched but the application opened. This is the trace from my console
[21:28:19] I/launcher - Running 1 instances of WebDriver
[21:28:19] I/direct - Using ChromeDriver directly...
DevTools listening on ws://127.0.0.1:51650/devtools/browser/bf44c6c7-72a6-49e5-ab80-b13139ce9005
[15808:15796:0115/212822.298:ERROR:url_util.cc(414)] Invalid pattern javascript://
[15808:4128:0115/212826.609:ERROR:chrome_browser_main_extra_parts_metrics.cc(227)] START: ReportBluetoothAvailability(). If you don't see the END: message, this is crbug.com/1216328.
[15808:4128:0115/212826.610:ERROR:chrome_browser_main_extra_parts_metrics.cc(230)] END: ReportBluetoothAvailability()
[15808:4128:0115/212826.611:ERROR:chrome_browser_main_extra_parts_metrics.cc(235)] START: GetDefaultBrowser(). If you don't see the END: message, this is crbug.com/1216328.
[15808:15796:0115/212826.611:ERROR:device_event_log_impl.cc(214)] [21:28:26.611] USB: usb_device_handle_win.cc:1050 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[15808:15796:0115/212826.613:ERROR:device_event_log_impl.cc(214)] [21:28:26.613] USB: usb_device_handle_win.cc:1050 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[15808:4128:0115/212826.672:ERROR:chrome_browser_main_extra_parts_metrics.cc(239)] END: GetDefaultBrowser()
[15808:15796:0115/212826.687:ERROR:device_event_log_impl.cc(214)] [21:28:26.688] Bluetooth: bluetooth_adapter_winrt.cc:1206 Getting Radio failed. Chrome will be unable to change the power state by itself.
[15808:15796:0115/212826.730:ERROR:device_event_log_impl.cc(214)] [21:28:26.730] Bluetooth: bluetooth_adapter_winrt.cc:1284 OnPoweredRadioAdded(), Number of Powered Radios: 1
[15808:15796:0115/212826.732:ERROR:device_event_log_impl.cc(214)] [21:28:26.732] Bluetooth: bluetooth_adapter_winrt.cc:1299 OnPoweredRadiosEnumerated(), Number of Powered Radios: 1
Thanks in advance
We are using Protractor (5.2.2), chrome based functional testing. Please see the configuration information.
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
getPageTimeout: 1000,
allScriptsTimeout: 3000,
framework: 'custom',
verbose:'true',
frameworkPath: require.resolve('../../node_modules/protractor-cucumber-framework'),
ignoreUncaughtExceptions: true,
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['--disable-web-security'],
'mobileEmulation': {
'deviceName': 'Nexus 6'
}
}
}
Our test scripts where working from past 4 months without any issue, suddenly from Dec 17th all the element.all(by.css('')).click() stopped working. When it tries to execute this method after some time I could see browser right-click menu instead of element click.
Please help me in resolving this issue.
I did a work around by pointing the chromeOptions to user-agent instead of mobileEmulation, the test script worked fine.
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A405 Safari/600.1.4']
}
},
and set the browser size - browser.manage().window().setSize(375, 667);
I am trying to use a custom HTTP UserAgent Header string to bypass a captcha code on our website. It works correctly manually, and I am trying to make it work with my automation tests. I write them in PHP using the Codeception framework. As you can see below, I have tried adding variables to my config yml for browserstack-sierra-safari. "headers" "User-Agent". I've tried adding this code to win7-chrome, as well as up in the env. I have also tried the variable browserstack.useragent and browserstack.user-agent. My config file is below.
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- Helper\Acceptance
- Helper\CaptchaSolver
- Asserts
config:
WebDriver:
url: '**********************'
browser: chrome
env:
prod:
modules:
config:
WebDriver:
url: '**********************'
test:
modules:
config:
WebDriver:
url: '************************'
dev:
modules:
config:
WebDriver:
url: '********************'
browserstack-win7-chrome:
modules:
config:
WebDriver:
host: '**************************'
port: 80
browser: chrome
capabilities:
browserstack.user: 'a******'
browserstack.key: '******************'
browserstack.console: 'verbose'
browserstack.idleTimeout: 300
acceptSslCerts: true
os: Windows
os_version: 7
browserstack.local: true
browserstack.debug: true
browserstack-sierra-safari:
modules:
config:
WebDriver:
host: '******************#hub.browserstack.com'
port: 80
browser: edge
capabilities:
os: Windows
os_version: 7
browserstack.local: true
browserstack.debug: true
browserstack.acceptSslCerts: true
headers:
Accept:'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
Accept-Language: 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3'
User-Agent: 'Mozilla/5.0 (Windows NT 10.0; WOW64)'
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36'
browserstack-win10-edge:
modules:
config:
WebDriver:
host: '****************#hub.browserstack.com'
port: 80
browser: Edge
capabilities:
os: Windows
os_version: 10
browserstack.local: true
browserstack.debug: true
Has anyone successfully sent an HTTP header through browserstack in an automation test? If so, what variable was used?
Ideally, I would recommend you override the useragent while instantiating the browser.
For eg, if you are using chrome and tests are implemented in java, below code should help:
ChromeOptions options = new ChromeOptions();
options.addArguments("--user-agent=Mozilla/5.0 (Linux; Android 6.0; HTC One M9 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36");
driver = new ChromeDriver(options);
on similar lines, while implementing it on browserstack, you may use the below lines of code for your webdriver call
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("--user-agent=Mozilla/5.0 (Linux; Android 6.0; HTC One M9 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new RemoteWebDriver(new URL(“https://" + <BROWSERSTACK_USERNAME> + ":" + <BROWSERSTACK_KEY> + "#hub-cloud.browserstack.com/wd/hub”), capabilities);
Not sure if Browserstack has any capability called browserstack.useragent or browserstack.user-agent
I'm trying to make Phantom JS load a page, but no matter what, it responds with an "operation canceled :( I've tried various versions settings that ignore ssl and various websites. But neither works.
I can reach all sites with a normal browser and run PhantomJS locally from a fully updated mac osx
./phantomjs --ignore-ssl-errors=true --ignore-ssl-errors=yes --ssl-protocol=tlsv1 ../../index.js http://askbar.dk
yelds
= onNavigationRequested
destination_url: http://askbar.dk/
type (cause): Other
will navigate: true
from page's main frame: true
= onResourceRequested()
request: {
"headers": [
{
"name": "Accept",
"value": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
},
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36"
}
],
"id": 1,
"method": "GET",
"time": "2016-04-11T20:05:39.998Z",
"url": "http://askbar.dk/"
}
= onNavigationRequested
destination_url: about:blank
type (cause): Other
will navigate: true
from page's main frame: true
http://askbar.dk/: Operation canceled
phantomjs://code/index.js:60 in onResourceError
= onResourceReceived()
id: 1, stage: "end", response: {"contentType":null,"headers":[],"id":1,"redirectURL":null,"stage":"end","status":null,"statusText":null,"time":"2016-04-11T20:05:39.999Z","url":"http://askbar.dk/"}
Any ideas ?
I want to be able to set UserAgent when running Selenium mobile tests on Safari but I can't figure out how I do that. When I run the same tests on Chrome I can define the UserAgent in my desiredCapabilities like this:
var options = {
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: [
'use-mobile-user-agent',
'user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OSX) ...'
]
}
}
}
Guess there must be a similar way to do it when running it on Safari. I'm using webdriverio to setup my Selenium project but don't think that should matter.
Thanks.
This is not supported by SafariDriver unfortunately. Hope we will see this in the future.