Error by executeAsyncScript: Detected a page unload event; async script execution does not work across page loads
Hi folk, i got this error when running the executeAsyncScript(): "Detected a page unload event; async script execution does not work across page loads"
my code: create: function (contentObj) { return browser.executeAsyncScript(function(contentObj, callback) { var api = angular.injector(['module']).get('moduleService'); var aContentObj = new api.Page(contentObj); //return a resource object console.log('contentObj:' + JSON.stringify(pageContentObj)); aContentObj.$save(pageContentObj, function(createdPage) { callback(createdPage); }); }, contentObj); }
Has any one the same issue by executing asynscript? Any help is very appreciated Regards, Emy
Hey, you must be executing some sort of navigation somewhere, causing the page to unload. Without being able to see the rest of the code it's difficult to help you though
Hi, thanks for your answer, actually in the test i just log in the app and execute the script. The same test ececuting script for deleting and getting the object id work.
the test looks like that: beforeEach(function () { ptor = protractor.getInstance(); loginPage.goLogin(TEST_USERNAME, TEST_PASSWORD); //browser.manage().timeouts().setScriptTimeout(50000); });
iit('should create an object', function() {
//Create object with the api
helperApi.page.create(objContent).then(function(){
console.log('object created');
}, function(error) {
console.log("ERROR !!!" + error.message);
});
});
If i run the body part of executeAsyncScript on browser, it works:
var api = angular.injector(['module']).get('moduleService'); var aContentObj = new api.Page(contentObj); //return a resource object aContentObj.$save(pageContentObj);
And this test run and can delete object:
it('should be able to delete object', function() {
//Delete the created object
helperApi.page.delete(872).then(function(){
console.log('page is deleted:');
});
});
the helper api for deleting object:
delete: function (objId) { return browser.executeAsyncScript(function(objId, callback) { var api = angular.injector(['module']).get('moduleService'); api.Page.delete({objId: objId}, function(){ callback(); }); }, objId); }
Does the log in trigger page navigation? Is it synchronous?
Hi, sorry for the long delay, i was in holiday. The problem sovled, the parameter to the executeAsynscript shouldn't be an object but a string. Thanks for your reply :)