angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

PhantomJS sometimes crashes #557

Closed mcalthrop closed 8 years ago

mcalthrop commented 10 years ago

I have been successfully running a fairly comprehensive suite of Protractor e2e tests using Chrome on OSX (Mavericks: 10.9.2).

We have a technical requirement to run these tests headlessly, so I swapped in PhantomJS instead of Chrome, and after 20 seconds (consistently), I get the following error:

Runner Process Exited With Error Code: 8
Fatal error: protractor exited with code: 1

Now for some more detailed information.

Here is the full error output from the grunt task I am running:

Running "protractor:phantomjs" (protractor) task
------------------------------------
PID: 9678 (capability: phantomjs #1)
------------------------------------
Starting selenium standalone server...
Selenium standalone server started at http://192.168.1.111:4444/wd/hub
/path/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1562
throw error;
^
UnknownError: null
at new bot.Error (/path/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:109:18)
at Object.bot.response.checkResponse (/path/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/response.js:106:9)
at /path/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:135:24
at /path/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1178:15
at webdriver.promise.ControlFlow.runInNewFrame_ (/path/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1455:20)
at notify (/path/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:328:12)
at notifyAll (/path/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:297:7)
at fulfill (/path/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:402:7)
at /path/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1178:15
at webdriver.promise.ControlFlow.runInNewFrame_ (/path/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1455:20)
==== async task ====
    WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (/path/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:132:49)
at Function.webdriver.WebDriver.createSession (/path/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:111:30)
at Builder.build (/path/node_modules/protractor/node_modules/selenium-webdriver/builder.js:105:20)
at LocalDriverProvider.getDriver (/path/node_modules/protractor/lib/driverProviders/local.dp.js:128:9)
at /path/node_modules/protractor/lib/runner.js:327:35
at _fulfilled (/path/node_modules/protractor/node_modules/q/q.js:797:54)
at self.promiseDispatch.done (/path/node_modules/protractor/node_modules/q/q.js:826:30)
at Promise.promise.promiseDispatch (/path/node_modules/protractor/node_modules/q/q.js:759:13)
at /path/node_modules/protractor/node_modules/q/q.js:573:44
    [launcher] Runner Process Exited With Error Code: 8
>>
Fatal error: protractor exited with code: 1

Package versions:

"grunt-protractor-runner": "~0.2.3"
"protractor": "0.19.0"
"selenium-webdriver": "~2.40"

Contents of protractor.conf.js:

exports.config = {
    seleniumServerJar: '../../node_modules/protractor/selenium/selenium-server-standalone-2.39.0.jar',
    seleniumPort: 4444,
    seleniumArgs: ['-browserTimeout=60'],
    specs: [
        '../e2e/utils.js',
        '../e2e/**/*-suite.js'
    ],
    capabilities: {
        browserName: 'phantomjs',
        'phantomjs.binary.path': './node_modules/karma-phantomjs-launcher/node_modules/phantomjs/bin/phantomjs',
        'phantomjs.cli.args': ['--debug=true', '--webdriver', '--webdriver-logfile=webdriver.log', '--webdriver-loglevel=DEBUG']
    },
    baseUrl: 'http://localhost:9292',
    rootElement: 'body',
    onPrepare: function () {
        require('jasmine-reporters');
        jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('test/results/', true, true));
    },
    framework: 'jasmine',
    jasmineNodeOpts: {
        onComplete: function () {
        },
        isVerbose: true,
        showColors: true,
        includeStackTrace: true,
        defaultTimeoutInterval: 30000
    }
};

I have tried installing version ~1.9.7-1 of the phantomjs package independently of the one that protractor depends upon, and updating the phantomjs.binary.path property in protractor.conf.js, but I get the same result.

After spending far too long debugging the JS to try to isolate where the error is occurring, I know that it is falling over in runner.js.

Specifically in Runner.prototype.runJasmine_(), the anonymous function passed to webdriver.promise.controlFlow().execute() here is never executed.

Can anyone help?

Let me know if you need more information.

Matt

manuelmazzuola commented 10 years ago

Yes, the same for me, if i delete the ignoreSynchronization and the sleep methods, it fails, but works fine with chrome.

ghost commented 10 years ago

I have experienced a similar but not exact issues. After tried for half day, I finally get my situation working using the PhantomJS official website's executable.

I downloaded the phantomjs.exe directly from http://phantomjs.org/download.html and then copy the exe on the same directory as my gruntfile (which is on my PATH), such that the exe get executed, but not the nodejs version of phantomJs that installed by npm. Since phantomjs is on PATH, I don't need the 'phantomjs.binary.path' setting (remove it).

When I run grunt, the firewall dialogue pop up asking me to allow phantomjs.exe access on network (I didn't take the screenshot, but here is a similar one, just use your imagination to replace that little IE icon with PhantomJs 's ghost icon yourself, you get what I mean) image

After clicking allow, it is all working fine.

So I am not sure if it is related to firewall setting or is in fact the npm installed phantomJS package is not fully working. However, I am able to run karma with phantomJS using the karma-phantomjs-launcher which is installed by npm.

juliemr commented 9 years ago

Hi folks, I just want to give an update here. Protractor does NOT test against PhantomJS in our CI environment, and while we'll try to address issues and look at pull requests that improve PhantomJS problems, it is not a high issue for the core team to work on personally.

In issue detro/ghostdriver#328 the phantom devs said some of this instability would be addressed with PhantomJS 2.0.

natkrish commented 9 years ago

I am getting same error when running my protractor cucumber js framework using phantomjs. Error while running module script protractorBaseModule_: Error communicating with the remote browser. It may have died. Does anyone know whether this issue has been fixed?

dotjose-zz commented 9 years ago

I have been working on protractor and when I used firefox browser to run my test specs on all my tests have passed. But when I used phantomjs to all my test specs that have been passed on firefox have failed and returns an error code 1. Does any one who have faced such an issue and fix it?

bentolor commented 8 years ago

I experience reproducable this crash on a CI server after upgrading from PhantomJS 1.9.18 to 1.9.19.

build   30-Nov-2015 16:18:20    /data/jira/bamboo-home/xml-data/build-dir/XX-DASH-CLIENTCI/client/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:108
build   30-Nov-2015 16:18:20      var template = new Error(this.message);
build   30-Nov-2015 16:18:20                     ^
build   30-Nov-2015 16:18:20    UnknownError: Session [8a8ef2a0-9775-11e5-ad8a-89605c3acb91] was terminated due to FORWARDING_TO_NODE_FAILED
build   30-Nov-2015 16:18:20        at new bot.Error (/data/jira/bamboo-home/xml-data/build-dir/XX-DASH-CLIENTCI/client/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:108:18)
build   30-Nov-2015 16:18:20        at Object.bot.response.checkResponse (/data/jira/bamboo-home/xml-data/build-dir/XX-DASH-CLIENTCI/client/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/response.js:109:9)
build   30-Nov-2015 16:18:20        at /data/jira/bamboo-home/xml-data/build-dir/XX-DASH-CLIENTCI/client/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:379:20
    ...
build   30-Nov-2015 16:18:20    [launcher] Process exited with error code 1

Interestingly it does not crash if I execute the very same command in a terminal session on the very same server nor on my own PC.

Downgrading did improve the likelihood for success, but not fix it.

artemjackson commented 8 years ago

Same issue with Phantomjs 1.9.19 but it works with 1.9.18

cjeffers commented 8 years ago

I was having the same issue with PhantomJS 1.9.x, but it appears* to be fixed by upgrading to the latest version of PhantomJS (2.1.3 currently). If this was the fix, it appears the issue lies with PhantomJS. Further, since it appears to be fixable by upgrading, could this issue potentially be closed?

*no failures in 10 runs of a suite that failed on ~40% of runs with 1.9.x. If this doesn't seem significant enough to justify the label "fixed", I can do more runs.

joaoffalcao commented 8 years ago

As @cjeffers said, after upgrading to PhantomJS 2.1.3, this issue doesn't happened anymore.

kscc25 commented 8 years ago

Yes, this is fixed by upgrade to PhantomJS 2 https://github.com/detro/ghostdriver/issues/328#issuecomment-44309690

NickTomlin commented 8 years ago

I'll go ahead and close the loop here because upgrading to PhantomJS 2 resolves this 👏 👏 🎊 🎺

I'd also like to restate what Julie mentioned earlier:

Protractor does NOT test against PhantomJS in our CI environment, and while we'll try to address issues and look at pull requests that improve PhantomJS problems, it is not a high issue for the core team to work on personally.

If anyone encounters additional issues with Phantom, please try to raise an issue on the Phantom queue and resolve it there. Thanks, y'all are awesome! 😺