I am running angular e2e scripts.
I am adding explicit wait for every element.
Instead, is it possible to tell protractor to delay 3 seconds for every command?
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.
Sign up to join this communityI think you can use the implicitlyWait option, although it has been removed from the Protractor documentation:
onPrepare: function(){
browser.manage().timeouts().implicitlyWait(3000);
},
Code example from: https://stackoverflow.com/questions/33299567/where-to-put-implicitlywait-in-protractor
Read this!!!: Is it a bad practice to use implicit wait in Selenium Webdriver? Should one use only explicit wait?
Alternatively:
Wrap your driver/browser in your own helper class and implement your own "findElement()
" method which always does an explicitWait.
My pageObjects action methods start with a wait for the first element and then expect the other elements to be there:
internal string ActionOnPage() {
wait.ForElement(By.Id("uniqueid1")).SendKeys("sometext");
driver.FindElement(By.Id("uniqueid2")).Click();
}
This wait.ForElement()
is just a wrapper around the driver:
public IWebElement ForElement(By by, int seconds = 10)
{
var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(seconds));
return wait.Until(f => f.FindElement(by));
}
The example is in C#, but I think it translates to JavaScript/Protractor
No, You should NOT use static waits, it is a bad practice. Instead...Read below
Disclaimer : I am an actual Protractor SDET, who has been using Protractor from last couple of years in actual Large Projects.
Using Hard coded waits(static wait) along with every statement is an very bad practice for multiple reasons:
Code Example:
var EC = protractor.ExpectedConditions;
// Waits for the element with id 'abc' to be clickable.
browser.wait(EC.elementToBeClickable($('#abc')), 5000);
Or may be you can generalize as common function:
function genericWait(expectedCondition) {
return browser.wait(expectedCondition, 3000).then(function() {
return true;
}, function() {
return false;
});
}
And then it can be resolved using an expect(from jasmine framework)
expect(genericWait(protractor.ExpectedConditions.presenceOf(locator))).toBe(true);