Protractor Running Tests On PhantomJS

I can't seem to get PhantomJS through a test successfully. I tried to integrate it into my project, but after that failed I tried to just run the basic Angular Docs samples and I'm getting the same issue. My steps so far:

  • npm install -g phantomjs
  • phantomjs --webdriver=9515 // ... GhostDriver - Main - running on port 9515
  • protractor protractorConf.js

This is the same file from the example with only browserName, and seleniumAddress port changed:

// An example configuration file.
exports.config = {
  // The address of a running selenium server.
  seleniumAddress: 'http://localhost:9515',

  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'phantomjs'

  // Spec patterns are relative to the current working directly when
  // protractor is called.
  specs: ['onProtractorRunner.js'],

  // Options to be passed to Jasmine-node.
  jasmineNodeOpts: {
    showColors: true,

I get the following error message:

UnknownError: Error Message => 'Detected a page unload event; asynchronous script execution does not work across page loads.'

I found this issue on github, which seemed to be related. I thought I had made enough sense of their to include it in one of my beforeEach functions. Then I found hereptor is just wrapping the driver anyway. Wow, I know I'm a noob here in protractor/selenium land, but the signal to noise ratio is intensively dissuasive. I'd really like to get the performance benefits of using PhantomJS, but the prospect of losing several more hours on this is hurting my head. I'm on Windows 7 Enterprise 64-bit, in case that matters. Thanks!



Acutally this fix was solving the same issue for me:

As originally described here: by renanmartins

Inside protractor/lib/protractor.js Replace

    ' = "' + DEFER_LABEL + '" +;' +
    'window.location.href = "' + destination + '"');


  var driver = this.driver;
  this.getCapabilities().then(function (capabilities) {
    if (capabilities.caps_.browserName === 'phantomjs') {
      driver.executeScript(' = "' + DEFER_LABEL + '" +;');
    } else {
          ' = "' + DEFER_LABEL + '" +;' +
          'window.location.href = "' + destination + '"');

    // Make sure the page is an Angular page.
    driver.executeAsyncScript(clientSideScripts.testForAngular, 10).
      then(function(hasAngular) {
        if (!hasAngular) {
          throw new Error('Angular could not be found on the page ' +