How would we make sure that a page is loaded using Selenium WebDriver?
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.JavascriptExecutor;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;
public class CheckPageLoad {
static WebDriver driver;
static String pageLoadingStatus = null;
@Test
void TestCase1_HomePage_LoadingCheck(){
System.setProperty("webdriver.chrome.driver","Add your chromedriver.exe path here");
driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://postbysanta.in");
JavascriptExecutor js;
js = (JavascriptExecutor) driver;
String pageLoadStatus = (String)js.executeScript("return document.readyState");
System.out.println(pageLoadStatus);
stringCompare(pageLoadStatus, "complete");
}
public static void stringCompare(String ExpectedString, String ActualString){
AssertJUnit.assertEquals("Comparison failed", ExpectedString,ActualString);
}
}
Comments
Post a Comment