1

I'm verifying and also clicking on elements of pop up window on Angular page with Protractor. The problem is that verification fails randomly.

My spec file:

describe('...
    it('...
        // initialize page object
        var home = new homePage();

        // hover over the shopping cart icon
        browser.actions().mouseMove(home.shoppingCartLink).perform();

        // pause browser for 4 sec
        browser.sleep(4000);

        // initialize page object
        var shoppingCartPreview = new shoppingCartPage();

        // hover over the shopping cart preview window
        browser.actions().mouseMove(shoppingCartPreview.window).perform();

        // verify elements are displayed
        expect(shoppingCartPreview.shopName.isDisplayed()).toBeTruthy();
        expect(shoppingCartPreview.price.isDisplayed()).toBeTruthy();
        expect(shoppingCartPreview.delete.isDisplayed()).toBeTruthy();

        // click on "Checkout" button
        shoppingCartPreview.checkoutButton.click();
    });
});

As wtritten, the problem is that for all the verifications I get falsy instead of truthy. What I'm doing wrong?

I even tried with the following without a success:

// waiting for elements to be visible
browser.wait(EC.presenceOf(shoppingCartPreview.popUpWindow),10000);
browser.wait(EC.presenceOf(shoppingCartPreview.shopName),10000);
browser.wait(EC.presenceOf(shoppingCartPreview.price),10000);
browser.wait(EC.presenceOf(shoppingCartPreview.delete),10000);
jurijk
  • 309
  • 8
  • 22
  • Found a solution at: http://stackoverflow.com/questions/25062748/testing-the-contents-of-a-temporary-element-with-protractor/32076359#32076359 – jurijk Mar 13 '17 at 13:02

1 Answers1

2

The problem is - you are waiting on - presenceOf() which only checks the presence of the element in DOM and hence it will always return true whether your pop-up is visible or not.

You need to wait like this leveraging visibilityOf() - browser.wait(EC.visibilityOf(shoppingCartPreview.popUpWindow), 5000)

AdityaReddy
  • 3,625
  • 12
  • 25
  • I'm ashamed! I use this for spinner, but didn't think I can use it for this as well. THANK YOU! – jurijk Mar 14 '17 at 06:25