Pass commandline argument to browser with Protractor - phantomjs

I'm trying to get PhantomJS working with Protractor. I'm currently having an issue with Phantom, but not Chrome, when my code needs to reach a backend endpoint which is kept on a separate server. As such, I would like to test it with the --ignore-ssl-errors option.
Unfortunately, the example config file provided in the Protractor documentation doesn't seem to list any way to pass arguments to the browser. Is this possible?

It turns out the answer was in a closed Protractor issue: https://github.com/angular/protractor/issues/150
You CAN pass arguments to the browser with the phantomjs.cli.args property, which takes an array of arguments. Just add it to the capabilities property in your configuration, in he same location where you specify the browserName:
capabilities: {
browserName: 'phantomjs',
'phantomjs.binary.path': require('phantomjs').path,
'phantomjs.cli.args': ['--web-security=false', '--ignore-ssl-errors=true', '--webdriver-loglevel=DEBUG'],
}

Related

How can I browse the web randomly in a Chrome instance with a logged in Chrome extension?

I want to test a Chrome extension and to test it I need to have it browse the web randomly and visit random pages for a long period to see if it generates any errors. You need to be logged into the extension, which is why I am not using Selenium for this as I cannot find a way to log into the extension using Selenium.
Is there a way to make Selenium act on an existing or pre-set Chrome existence? Any other options?
You can use web-ext. You can use Firefox, google Chrome, Chromium.
You can script your browser like this.
import webExt from 'web-ext';
webExt.cmd.run({
// These are command options derived from their CLI conterpart.
// In this example, --source-dir is specified as sourceDir.
firefox: '/path/to/Firefox-executable',
sourceDir: '/path/to/your/extension/source/',
}, {
// These are non CLI related options for each function.
// You need to specify this one so that your NodeJS application
// can continue running after web-ext is finished.
shouldExitProgram: false,
})
.then((extensionRunner) => {
// The command has finished. Each command resolves its
// promise with a different value.
console.log(extensionRunner);
// You can do a few things like:
// extensionRunner.reloadAllExtensions();
// extensionRunner.exit();
});
There should be an option to define --start-url. You can make this a random url with some programming... Not able to test it now, but you should be able to make it work
Or you just run from the commandline
web-ext run --start-url www.mozilla.com

How to pass client cert and key for https tests in Protractor?

I want to run https tests using Protractor nodeJS framework. But my tests expect to pass cert and key.
I looked into Protractor, I could not find any option to pass cert and key.
You should be able to use acceptInsecureCerts field in the capabilities section of your config to get around this. The following example works for chrome and firefox. I'm not entirely sure what it is for other browsers but it will be similar to this.
capabilities: {
browserName: 'chrome',
acceptInsecureCerts : true
}

Webdriverio with chrome browser does not display correcty

I am currently trying to test an app using webdriverio and chrome. But the app does not display anything but the images and some borders (??)(see pic). I get the same behaviour also with other websites, so it is not a problem of the app under test. Everything also displays well using other browsers (e.g firefox)
how it displays in chrome browser
Update: after searching a little bit more, I think this has something to do with passing basic auth credentials in the url, because the page I am testing is password protected. I have this in the webdriverio config file:
capabilities: [{
browserName: 'chrome',
chromeOptions: {
args: ['--disable-blink-features=BlockCredentialedSubresources']
}
}]
I am also using selenium-standalone as a service, version 0.0.10, webdriverio version 4.13.1.
In my code I open the page using:
browser.url("https://user:password#mywebsite.com/kontakt/");

Protractor functional test cannot load unsafe http javascript

So I wrote a bookmarklet and want to do some functional testing, I used Protractor and I was able to inject my bookmarklet javascript file to it. However since it is hosted locally it is not HTTPS. When I run the test although the js file is injected, I got
VM122:17 Mixed Content: The page at 'https://xxxx' was loaded over HTTPS, but requested an insecure script 'http://localhost:8000/content.js'. This request has been blocked; the content must be served over HTTPS.
Since the browser is newly created every time the test runs I can't set the 'load unsafe script option' for testing.
You could start chromedriver with extra arguments in your Protractor configuration.
capabilities: {
browserName: "chrome",
chromeOptions: {
args: [
"--allow-running-insecure-content"
]
}
}
For a full list of chromedriver arguments, see:
http://www.assertselenium.com/java/list-of-chrome-driver-command-line-arguments/
https://sites.google.com/a/chromium.org/chromedriver/capabilities

Confused about protractor v1.4.0 'protractor' and 'browser' global variables

The doc of protractor v1.4.0 (http://angular.github.io/protractor/#/api-overview) tries to describe the global variables in protractor:
browser - A wrapper around an instance of WebDriver, used for navigation and page-wide information. The browser.get method loads a page. Protractor expects Angular to be present on a page, so it will throw an error if the page it is attempting to load does not contain the Angular library. (If you need to interact with a non-Angular page, you may access the wrapped webdriver instance directly with browser.driver).
protractor - The Protractor namespace which wraps the WebDriver namespace. Contains static variables and classes, such as protractor.Key which enumerates the codes for special keyboard signals.
My questions:
1) i don't actually understand these definitions and the difference between browser and protractor
2) in the definition of browser there is mentioned about browser.driver but when i look to the protractor API doc(http://angular.github.io/protractor/#/api) there is no driver property available for browser.
1) There are 3 important keywords: element, browser, and protractor.
element is how you select content on the page, browser is how you interact with the browser that you're testing (i.e. browser.get(...)), protractor is a shortcut for you to access static variables defined in the webdriver namespace.
For example:
browser.get('http://www.someUrl.com'); // tell browser to go to an url
var input = element(by.css('#someInput')); // find the input using a css selector
input.sendKeys(protractor.Key.ENTER); // Send a `webdriver` key to the element (see http://selenium.googlecode.com/git/docs/api/javascript/enum_webdriver_Key.html)
I would suggest that you go through http://angular.github.io/protractor/#/tutorial as a starting place.
2) That's because driver is a property in browser and not a function. Use browser.driver to access the raw webdriver (although as a new user, you shouldn't have to use it)