I've created this step definition to check if a given text exists in a web page. The code works properly but sometimes, expecially when I look for a long text, I get an error even if the text exists in the page.
The code is this:
this.Then(/^The text "([^"]*)" exists in page$/, function(myText, callback){
browser.sleep(10000);
var selectedElement = element(by.xpath("//*[. = '" + myText + "']"));
expect(selectedElement.isPresent()).to.eventually.equal(true, "This text is not present in page").and.notify(callback);
});
Basically I do three things:
- I wait 10 seconds to be sure that all elements of the DOM have been loaded.
- I seach for an element(div, p, label or whatever) thet contains the text I'm looking for.
- I check if the element is present oterwise I get an error.
Can you tell me if there is a better way to do this? It's correct to use browser.sleep() at the beginning of a step definition to wait for the DOM loading?
IMPORTANT: I'm not using Angularjs
Thank you in advance.