2

Here's my conf file:

exports.config = { 
   seleniumServerJar: './selenium-server-standalone-2.43.1.jar', 
  "capabilities": { 
    "browserName": "phantomjs"   
 }, 
 specs: [ 
        "test.js" 
    ], 
    jasmineNodeOpts: { 
        isVerbose: false, 
        showColors: true, 
        includeStackTrace: true 
    }, 
};

here's the called test.js .It is against ng-europe community site so everybody who wish will be able to run this.I choose it to learn protractor as it is written in angular:

describe('test ng-europe', function() { 

        beforeEach(function() { 
                browser.get('http://ngeurope.org'); 
        }); 

         it('should have a title', function() { 
                expect(browser.getTitle()).toContain('ng-europe'); 
                element.all(by.repeater('avatar in talk.avatars')).count().then(function(count) { 
                        console.log(count); 
                }); 
        }); 

        it('search something', function() { 
                var search_=element(by.model('speakerq')); 
                var speakers_=element.all(by.repeater('speaker in config.speakers').column('name')); 
                var speakers = $$('div.speaker.col-xs-12.col-sm-4.text-center.ng-scope img.img-responsive.img-thumbnail.img-circle.avatar');
                search_.sendKeys('igor'); 
                expect(speakers.count()).toBe(1); 
                console.log("speakers count" + speakers.count()); 
        }); 

        it('search something else', function() { 
                var search_=element(by.model('talksq')); 
                var talkers = $$('ul.list-unstyled li.ng-scope.ng-binding span.speakers-names.ng-binding'); 
                search_.sendKeys('with'); 
                expect(talkers.count()).toBe(8); 
                console.log("talkers count" + talkers.count()); 
        }); 

        it('click on jobs', function() { 
                var jobs_button=element(by.linkText('Jobs')); 
                jobs_button.click(); 
                var sponsors=$$('div.col-md-4 img.sponsor-logo.gold-sponsor') 
                expect(sponsors.count()).toBe(4);        
        }); 
});

And here's how I call this:

>protractor conf.js

selenium driver is in the same directory node,%appdata%\npm is in the path, phantomjs is installed and updated.Everything runs fine if I set the driver to chrome or firefox but with phantomjs the script just hangs forever and nothing happens.No error displayed , nothing.Just this:

Starting selenium standalone server... 
[launcher] Running 1 instances of WebDriver 
Selenium standalone server started at http://XX.XX.XXX.XX:60324/wd/hub

What I am missing?

npocmaka
  • 55,367
  • 18
  • 148
  • 187

1 Answers1

1

I've managed to, at least, make it run the tests using:

  • phantomjs 1.9.7
  • protractor 2.0.0

But, now it throws the following error message right after successfully passed first it() block:

Error: Failed: Error communicating with the remote browser. It may have died.

Here is the config I've used (several phantomjs helper "tricks" applied):

exports.config = {
    seleniumArgs: ['-browserTimeout=60'],

    "capabilities": {
        "browserName": "phantomjs",
        'phantomjs.cli.args': [
            '--ignore-ssl-errors=true',  
            '--web-security=false'
        ]
    },

    specs: [
        "test.js"
    ],

    framework: "jasmine2",

    allScriptsTimeout: 20000,

    onPrepare: function () {
        browser.driver.manage().window().maximize();
    },

    jasmineNodeOpts: {
        showColors: true,
        isVerbose: true,
        includeStackTrace: true,

        defaultTimeoutInterval: 25000
    }
};

There are a lot of people asking how to tackle an error like this:

There are different workarounds suggested but none of them worked for me and other people.

Which leads to the main point of the answer: why phantomjs in the first place?

As noted by protractor developers:

We recommend against using PhantomJS for tests with Protractor. There are many reported issues with PhantomJS crashing and behaving differently from real browsers.

Extending the point.

If the main purpose for using protractor is end-to-end testing, then you should definitely rethink your browser choice. End to end tests should imitate a real user of your application which, I'm pretty sure, would not use phantomjs to browse your site.

If the reason to choose phantomjs is the absence of a real display, you can use virtual one with the help of xvfb (see more here) or run your tests on a remote selenium server, either your own, or provided by BrowserStack or Sauce Labs.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • thanks for the exhausting answer! I still cannot run this , but anyway will accept the answer (the only difference is that my phantom is `v1.98`) . Sauce labs looks promising :-) – npocmaka May 08 '15 at 07:36