2

Refrence: Speeding up end-to-end tests

I tried removing ImplicitWaits and I found myself ending up writing too much code for every click and sendkeys etc. I have to put wait condition for every base function.

Implicit Wait:

public WebDriver openBrowser() {
 System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + getProperty("chromeDriver_exe"));
            driver = new ChromeDriver();
        } 
 driver.manage().window().maximize();
 driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

    }

Click Function:

public void click(String locatorKey) {
        //Put Wait condition else element will be remain unattended/notFound
        driver.findElement(By.xpath(xpathExpression)).click();

        logger("Clicked on " + locatorKey);
    }
  • What is your question? Where do you want to remove implicit wait from? why do you need to wrap each click in own function? – Alexey R. Jun 23 '18 at 20:58
3

If you really want to speed up your e2e tests, I don't think replacing all implicit waits by fluent wait will help that much. Instead, i would suggest exploring selenium grid or cloud based solutions like saucelabs.

Practically we do use both implicit and fluent wait for different purposes depending on the scenario.

  • Yes, I agree it is not an replacement, both have their own places based on scenarios however instead of having large implicit waits I prefer short implicit waits coupled with conditional waits based on each individual scenarios. – Vishal Aggarwal Jun 24 '18 at 20:12
  • I never wrote it is only a difference maker, but it could be one among many like you listed. I have already provided the reference which has list of ways which can speed up tests. – paul Jun 25 '18 at 4:10
2

Use Explicit or FluentWait instead of implicit wait.

Why not implicitWait for everything?

So, there are certain elements that might take longer to load or there is a certain amount of uncertainty in the loading time. So, waits should be used for such elements only.

I would call it a deliberate exemption but not every element should enjoy this exemption. With implicit wait, every page element have this luxury to be loaded within the time defined for implicitWait which should not be the case. If regular page elements are taking time to load then we want to know this as this might be a potential issue.

Why implicitWait?

So, in case, if overall, the website is slow but we still want to go ahead with functional automation then implicitWait is a good option with a time value of 500ms to 1 sec or whatever required. Now, this value will apply to all the elements however, you find some of the page elements (which are important for automation) taking longer than usual then explicit or fluentWait should be used for such elements.

2

Yes, I would suggest using fluent wait in each base action methods like click,enterText, select etc.

It tries to find the web element repeatedly at very short intervals of time until the timeout or till the object gets found instead of longer static waits for every object.

This saves huge time in larger automated suites.

Code Example:

browser.manage().timeouts().implicitlyWait(0);
browser.wait(function () {
    browser.sleep(1000);
    return element(by.id('id1')).isDisplayed()
    .then(
        function (isDisplayed) { 
            return isDisplayed; 
        }, 
        function (error) { 
            return false 
        });
}, 20 * 1000);

Note: By making the implicit wait to zero, we are making sure that the implicit wait timeout does not interfere with our polling interval.

  • Do you mind sharing the one that you wrote? If it was so useless why it was there at all since beginning of selenium? – paul Jun 24 '18 at 3:42
  • Added an example. – Vishal Aggarwal Oct 17 '18 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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