user7420873
user7420873

Reputation: 21

Protractor not waiting for page load

I created a basic test with protractor to click on a element and on the new page check if given element exists, but Protractor does not seem to wait and it runs the assertion just after the click but before the new page loads. The element I am looking for is available on both pages, so protractor sees the element on the old page, before the new page loads. Can someone please tell me what am I doing wrong?

it('should check when new page is loaded', function () {
button.click().then(function (){
    return expect(newElement).to.exist;
});

Upvotes: 1

Views: 12397

Answers (2)

Parthi
Parthi

Reputation: 142

You can use below method in Configuration file

jasmineNodeOpts: {
    showColors: true,
    includeStackTrace: true,
    defaultTimeoutInterval: 1440000
},

And In Spec file you can customise the wait time according to page and object visibility

browser.sleep(20000);

I hope above method will work fine in all the cases if you customise the wait time Properly.

Upvotes: 0

Vishal Aggarwal
Vishal Aggarwal

Reputation: 4178

First of all ,add "getPageTimeout" variable to your Protractor configuration file.

If you are not using it already.This is to set global page timeout based on your average page load time in your application.

conf.js

getPageTimeout: 120000,//change it based on your app response time

If it does not help even then verify the page title of next page(assuming its different from previous page) before checking the actual element you are looking for.

it('should check when new page is loaded', function () {
button.click().then(function (){
    browser.getCurrentUrl();
    browser.getTitle().then(function (title) {
            expect(title).toEqual('Next Page Title');
        });
   return expect(newElement.isDisplayed()).toBeTruthy();
});

Even if that does not help you may use expected conditions.There are several predefined conditions to explicitly wait for. In case you want to wait for an element to become present:

var EC = protractor.ExpectedConditions;

var e = element(by.id('xyz'));
browser.wait(EC.presenceOf(e), 10000);

expect(e.isPresent()).toBeTruthy();

Upvotes: 7

Related Questions