Added implicit timeout handling
This commit is contained in:
parent
90612a1880
commit
75f1b8942c
|
@ -14,13 +14,16 @@ import org.testng.annotations.Test;
|
|||
public class BasicTest {
|
||||
private WebDriver driver;
|
||||
private WebDriverWait wait;
|
||||
private implicitTimeoutMilliseconds = 3000;
|
||||
private timeoutInSeconds = 20;
|
||||
String URL = "https://0.fredldev.fremo-net.eu";
|
||||
|
||||
@BeforeClass
|
||||
public void testSetUp() {
|
||||
|
||||
driver = new HtmlUnitDriver(true);
|
||||
wait = new WebDriverWait(driver, 15);
|
||||
wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
|
||||
driver.manage().timeouts().implicitlyWait(implicitTimeoutMilliseconds, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -28,6 +31,20 @@ public class BasicTest {
|
|||
driver.quit();
|
||||
}
|
||||
|
||||
private boolean elementExistsByXpath(String xpath) {
|
||||
driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS);
|
||||
boolean exists = driver.findElements( By.xpath(xpath) ).size() != 0;
|
||||
driver.manage().timeouts().implicitlyWait(implicitTimeoutMilliseconds, TimeUnit.MILLISECONDS);
|
||||
return exists;
|
||||
}
|
||||
|
||||
private boolean elementExistsById(String id) {
|
||||
driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS);
|
||||
boolean exists = driver.findElements( By.id(id) ).size() != 0;
|
||||
driver.manage().timeouts().implicitlyWait(implicitTimeoutMilliseconds, TimeUnit.MILLISECONDS);
|
||||
return exists;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyFredlPageTitle() {
|
||||
driver.navigate().to(URL);
|
||||
|
@ -43,7 +60,7 @@ public class BasicTest {
|
|||
// String body = driver.getPageSource();
|
||||
// System.out.println("HTML: " + body);
|
||||
|
||||
if (driver.findElements( By.id("privacy-cookie-statement") ).size() != 0) {
|
||||
if (elementExistsById("privacy-cookie-statement")) {
|
||||
System.out.println("Cookies consent page is shown");
|
||||
WebElement consentButton = driver.findElement(By.id("opt-in-button-allow"));
|
||||
consentButton.click();
|
||||
|
|
Loading…
Reference in New Issue