Skip to content

Commit

Permalink
[java] Stop using deprecated WebDriverWait constructors in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Oct 1, 2019
1 parent 318c819 commit 26a6315
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Clock;
import java.time.Duration;
import java.util.Collection;

/**
Expand Down Expand Up @@ -141,10 +142,10 @@ public void waitFor(final Finder<WebElement, WebDriver> finder, final long timeo
Wait<WebDriver> wait =
new WebDriverWait(
driver,
Duration.ofMillis(timeoutMillis),
Duration.ofMillis(sleepTimeout),
clock,
sleeper,
millisToSeconds(timeoutMillis),
sleepTimeout) {
sleeper) {
@Override
protected RuntimeException timeoutException(String message, Throwable lastException) {
throw new AssertionError("Element was not rendered within " + timeoutMillis + "ms");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.io.IOException;
import java.nio.file.Files;
import java.time.Duration;
import java.util.Base64;

public class EdgeOptionsFunctionalTest extends JUnit4TestBase {
Expand Down Expand Up @@ -91,10 +92,10 @@ public void canAddExtensionFromFile() {
edgeDriver.get(pages.clicksPage);

edgeDriver.findElement(By.id("normal")).click();
new WebDriverWait(edgeDriver, 10).until(titleIs("XHTML Test Page"));
new WebDriverWait(edgeDriver, Duration.ofSeconds(10)).until(titleIs("XHTML Test Page"));

edgeDriver.findElement(By.tagName("body")).sendKeys(Keys.BACK_SPACE);
new WebDriverWait(edgeDriver, 10).until(titleIs("clicks"));
new WebDriverWait(edgeDriver, Duration.ofSeconds(10)).until(titleIs("clicks"));
}

@Test
Expand All @@ -108,10 +109,10 @@ public void canAddExtensionFromStringEncodedInBase64() throws IOException {
edgeDriver.get(pages.clicksPage);

edgeDriver.findElement(By.id("normal")).click();
new WebDriverWait(edgeDriver, 10).until(titleIs("XHTML Test Page"));
new WebDriverWait(edgeDriver, Duration.ofSeconds(10)).until(titleIs("XHTML Test Page"));

edgeDriver.findElement(By.tagName("body")).sendKeys(Keys.BACK_SPACE);
new WebDriverWait(edgeDriver, 10).until(titleIs("clicks"));
new WebDriverWait(edgeDriver, Duration.ofSeconds(10)).until(titleIs("clicks"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -259,7 +260,7 @@ public void aNewProfileShouldAllowSettingAdditionalParameters() {
profile.setPreference("browser.startup.homepage", pages.formPage);

localDriver = new FirefoxDriver(new FirefoxOptions().setProfile(profile));
new WebDriverWait(localDriver, 30).until(titleIs("We Leave From Here"));
new WebDriverWait(localDriver, Duration.ofSeconds(30)).until(titleIs("We Leave From Here"));
String title = localDriver.getTitle();

assertThat(title).isEqualTo("We Leave From Here");
Expand Down Expand Up @@ -337,7 +338,7 @@ public void shouldAllowUserToSuccessfullyOverrideTheHomePage() {
profile.setPreference("browser.startup.homepage", pages.javascriptPage);

localDriver = new FirefoxDriver(new FirefoxOptions().setProfile(profile));
new WebDriverWait(localDriver, 30).until(urlToBe(pages.javascriptPage));
new WebDriverWait(localDriver, Duration.ofSeconds(30)).until(urlToBe(pages.javascriptPage));
}

private ExpectedCondition<Boolean> urlToBe(final String expectedUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;
import java.util.List;

public class PageFactoryTest {
Expand Down Expand Up @@ -168,7 +169,7 @@ public void shouldNotThrowANoSuchElementExceptionWhenUsedWithAFluentWait() {
when(driver.findElement(ArgumentMatchers.any())).thenThrow(new NoSuchElementException("because"));

TickingClock clock = new TickingClock();
Wait<WebDriver> wait = new WebDriverWait(driver, clock, clock, 1, 1001);
Wait<WebDriver> wait = new WebDriverWait(driver, Duration.ofSeconds(1), Duration.ofMillis(1001), clock, clock);

PublicPage page = new PublicPage();
PageFactory.initElements(driver, page);
Expand Down

0 comments on commit 26a6315

Please sign in to comment.