1

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?

1
  • What have you tried so far? Please share your code. Oct 6, 2019 at 1:40

2 Answers 2

2

I 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

1

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:

  • It slows down the whole batch execution, particularly visible if you are running thousands of tests(like me!)
  • It still does not give guarantee that it will work in scenarios where application is even more slower.

Instead Use Dynamic Promise based waits because:

  • RELIABLE: It is always reliable as it waits till object/state is resolved through promise.
  • FASTER: it only relies on actual object availability so it is generally 10 times faster if implemented correctly and application response time is reasonable
  • Using DRY principle can be implemented globally by a single function.

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);

Protractor Documentation Reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.