Added implicit timeout handling
This commit is contained in:
		| @@ -14,19 +14,36 @@ import org.testng.annotations.Test; | |||||||
| public class BasicTest  { | public class BasicTest  { | ||||||
|         private WebDriver driver; |         private WebDriver driver; | ||||||
|         private WebDriverWait wait; |         private WebDriverWait wait; | ||||||
|  | 	private implicitTimeoutMilliseconds = 3000; | ||||||
|  | 	private timeoutInSeconds = 20; | ||||||
| 	String URL = "https://0.fredldev.fremo-net.eu"; | 	String URL = "https://0.fredldev.fremo-net.eu"; | ||||||
|  |  | ||||||
| 	@BeforeClass | 	@BeforeClass | ||||||
| 	public void testSetUp() { | 	public void testSetUp() { | ||||||
| 		 | 		 | ||||||
| 		driver = new HtmlUnitDriver(true); | 		driver = new HtmlUnitDriver(true); | ||||||
|                 wait = new WebDriverWait(driver, 15); |                 wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds)); | ||||||
|  | 		driver.manage().timeouts().implicitlyWait(implicitTimeoutMilliseconds, TimeUnit.MILLISECONDS); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	@AfterClass | 	@AfterClass | ||||||
| 	public void tearDown() { | 	public void tearDown() { | ||||||
| 		driver.quit(); | 		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 | 	@Test | ||||||
| 	public void verifyFredlPageTitle() { | 	public void verifyFredlPageTitle() { | ||||||
| @@ -43,7 +60,7 @@ public class BasicTest  { | |||||||
|                 // String body = driver.getPageSource(); |                 // String body = driver.getPageSource(); | ||||||
|                 // System.out.println("HTML: " + body); |                 // 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"); | 		  System.out.println("Cookies consent page is shown"); | ||||||
| 		  WebElement consentButton = driver.findElement(By.id("opt-in-button-allow")); | 		  WebElement consentButton = driver.findElement(By.id("opt-in-button-allow")); | ||||||
| 		  consentButton.click(); | 		  consentButton.click(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user