What is a good headless browser to run with protractor? - javascript

New User here.
After hours of building my smoke and regression tests, I found out after reading many cases online that phantomjs is known to be a trouble to run with protractor. Jenkins has been running phantomjs for all the tasks it has been given so far.
They need these tests to run as part of ci which does not have a windowing system installed.
So I would appreciate it if there is a recommendation for completely headless browser or a headless chrome(that would be most beneficial) and a step by step to set it up. I already have a conf.js and a e2e.conf.js file. My code works perfectly fine with chrome.
I am on a iMac and selenium webdriver, I believe.
Edit: Problem = protractor doesn't work with phantomjs.
What I have done = use different web elements and googled if anyone has faced a similar situation. Also googled for headless browsers that worked for protractor, unable to find a suitable solution.

If anyone reached here - the answers are outdated.
Chromium (on next release) now supports headless mode. no need to work hard.
You can read more here:
https://developers.google.com/web/updates/2017/04/headless-chrome
Here is an example from command line
chrome \
--headless \ # Runs Chrome in headless mode.
--disable-gpu \ # Temporarily needed for now.
--remote-debugging-port=9222 \
https://www.chromestatus.com # URL to open. Defaults to about:blank.
And you can simply trigger protractor with capabilities for chrome:
Activating chrome language flags when activating from protractor (selenium)
Here is the configuraiton I am using
capabilities: {
'browserName': browserName,
chromeOptions: {
binary: '/Users/guymograbi/Downloads/chrome-mac/Chromium.app/Contents/MacOS/Chromium',
args: ['--headless','--disable-gpu']
}
},
Update - new versions of chrome doesn't require binary property
In my environments I found I can remove the binary property as new version of chrome is available on stable branches
My protractor configuration is
capabilities: {
'browserName': 'chrome',
chromeOptions: {
args: [ '--headless', '--disable-gpu', '--no-sandbox', '--window-size=1920x1200' ]
},
},
And it works smoothly for weeks now. highly recommended.
Update - how to do this in karma is super easy
Using headless chrome in karma is super easy:
browsers: 'ChromeHeadless'
it should work with the chrome loader and everything. more info

Your best bet is to continue with Chrome. With a bit of work you can get it to work via a CI and in a headless manner - we do this using Jenkins and Docker Ubuntu servers which are headless.
You will need to configure Chrome to run headless using XVFB. You can start off by following the gist here https://gist.github.com/addyosmani/5336747
You state you are on a Mac so you can either run the headless tests via Docker on your machine or you could set up a second config for the CI tests.
Another resource http://tobyho.com/2015/01/09/headless-browser-testing-xvfb/

I would continue testing in normal browsers with a head, but would use a remote selenium server as a service - Sauce Labs or BrowserStack, see:
Integration Testing with Protractor, WebdriverJS and Sauce Labs
Running Protractor tests on Browserstack Automate
automate-node-samples

You could run your Protractor tests against CodeShip or Drone.io, both of which offer Chrome and/or Firefox running headless for free. No really...

If you've got Chrome 59+ installed, start Chrome with the following flag:
--headless
please let me know if you need more help, will write the config for you :) enjoy

Related

can we run Cypress tests in Safari browser and Mobile testing with integration of Saucelabs?

my testscripts need to executed in mobile devices and safari browser . with the cypress and sauce labs integration can we achieve mobile testing and safari browser using cypress ?.
currently my test scripts in protractor and running all browsers like safari and mobile devices with integration of sauce labs.(Currently we are running scripts with Protractor+Saucelabs+Jenkins)
As Protractor deprecated by end of 2022, we want to migrate existing code from protractor to cypress . Can some please confirm can we achieve safari browser,mobile testing.future we want to run(Cypress+Saucelabs+Jenkins).
Please suggest.
Cypress doesn’t support Safari at the moment, so the answer is no
Since Cypress v10.8, it is possible to run tests in WebKit (the browser engine used in Safari). Currently, the support for WebKit is experimental and can be enabled by following 2 steps:
set experimentalWebKitSupport to true in the Cypress config
install the playwright-webkit npm package
You can find more details in the official Cypress release: https://www.cypress.io/blog/2022/09/13/cypress-10-8-experimental-run-tests-in-webkit/

Cannot Run Nightwatch Tests in Safari

I have followed all instructions in the Nightwatch docs and followed many issues in github. I believe I have the correct setup in my nightwatch.json for safari. Safari does launch when I run a test against it but then all the commands in my test fail. For example I have a global beforeEach to resize the browser window which works great in Firefox and Chrome but fails in Safari with
The command 'POST /session/FA198F5F-EE09-4129-9FF0-F55FEA0EE6F0/window/current/size' was not found.
If I remove that then the first step in my test (which is a waitForElementVisible test fails with the error of
The command 'GET /session/FA198F5F-EE09-4129-9FF0-F55FEA0EE6F0/element/node-F5A12DD5-2557-4AE6-806A-0A0B99B63EFC/displayed' was not found.
Again, I'm certain my config is setup properly as nightwatch is launching the safari browser but then failing on the test commands. I have enabled safaridriver and checked 'Allow Remote Automation' but everything still fails. Has anyone run into this issue?
If you used Appium and the XCUITest driver as your WebDriverAgent then you can use browser.execute('mobile:gesture',{arguments}) to replace all the 'Element Interaction' commands. The full list of gestures can be found here
For the command like waitForElementVisible(), you can use the assertions commands instead (in my case I have used assert.visible('element css selector')).
Hope they will change things in NightWatch v2 but for now we can only work around that

Docker/Selenium/Headless Chrome: Configure SUID sandbox correctly

I want to run selenium and headless chrome in my docker container for testing purpose.
I have tried to run selenium in headless chrome (outside my docker container) with the following in my .js file. This worked:
const client = webdriverio.remote({
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--headless', '--disable-gpu']
},
binary: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
},
baseUrl: CONFIG.host,
logLevel: 'verbose',
waitForTimeout: 3000
})
But I can't get this to work in my docker container. In my docker container I use "FROM selenium/standalone-chrome". There does not seem to be any problem with my dockerfile. The problem occurs when I try to run my selenium tests. I changed the binary_path in my .js file to /opt/google/chrome/google-chrome. But the tests fails and client can not even be initiated.
So I tried to just run /opt/google/chrome/google-chrome in order to see if chrome works, but then I get this error:
[0711/005304.226472:ERROR:nacl_helper_linux.cc(311)] NaCl helper
process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly
I am pretty new to this (and stack overflow) so there might be some basic things I have missed.
Try to include --no-sandbox
chromeOptions: {
args: ['--headless', '--disable-gpu', '--no-sandbox']
},
As I'm doing at docker-selenium
This error message...
[1003/144118.702053:ERROR:nacl_helper_linux.cc(310)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly
...implies that you have no setuid sandbox in your system, hence the program was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Solution
The easiest (not so clean) solution is, if you want to run Chrome and only use the namespace sandbox, you can set the flag:
--disable-setuid-sandbox
This flag will disable the setuid sandbox (Linux only). But if you do so on a host without appropriate kernel support for the namespace sandbox, Chrome will not spin up. As an alternative you can also use the flag:
--no-sandbox
This flag will disable the sandbox for all process types that are normally sandboxed.
Example:
chromeOptions: {
args: ['--disable-setuid-sandbox', '--no-sandbox']
},
You can find a detailed discussion in Security Considerations - ChromeDriver - Webdriver for Chrome
Deep dive
As per the documentation in Linux SUID Sandbox Development google-chrome needs a SUID helper binary to turn on the sandbox on Linux. In majority of the cases you can install the proper sandbox for you using the command:
build/update-linux-sandbox.sh
This program will install the proper sandbox for you in /usr/local/sbin and tell you to update your .bashrc if required.
However, there can be some exceptions as an example, if your setuid binary is out of date, you will get messages such as:
NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly
Or
Running without the SUID sandbox!
In these cases, you need to:
Build chrome_sandbox whenever you build chrome (ninja -C xxx chrome chrome_sandbox instead of ninja -C xxx chrome)
After building, execute update-linux-sandbox.sh.
# needed if you build on NFS!
sudo cp out/Debug/chrome_sandbox /usr/local/sbin/chrome-devel-sandbox
sudo chown root:root /usr/local/sbin/chrome-devel-sandbox
sudo chmod 4755 /usr/local/sbin/chrome-devel-sandbox
Finally, you have to include the following line in your ~/.bashrc (or .zshenv):
export CHROME_DEVEL_SANDBOX=/usr/local/sbin/chrome-devel-sandbox

Running Protractor against a nightly Firefox build

When I try to run Protractor tests against a "Nightly" Firefox build, firefox window hangs indefinitely:
Here is the relevant part of my configuration:
exports.config = {
baseUrl: 'http://localhost:8080/dev/src/',
specs: ['dev/test/e2e/**/dashboard.spec.js'],
directConnect: true,
capabilities: {
browserName: "firefox",
firefox_binary: "/Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin",
},
allScriptsTimeout: 110000,
getPageTimeout: 100000,
framework: 'jasmine2',
jasmineNodeOpts: {
isVerbose: false,
showColors: true,
includeStackTrace: false,
defaultTimeoutInterval: 400000
},
};
There was a related issue with no solution provided.
One of the possible workarounds I've found might be to move the WebDriver xpi extension from the stable firefox installation (or a different source) to the "extensions" directory of the Nightly firefox profile, but I'm not sure how to do it.
I've also found something about using "Marionette" driver to test a nightly Firefox build, but I haven't found any guidelines on it's relationship to Protractor.
Using:
currently latest Protractor 3.0.0
Firefox Nightly is 46.0.a1
Mac OS X El Capitan
Tried with directConnect and without - same behavior.
On both Mac and Linux I had to update to FF 47.0.1 selenium 2.53.1.
I initially explored trying to configure Protractor with the new Mozilla Marionette driver, per the answer by jrharshath
I got protractor to use it (description of what I did below). However, I had manifold problems with the driver running my tests.
I then found discussions saying 47.0.1 and selenium 2.53.1 restored FirefoxDriver functionality, so abandoned the Marionette driver in favor of compatible upgrades.
For those looking at configuring and using the Marionette driver with Protractor and webdriver I did the following:
Downloaded and unzipped the latest Marionette driver from https://github.com/mozilla/geckodriver/releases
Renamed it to wires and put it on the path
Started a standalone selenium webdriver 2.53.1 with the -Dwebdriver.gecko.driver=${path_to_driver} property, and used that server.
Set marionette true in my firefox capabilities in my config, ie :
multiCapabilities:[
{
'browserName': 'chrome'
}
},
{
'browserName': 'firefox',
'marionette' : true
}
],
Apparently this is an issue with Firefox 46. The default FirefoxDriver no longer works with this version - you need to be using the Marionette driver. I also found a quick how-to on using the new driver with Selenium.
I'm facing the same problem as well. We run our tests with directConnect by default, so I'm yet to figure out how to get protractor to use Marionette instead of FirefoxDriver.
If you're having protractor connect to Selenium, then you should be able to follow the guides available to make Selenium use the new driver - that shouldn't affect protractor's relationship with Selenium.
Update: Looking into the problem of using the latest versions of Firefox with directConnect, I found no way of instructing protractor to use the Marionette driver. I've opened an issue with the protractor team for this.

Running Automation test in PhantomJS through Webdriver-IO

I have been trying to run my tests on phantomjs, directly through mocha, or wdio or gulp, But every time tests dies out with error of timeout. Though tests run perfectly on chrome and firefox, its just in phantomjs I get an error. I have installed phantom js globally and and in my project, but I am unable to get it work since last 2 days.
that's how I have done it the test
before( function (done) {
driver = webdriverio.remote({ desiredCapabilities: {
browserName: 'phantomjs'
} });
driver.init(done);
});
Link to my project : https://github.com/anarwal/asg...
NOTE: I run tests on windows, that is where the problem is, they work fine on MAC
When you use a headless browser you need a selenium server running.
There is an very well explained example using javascript Here.
You may find Chimp.js useful as it easily allows you to use Chrome or FF locally but PhantomJS on the server. See: http://chimpjs.com/
Chimp.js works by "seamlessly integrating CucumberJS / Mocha, Selenium, WebdriverIO and Chai / Jasmine Expect to work in unison. It's designed to take away all the pain that comes with setting up these tools to play nicely together..." - Read more at: https://chimp.readme.io/docs

Categories