Skip to content

Commit

Permalink
Wait strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
angiejones committed Jul 9, 2019
1 parent 7b5db4e commit 9f83c37
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
42 changes: 42 additions & 0 deletions webdriver_java/src/main/java/pages/DynamicLoadingExample1Page.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package pages;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class DynamicLoadingExample1Page {

private WebDriver driver;
private By startButton = By.cssSelector("#start button");
private By loadingIndicator = By.id("loading");
private By loadedText = By.id("finish");

public DynamicLoadingExample1Page(WebDriver driver){
this.driver = driver;
}

public void clickStart(){
driver.findElement(startButton).click();
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.invisibilityOf(
driver.findElement(loadingIndicator)));

/* FLUENT WAIT */
// FluentWait wait = new FluentWait(driver)
// .withTimeout(Duration.ofSeconds(5))
// .pollingEvery(Duration.ofSeconds(1))
// .ignoring(NoSuchElementException.class);
// wait.until(ExpectedConditions.invisibilityOf(
// driver.findElement(loadingIndicator)));

}

public String getLoadedText(){
return driver.findElement(loadedText).getText();
}
}
20 changes: 20 additions & 0 deletions webdriver_java/src/main/java/pages/DynamicLoadingPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class DynamicLoadingPage {

private WebDriver driver;
private String linkXpath_Format = ".//a[contains(text(), '%s')]";
private By link_Example1 = By.xpath(String.format(linkXpath_Format, "Example 1"));

public DynamicLoadingPage(WebDriver driver){
this.driver = driver;
}

public DynamicLoadingExample1Page clickExample1(){
driver.findElement(link_Example1).click();
return new DynamicLoadingExample1Page(driver);
}
}
5 changes: 5 additions & 0 deletions webdriver_java/src/main/java/pages/HomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public WysiwygEditorPage clickWysiwygEditor(){
return new WysiwygEditorPage(driver);
}

public DynamicLoadingPage clickDynamicLoading(){
clickLink("Dynamic Loading");
return new DynamicLoadingPage(driver);
}

private void clickLink(String linkText){
driver.findElement(By.linkText(linkText)).click();
}
Expand Down
4 changes: 4 additions & 0 deletions webdriver_java/src/test/java/base/BaseTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import org.testng.annotations.BeforeMethod;
import pages.HomePage;

import java.util.concurrent.TimeUnit;


public class BaseTests {

private WebDriver driver;
Expand All @@ -16,6 +19,7 @@ public class BaseTests {
public void setUp(){
System.setProperty("webdriver.chrome.driver", "resources/chromedriver");
driver = new ChromeDriver();
//driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
goHome();
}

Expand Down
16 changes: 16 additions & 0 deletions webdriver_java/src/test/java/wait/WaitTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package wait;

import base.BaseTests;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

public class WaitTests extends BaseTests {

@Test
public void testWaitUntilHidden(){
var loadingPage = homePage.clickDynamicLoading().clickExample1();
loadingPage.clickStart();
assertEquals(loadingPage.getLoadedText(), "Hello World!", "Loaded text incorrect");
}
}

0 comments on commit 9f83c37

Please sign in to comment.