Ram
Ram

Reputation: 19

Selenium Explicit wait

Can any one let me know how and where to implement Explicit Wait in POM frameowrk?

I mean, where should i implement explicit wait code? In POM classes or in Test Case classes?

since now, i have implemented the EW code line in POM class and within the constructor body, below code

public RegistrationPage (WebDriver driver)
    {
        PageFactory.initElements(driver, this);
        new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOf(GenderRadioButton));
    }

This worked fine for me, but not 100% sure whether or not this is a correct place to implement Explicit wait, need some insight on this plz

--- Ram

Upvotes: 0

Views: 265

Answers (1)

j.barrio
j.barrio

Reputation: 1038

You could try with this:

public RegistrationPage (WebDriver driver, int timeOutSeconds)
{
    driver.manage().timeouts().implicitlyWait(timeOutSeconds, TimeUnit.SECONDS);
    PageFactory.initElements(driver, this);
    new FluentWait<WebDriver>(driver)
            .withTimeout(timeOutSeconds, TimeUnit.SECONDS)
            .pollingEvery(RETRY_TIME, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class)
            .until(ExpectedConditions
                    .visibilityOf(By.xpath(xpath)))
   driver.manage().timeouts().implicitlyWait(timeOutSeconds, CLASS_VARIABLE_IMPLICIT_TIMEOUT);
}

Upvotes: 1

Related Questions