"Detected a page unload event" error in phantom.js
Trying to run "onMocha.js" example with phantomjs or chromedriver doesn't seem to work.
Here's the code, I only changed webdriver.Capabilities.chrome() to webdriver.Capabilities.phantomjs() and expect.js to chai
/**
* This example shows how to use the protractor library in a Mocha test.
* It assumes that a selenium server is running at localhost:4444.
* Run this test with:
* mocha onMocha.js
*/
var util = require('util');
var expect = require('chai').expect;
var webdriver = require('selenium-webdriver');
var protractor = require('../lib/protractor.js');
describe('angularjs.org homepage', function() {
this.timeout(80000);
var driver, ptor;
before(function() {
driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.phantomjs()).build();
driver.manage().timeouts().setScriptTimeout(10000);
ptor = protractor.wrapDriver(driver);
});
after(function(done) {
driver.quit().then(function() {done()});
})
it('should greet using binding', function(done) {
ptor.get('http://www.angularjs.org');
ptor.findElement(protractor.By.input('yourName')).sendKeys('Julie');
ptor.findElement(protractor.By.binding('{{yourName}}')).
getText().then(function(text) {
expect(text).to.eql('Hello Julie!');
done();
});
});
... snip
});
Here's the error
Uncaught UnknownError: Error Message => 'Detected a page unload event; asynchronous script execution does not work across page loads.'
caused by Request => {"headers":{"Accept":"application/json; charset=utf-8","Connection":"keep-alive","Content-Length":"425","Content-Type":"application/json;charset=UTF-8","Host":"192.168.128.240:56087"},"httpVersion":"1.1","method":"POST","post":"{\"script\":\"return (function () {\\n var attempts = arguments[0];\\n var callback = arguments[arguments.length - 1];\\n var check = function(n) {\\n if (window.angular && window.angular.resumeBootstrap) {\\n callback(true);\\n } else if (n < 1) {\\n callback(false);\\n } else {\\n window.setTimeout(function() {check(n - 1)}, 1000);\\n }\\n };\\n check(attempts);\\n}).apply(null, arguments);\",\"args\":[10]}","url":"/execute_async","urlParsed":{"anchor":"","query":"","file":"execute_async","directory":"/","path":"/execute_async","relative":"/execute_async","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/execute_async","queryKey":{},"chunks":["execute_async"]},"urlOriginal":"/session/e2dbebc0-1b3f-11e3-84c0-67b730e3988e/execute_async"}
at new bot.Error (./node_modules/selenium-webdriver/lib/atoms/error.js:109:18)
at Object.bot.response.checkResponse (./node_modules/selenium-webdriver/lib/atoms/response.js:106:9)
at ./node_modules/selenium-webdriver/lib/webdriver/webdriver.js:275:20
at ./node_modules/selenium-webdriver/lib/goog/base.js:1178:15
at webdriver.promise.ControlFlow.runInNewFrame_ (./node_modules/selenium-webdriver/lib/webdriver/promise.js:1438:20)
at notify (./node_modules/selenium-webdriver/lib/webdriver/promise.js:328:12)
at notifyAll (./node_modules/selenium-webdriver/lib/webdriver/promise.js:297:7)
at fulfill (./node_modules/selenium-webdriver/lib/webdriver/promise.js:402:7)
at ./node_modules/selenium-webdriver/lib/webdriver/promise.js:1305:10
at ./node_modules/selenium-webdriver/lib/goog/base.js:1178:15
at webdriver.promise.ControlFlow.runInNewFrame_ (./node_modules/selenium-webdriver/lib/webdriver/promise.js:1438:20)
at notify (./node_modules/selenium-webdriver/lib/webdriver/promise.js:328:12)
at notifyAll (./node_modules/selenium-webdriver/lib/webdriver/promise.js:297:7)
at fulfill (./node_modules/selenium-webdriver/lib/webdriver/promise.js:402:7)
at ./node_modules/selenium-webdriver/lib/goog/base.js:1178:15
at webdriver.promise.ControlFlow.runInNewFrame_ (./node_modules/selenium-webdriver/lib/webdriver/promise.js:1438:20)
at notify (./node_modules/selenium-webdriver/lib/webdriver/promise.js:328:12)
at notifyAll (./node_modules/selenium-webdriver/lib/webdriver/promise.js:297:7)
at fulfill (./node_modules/selenium-webdriver/lib/webdriver/promise.js:402:7)
at ./node_modules/selenium-webdriver/lib/webdriver/promise.js:607:51
at ./node_modules/selenium-webdriver/lib/webdriver/http/http.js:96:5
at IncomingMessage.<anonymous> (./node_modules/selenium-webdriver/http/index.js:113:7)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:895:16
at process._tickCallback (node.js:415:13)
==== async task ====
WebDriver.executeScript()
at webdriver.WebDriver.schedule (./node_modules/selenium-webdriver/lib/webdriver/webdriver.js:266:15)
at webdriver.WebDriver.executeAsyncScript (./node_modules/selenium-webdriver/lib/webdriver/webdriver.js:506:15)
at Protractor.get (./node_modules/protractor/lib/protractor.js:556:15)
at Context.<anonymous> (./node_modules/protractor/example/onMocha.js:32:10)
at Test.Runnable.run (./node_modules/protractor/node_modules/mocha/lib/runnable.js:194:15)
at Runner.runTest (./node_modules/protractor/node_modules/mocha/lib/runner.js:355:10)
at ./node_modules/protractor/node_modules/mocha/lib/runner.js:401:12
at next (./node_modules/protractor/node_modules/mocha/lib/runner.js:281:14)
at ./node_modules/protractor/node_modules/mocha/lib/runner.js:290:7
at next (./node_modules/protractor/node_modules/mocha/lib/runner.js:234:23)
at Object._onImmediate (./node_modules/protractor/node_modules/mocha/lib/runner.js:258:5)
at processImmediate [as _immediateCallback] (timers.js:317:15)
phantom
> phantomjs --version
1.9.1
I wasn't able to get protractor to work with plain chromedriver nor phantomjs... the only thing that worked was standalone selenium driver as per the doc.
Is there any insight into this error?
Haven't seen this one before and I can't reproduce it - do you see the chrome window pop up when you're running tests?
@juliemr is it working with phantomjs for you? I'm trying to setup e2e tests for our CI environment and really, really want to use protractor instead of karma and old e2e :( I can't use chromebecause of this.
I've dug a bit deeper into the issue, and tracked it down to this code
Protractor.prototype.get = function(destination) {
destination = url.resolve(this.baseUrl, destination);
this.driver.get('about:blank');
this.driver.executeScript('window.name += "' + DEFER_LABEL + '";' +
'window.location.href = "' + destination + '"');
// Make sure the page is an Angular page.
this.driver.executeAsyncScript(clientSideScripts.testForAngular, 10).
...
I think what happens here is that window.location.href triggers page unload for the current about:blank while testForAngular is waiting for angular framework... apparently phantomjs doesn't like that. Any suggestions?
@juliemr there should be no chrome windows because it's phantomjs.
Same issue here. It sometimes throws that exception.
Ditto, same issue here with PhantomJS. The error manifests itself intermittently. Seems that if I wait long enough between test runs there are no errors. Strange because I have checked that the selenium process has terminated properly.
Seems to be a timing issue. My coworker has a newer Macbook Air than I do which is much faster and he cannot reproduce the error. Our tests are also automated and idiot-proof so that our node webserver and the selenium server are started immediately before running the tests and shutdown immediately afterwards. After modifying the process so that the node webserver and selenium are kept running between test runs the error goes away.
:+1: I'm seeing this on about 80% of test runs from my machine with Phantom
I was getting this 100% of the time on my latest macbook air with 8gb ram and phantom 1.9.1
I'm also on the latest MacBook Air with 8gb of ram and I'm now getting it more like 95% of the time.
On Wed, Sep 18, 2013 at 4:48 PM, Alex Gorbatchev [email protected] wrote:
I was getting this 100% of the time on my latest macbook air with 8gb ram and phantom 1.9.2
Reply to this email directly or view it on GitHub: https://github.com/angular/protractor/issues/85#issuecomment-24698000
I'm seeing it a lot on a retina Macbook Pro. Close to 95% of the time.
Given that protractor was working fine for me last week, I suspect that one of its transitive dependencies has updated and effectively broken it. When I don't get this error, I get timeouts.
On Wed, Sep 18, 2013 at 5:27 PM, seubert [email protected] wrote:
I'm seeing it a lot on a retina Macbook Pro. Close to 95% of the time.
Reply to this email directly or view it on GitHub: https://github.com/angular/protractor/issues/85#issuecomment-24700945
Also, important to mention, I have no problems when using selenium+chromedriver or even saucelabs service. This problem seems to be specific to phantomjs :(
Alex Gorbatchev (650) 931-5954
On Wed, Sep 18, 2013 at 2:28 PM, Justin Searls [email protected]:
Given that protractor was working fine for me last week, I suspect that one of its transitive dependencies has updated and effectively broken it. When I don't get this error, I get timeouts.
On Wed, Sep 18, 2013 at 5:27 PM, seubert [email protected] wrote:
I'm seeing it a lot on a retina Macbook Pro. Close to 95% of the time.
Reply to this email directly or view it on GitHub: https://github.com/angular/protractor/issues/85#issuecomment-24700945
— Reply to this email directly or view it on GitHubhttps://github.com/angular/protractor/issues/85#issuecomment-24701034 .
Thanks for all the reports - I'll do some playing around with phantomjs and see if I can reproduce reliably.
Anyone have any workarounds for this? Very disappointing.
Also am running into this almost all the time on a really nice Mac Mini.
FWIW, I was able to change the message by manually wiping out node_modules/selenium-webdriver and npm install [email protected] (2.35.1 had been installed).
I'm getting a timeout now instead, but not the page unloaded error.
I'm still having the same issue with 2.35.0
+1 for this. With ptor.sleep() I was able to get it to work once but only once (so it seems inconsistent - works once and awhile but not reliably) - it does seem to be a timing issue as it works fine with chromedriver but not with PhantomJS. I also got an Angular not loaded (or similar) error with PhantomJS.
@juliemr I get the same issue with phantomjs.Otherwise my tests are running fine with chrome and firefox. But my long term goal is to opt for headless browser testing for the continuous CI. Below is the error detail that i get.
UnknownError: Error Message => 'Detected a page unload event; asynchronous script execution does not work across page loads.' caused by Request => {"headers":{"Accept":"application/json, image/png","Connection":"Keep-Alive","Content-Length":"425","Content-Type":"application/json; charset=utf-8","Host":"localhost:33735"},"httpVersion":"1.1","method":"POST","post":"{"args":[10],"script":"return (function () {\n var attempts = arguments[0];\n var callback = arguments[arguments.length - 1];\n var check = function(n) {\n if (window.angular && window.angular.resumeBootstrap) {\n callback(true);\n } else if (n < 1) {\n callback(false);\n } else {\n window.setTimeout(function() {check(n - 1)}, 1000);\n }\n };\n check(attempts);\n}).apply(null, arguments);"}","url":"/execute_async","urlParsed":{"anchor":"","query":"","file":"execute_async","directory":"/","path":"/execute_async","relative":"/execute_async","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/execute_async","queryKey":{},"chunks":["execute_async"]},"urlOriginal":"/session/0a38df00-2c72-11e3-a864-e527bed93cbd/execute_async"} Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01' System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.5', java.version: '1.6.0_51' Driver info: driver.version: unknown