Reputation: 133
I have the below spec which is working fine, but I want to prevent using browser.sleep()
:
it('should go to the item details page', function () {
browser.get(testOptions.baseUrl+testOptions.cpdmPath+testOptions.itemDetailsForAttachment);
browser.getCurrentUrl().then(function() {
//browser.driver.sleep('4000');
console.log('inside then 4');
browser.driver.sleep('4000');
element(by.css('.md-header-items-container')).isDisplayed().then(function (isVisible) {
if (isVisible) {
// element is visible
browser.driver.sleep('4000');
element.all(by.repeater('(key, value) in tabList')).count().then(function (numberOfTabs) {
//console.log(numberOfTabs);
});
element.all(by.repeater('(key, value) in tabList')).get(4).click().then(function () {
browser.driver.sleep('4000');
element(by.css('.hidden-attachment-info-bar')).isDisplayed().then(function (isVisible) {
expect(isVisible).to.equal(true);
})
});
} else {
// element is not visible
console.log('is invisible');
}
});
})
});
Upvotes: 0
Views: 1374
Reputation: 133
Finally, I got it working as below:
it('should go to the attachments page and pass waiting time for element', function() {
browser.get(testOptions.baseUrl+testOptions.cpdmPath+testOptions.itemDetailsForAttachment);
browser.wait(function() {
return browser.driver.isElementPresent(cpdmAttachTabPage.notificationBar);
}, 90000);
browser.driver.isElementPresent(cpdmAttachTabPage.notificationBar).then(function(isVisible) {
console.log(isVisible);
expect(isVisible).to.equal(true);
})
})
Upvotes: 0
Reputation: 473863
A common alternative to using sleep()
with hardcoded time intervals is to use wait()
and explicitly wait for a specific condition to be met. For example, wait for element to be visible:
var EC = protractor.ExpectedConditions;
var elm = element(by.css('.md-header-items-container'));
browser.wait(EC.visibilityOf(elm), 4000);
Upvotes: 3