Skip to content

Commit

Permalink
Resolve WebDriverWait deprecation warnings (#7526)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbruning committed Aug 31, 2019
1 parent a03a556 commit 1addebd
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.util.List;

public class CorrectEventFiringTest extends JUnit4TestBase {
Expand Down Expand Up @@ -547,7 +548,8 @@ private static void clickOnElementWhichRecordsEvents(WebDriver driver) {
private static void assertEventFired(String eventName, WebDriver driver) {
WebElement result = driver.findElement(By.id("result"));

String text = new WebDriverWait(driver, 10).until(elementTextToContain(result, eventName));
String text = new WebDriverWait(driver, Duration.ofSeconds(10))
.until(elementTextToContain(result, eventName));
boolean conditionMet = text.contains(eventName);

assertThat(conditionMet).as("%s fired with text %s", eventName, text).isTrue();
Expand Down
3 changes: 2 additions & 1 deletion java/client/test/org/openqa/selenium/ImplicitWaitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.openqa.selenium.testing.NeedsLocalEnvironment;
import org.openqa.selenium.testing.NotYetImplemented;

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

@NeedsLocalEnvironment(reason =
Expand Down Expand Up @@ -145,7 +146,7 @@ public void testShouldRetainImplicitlyWaitFromTheReturnedWebDriverOfFrameSwitchT
driver.get(pages.xhtmlTestPage);
driver.findElement(By.name("windowOne")).click();

Wait<WebDriver> wait = new WebDriverWait(driver, 1);
Wait<WebDriver> wait = new WebDriverWait(driver, Duration.ofSeconds(1));
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
String handle = (String)driver.getWindowHandles().toArray()[1];

Expand Down
3 changes: 2 additions & 1 deletion java/client/test/org/openqa/selenium/PageLoadingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.openqa.selenium.testing.NotYetImplemented;
import org.openqa.selenium.testing.SwitchToTopAfterTest;

import java.time.Duration;
import java.util.Set;

public class PageLoadingTest extends JUnit4TestBase {
Expand Down Expand Up @@ -461,7 +462,7 @@ public void testShouldNotStopLoadingPageAfterTimeout() {
driver.manage().timeouts().pageLoadTimeout(300, SECONDS);
}

new WebDriverWait(driver, 30)
new WebDriverWait(driver, Duration.ofSeconds(30))
.ignoring(StaleElementReferenceException.class)
.until(elementTextToEqual(By.tagName("body"), "Slept for 11s"));
}
Expand Down
3 changes: 2 additions & 1 deletion java/client/test/org/openqa/selenium/ReferrerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import java.net.URL;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -330,7 +331,7 @@ public void navigationWhenProxyInterceptsASpecificUrl() {
}

private void performNavigation(WebDriver driver, String firstUrl) {
WebDriverWait wait = new WebDriverWait(driver, 5);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));

driver.get(firstUrl);
wait.until(titleIs("Page 1"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.openqa.selenium.testing.NeedsLocalEnvironment;
import org.openqa.selenium.testing.NoDriverBeforeTest;

import java.time.Duration;

@NeedsLocalEnvironment(reason = "Requires local browser launching environment")
@Ignore(value = SAFARI, reason = "Does not support alerts yet")
public class UnexpectedAlertBehaviorTest extends JUnit4TestBase {
Expand Down Expand Up @@ -109,8 +111,10 @@ private void runScenarioWithUnhandledAlert(
driver.findElement(By.id("prompt-with-default")).click();

Wait<WebDriver> wait1
= silently ? wait
: new WebDriverWait(driver, 10).ignoring(UnhandledAlertException.class);
= silently
? wait
: new WebDriverWait(driver, Duration.ofSeconds(10))
.ignoring(UnhandledAlertException.class);
wait1.until(elementTextToEqual(By.id("text"), expectedAlertText));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

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

public class ChromeOptionsFunctionalTest extends JUnit4TestBase {
Expand Down Expand Up @@ -92,10 +93,10 @@ public void canAddExtensionFromFile() {
driver.get(pages.clicksPage);

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

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

@NeedsLocalEnvironment
Expand All @@ -109,10 +110,10 @@ public void canAddExtensionFromStringEncodedInBase64() throws IOException {
driver.get(pages.clicksPage);

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.time.Duration;
import java.util.stream.StreamSupport;

public abstract class AppServerTestBase {
Expand Down Expand Up @@ -135,7 +136,7 @@ public void uploadsFile() throws Throwable {
Thread.sleep(50);

driver.switchTo().frame("upload_target");
new WebDriverWait(driver, 10).until(
new WebDriverWait(driver, Duration.ofSeconds(10)).until(
d -> d.findElement(By.xpath("//body")).getText().equals(FILE_CONTENTS));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.openqa.selenium.testing.drivers.Browser;
import org.openqa.selenium.testing.drivers.WebDriverBuilder;

import java.time.Duration;
import java.util.logging.Logger;
import java.util.stream.Stream;

Expand Down Expand Up @@ -196,15 +197,15 @@ private void createDriver() {
System.out.println("CREATING DRIVER");
driver = actuallyCreateDriver();
System.out.println("CREATED " + driver);
wait = new WebDriverWait(driver, 10);
shortWait = new WebDriverWait(driver, 5);
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
shortWait = new WebDriverWait(driver, Duration.ofSeconds(5));
}

public void createNewDriver(Capabilities capabilities) {
removeDriver();
driver = actuallyCreateDriver(capabilities);
wait = new WebDriverWait(driver, 10);
shortWait = new WebDriverWait(driver, 5);
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
shortWait = new WebDriverWait(driver, Duration.ofSeconds(5));
}

private static WebDriver actuallyCreateDriver() {
Expand Down

0 comments on commit 1addebd

Please sign in to comment.