Wednesday, December 30, 2015

E2E Test - Protractor - Wait for google map markers to present

The problem is that in my e2e-test I expect markers to present on map too early before google maps api actually rendering them.

This is, or should be, an easy one, nevertheless it pained my ass because I'm a stinky newbie to Protractor.

TL;DR: Use browser.wait(protractor.until.elementLocated(locator), timeout) to wait for markers to present, like the following code

 browser.wait(protractor.until.elementLocated(by.className('gmnoprint')), 10000);  

The above code tells browser to wait at most 10 seconds for markers to present.
Then you can safely make expectations upon them.

 expect(element.all(by.xpath("//div[@class=\"gmnoprint\" and @title]")).count()).toBeGreaterThan(0);  

And thanks to this article, Protractor Testing with Google Map Markers and Markerclusterers, without which I could never get a clue about how to access markers DOM in protractor. (with a class name = "gmnoprint", how the hell do I know it?)

No comments:

Post a Comment