diff --git a/webdriver_java/src/main/java/pages/DynamicLoadingExample1Page.java b/webdriver_java/src/main/java/pages/DynamicLoadingExample1Page.java new file mode 100644 index 0000000..563ac36 --- /dev/null +++ b/webdriver_java/src/main/java/pages/DynamicLoadingExample1Page.java @@ -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(); + } +} diff --git a/webdriver_java/src/main/java/pages/DynamicLoadingPage.java b/webdriver_java/src/main/java/pages/DynamicLoadingPage.java new file mode 100644 index 0000000..ecad08e --- /dev/null +++ b/webdriver_java/src/main/java/pages/DynamicLoadingPage.java @@ -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); + } +} diff --git a/webdriver_java/src/main/java/pages/HomePage.java b/webdriver_java/src/main/java/pages/HomePage.java index 8bbfadf..50244fc 100644 --- a/webdriver_java/src/main/java/pages/HomePage.java +++ b/webdriver_java/src/main/java/pages/HomePage.java @@ -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(); } diff --git a/webdriver_java/src/test/java/base/BaseTests.java b/webdriver_java/src/test/java/base/BaseTests.java index c36835b..c8f9fe9 100644 --- a/webdriver_java/src/test/java/base/BaseTests.java +++ b/webdriver_java/src/test/java/base/BaseTests.java @@ -7,6 +7,9 @@ import org.testng.annotations.BeforeMethod; import pages.HomePage; +import java.util.concurrent.TimeUnit; + + public class BaseTests { private WebDriver driver; @@ -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(); } diff --git a/webdriver_java/src/test/java/wait/WaitTests.java b/webdriver_java/src/test/java/wait/WaitTests.java new file mode 100644 index 0000000..20cdc2f --- /dev/null +++ b/webdriver_java/src/test/java/wait/WaitTests.java @@ -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"); + } +}