I am using Protractor to do testing. Can anyone tell me if there is a way for me to change it from using Chrome to doing headless testing. I saw a number of articles about these seem to assume I am using a Linux OS. I am using a Windows machine to do my testing.
ChromeOptions options = new ChromeOptions() options. addArgument("headless"); ChromeDriver driver = new ChromeDriver(options); In the above code, the browser is instructed to run in the headless mode using the addArgument() method of the ChromeOptions class provided by the Selenium WebDriver.
What is Headless testing? Headless testing is simply running your Selenium tests using a headless browser. It operates as your typical browser would, but without a user interface, making it excellent for automated testing.
Selenium Moreover, you can use either Headless Chrome or Headless Firefox to execute the headless browser Selenium. Using Chrome for Selenium: With Chrome, you need Selenium WebDriver, which will provide you with a class called “ChromeOptions”. This class can provide headless configurations to your Chrome.
Headless testing is when you run a UI-based browser test without showing the browser UI. It's running a test or running a script against a browser, but without the browser, UI starts up.
Yes phantomjs works with protractor in Windows. I too have found nearly all online documentation to be *nix specific but getting it working in Windows is very easy. Assuming you already have protractor running with chrome:
Add phantomjs. You can either install the Windows version or install the node module. I suggest the node module because it will simplify build setup if another development environment needs to be set up:
npm install phantomjs --save-dev
Then update your protractor.conf.js to point to phantomjs:
capabilities: {
browserName: 'phantomjs',
'phantomjs.binary.path': require('phantomjs').path
},
Note the value of phantomjs.binary.path. All online documentation to date hard codes the value of that path to *nix appropriate values. Using those hardcoded paths in Windows won't resolve to the correct binary. Since we rely on the path property, this configuration will work in both Windows and *nix!
Protractor could be used with PhantomJS "a headless WebKit". The following section is an extract of the protractor documentation :
In order to test locally with PhantomJS, you'll need to either have it installed globally, or relative to your project. For global install see the PhantomJS download page. For relative install run: npm install --save-dev phantomjs
.
Add phantomjs to the driver capabilities, and include a path to the binary if using local installation:
capabilities: {
'browserName': 'phantomjs',
/*
* Can be used to specify the phantomjs binary path.
* This can generally be ommitted if you installed phantomjs globally.
*/
'phantomjs.binary.path':'./node_modules/phantomjs/bin/phantomjs',
/*
* Command line arugments to pass to phantomjs.
* Can be ommitted if no arguments need to be passed.
* Acceptable cli arugments: https://github.com/ariya/phantomjs/wiki/API- Reference#wiki-command-line-options
*/
'phantomjs.cli.args':['--logfile=PATH', '--loglevel=DEBUG']
}
A basic workflow could be to run the tests on phantomjs on the developper machine. It allows to run your e2e without an annoying browser window. The tests on the others browsers could be run on the continuous integration server. When you develop you run the test with phantom js until the pass. Then you push, a build is triggered on the ci server and run the tests against the different browsers. If one of the test fails on a specific browser, you could run it on your dev machine. For exemple with chrome :
protractor --browser=chrome
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With