4
votes

I am using protractor and it works when I specify chrome as the browsertype. I am looking for a headless browser sample code, I have looked for phantomJs but I could not run any of them. Is there a working sample available of another headless browser?

2
What runner are you using?gwin003
Sorry, I don't know anything about selenium. If you were using Karma I would be able to help.gwin003

2 Answers

5
votes

No other headless browser out there besides PhantomJS while the latter is a dead-end with Protractor.

You can try docker-selenium or, if you don't like Docker you can do it yourself with ubuntu-headless sample. Both solutions provide Chrome & Firefox by using Xvfb even though there is no real DISPLAY.

UPDATE 2 Seems to be possible to run Xvfb in OSX: http://xquartz.macosforge.org/landing/

UPDATE 1 Mac OSX selenium headless solution:

Enable multi-user remote desktop access to OSX machine

So can test selenium headless on mac. Not headless really but as another user so it doesn't interfere with your current user display. To do this you need kickstart: http://support.apple.com/en-us/HT201710 Begin using the kickstart utility

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -restart -agent

Activate Remote Desktop Sharing, enable access privileges for all users and restart ARD Agent:

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -restart -agent -privs -all 

Allow access for all users and give all users full access

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -allowAccessFor -allUsers -privs -all

Kickstart help command

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -help
1
votes

PhantomJS is a dead-end with Protractor on certain websites when there is a div, which is fixed and always visible (due to https://github.com/ariya/phantomjs/issues/11637). Otherwise you can make it work:

using phantomjs:~1.9.0 and protractor: ~1.8.0

inside protractor config file register function:

 onPrepare : function() {

    var minWindowWidth = 1024,
    minWindowHeight = 768,
    browserName,
    platform,
    window = browser.manage().window();

    browser.getCapabilities().then(function (capabilities) {
        browserName = capabilities.caps_.browserName;
        platform = capabilities.caps_.platform;
    }).then(function getCurrentWindowSize() {
        return window.getSize();
    }).then(function setWindowSize(dimensions) {
        var windowWidth = Math.max(dimensions.width, minWindowWidth),
            windowHeight = Math.max(dimensions.height, minWindowHeight);

        return window.setSize(windowWidth, windowHeight);
    }).then(function getUpdatedWindowSize() {
        return window.getSize();
    }).then(function showWindowSize(dimensions) {
        console.log('Browser:', browserName, 'on', platform, 'at', dimensions.width + 'x' + dimensions.height);
        console.log("Running e2e tests...");
    });     

},