I have created a new class called "FluentWaitClass" and added fluent wait like below: And I want to use this wait functionality to check whether my login page has loaded in one of my below test case "TC_LoginTest_001.java". Can anyone please help letting me know how to do that ?
package com.internetBanking.utilities;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import com.google.common.base.Function;
public class FluentWaitClass {
WebDriver driver;
// Waiting 30 seconds for an element to be present on the page, checking
// for its presence once every 5 seconds.
@SuppressWarnings("deprecation")
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(new Function<WebDriver, WebElement>()
{
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
});
}
**TC_LoginTest_001.java**
package com.internetBanking.testCases;
import org.testng.annotations.Test;
import com.internetBanking.pageObjects.LoginPage;
import com.internetBanking.utilities.*;
public class TC_LoginTest_001 extends BaseClass {
@Test
public void LoginTest() {
driver.get(baseURL);
logger.info("URL is opened");
FluentWaitClass fluentwait = new FluentWaitClass();
LoginPage loginPage = new LoginPage(driver);
loginPage.setUsrname(username);
logger.info("Username is entered");
loginPage.setPwd(password);
logger.info("Password is entered");
loginPage.login();
logger.info("Login button is clicked");
}
}```