PHP - Chrome Webdriver - Browserstack \\ What is the correct variable to provide in my yml to set a Custom HTTP Browser Heading? - codeception

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

Related

Drag and Drop codeception

I'm running a test with codeception to do a Drag & Drop. Running the test returns no error BUT the Drag & Drop does not actually work (I don't see what I want).
I have to move one window to another
This is my test:
$I->click(['id' => 'showGallery']);
$I->amOnUrl("http://xxxxxx");
$I->dragAndDrop("//div[#class='grid-stack-item-content']","//div[#id='dashboard']");
$I->wait ('15');
$I->see ("Codice prodotto:");
This is my acceptance.suite.yml:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://xxxx
host: xxxx
port: xxxx
window_size: false
browser: chrome
capabilities:
unexpectedAlertBehaviour: 'ignore'
chromeOptions:
args: ["--disable-gpu", "window-size=1920x1080", "--no-sandbox"]
- \Helper\Acceptance

Codeception, how override url from command line for a specific (or not specific) suite test?

I'm looking for a way to override the base url of my tests from the command line. In the future, I'll tests a lot of websites, so it's very unwieldy if I must add each website in a new environment in the acceptance.suite.yml file.
Currently, my acceptance.suite.yml is:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://foo.com
browser: chrome
I see I can use the option 'override' with the run command, but even if I read the codeception document and navigate through help website (like stack overflox..), I can't find a good way for override. Can someone help me?
When I prints all config (via ./vendor/bin/concept), I get:
Array
(
actor => AcceptanceTester
modules => Array
(
enabled => Array
(
0 => Array
(
WebDriver => Array
(
url => http://foo.foo
browser => chrome
)
)
1 => \Helper\Acceptance
)
config => Array
(
)
depends => Array
(
)
)
I tried : ./vendor/bin/codecept run acceptance --steps -o 'modules: enabled: 0: WebDriver: url: http://faa.faa, but the test run ever on http://foo.foo
In this codeception issue post, it seems it's impossible to override a config value when we run a specific suite (my english is not very good , so maybe I misunderstood). So I add an env in my acceptance.suite.yml file :
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://foo.foo
browser: chrome
env:
generic:
modules:
config:
WebDriver:
url: http://faa.faa
And I tried theses commands :
./vendor/bin/codecept run acceptance --env generic --steps -o 'env: generic: modules: config: WebDriver: url: http://faa.faa
And
./vendor/bin/codecept run acceptance --env generic --steps -o 'WebDriver: url: http://faa.faa
And nothing happened. My test are always on http://foo.foo
EDIT AFTER "LEGION" HELP
When I use this acceptance.suite.yml :
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: ''
browser: ''
env:
chrome:
modules:
config:
WebDriver: {}
I get an error :
So when I use this acceptance.suite.yml :
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: ''
browser: chrome
env:
chrome:
modules:
config:
WebDriver: {}
I get an another error :
And if I use this acceptance.suite.yml :
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: ''
browser: chrome
env:
chrome:
modules:
config:
WebDriver:
url: 'http://foo.foo'
browser: 'chrome'
No error ! buuuUUUT ! I'm not on the good url x)
The url I get is "data:", its strange...
For get the url, I add this simple line in my test file :
$this->comment("I am on the url : " . $this->executeJS("return window.location.href") . "\n");
N.B: You need Codeception 1.8 or above! Before that version is bugged.
If the version is > 1.8 it should works... you may try editing your acceptance file like below and see if something is changed:
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: 'http://foo.foo/'
browser: 'firefox'
env:
chrome: #or watherver you want
modules:
config:
WebDriver:
url: 'http://fuu.fuu/'
browser: 'chrome'
run it like below:
php vendor/bin/codecept run acceptance --env chrome
** EDIT **
To pass the url from commandline you need empty WebDriver Configuration:
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver: {}
env:
chrome: #or watherver you want
modules:
config:
WebDriver:
url:'http://foo.foo'
browser:'firefox'
commandline:
./vendor/bin/codecept run acceptance --env chrome --steps -o 'WebDriver: url: \'http://faa.faa\' browser: \'chrome\''
(I usually use apex for url and browser... but not sure are really neded).

Protractor (5.2.2) - element.all(by.css('')).click() stopped working suddenly from Dec 17th

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);

Set user agent in PhantomJS and Protractor

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"
}

Set UserAgent when running Selenium mobile tests with SafariDriver

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.