Skip to content

Commit

Permalink
Use Selenium 4 in tests
Browse files Browse the repository at this point in the history
Update Selenium and Selenium Jupiter to latest versions.
Update code for the newer versions, address deprecations mainly.

Signed-off-by: thc202 <thc202@gmail.com>
  • Loading branch information
thc202 committed Jan 19, 2023
1 parent 3a69d45 commit 9bc62e6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-params:$jupiterVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion")

testImplementation("io.github.bonigarcia:selenium-jupiter:3.4.0")
testImplementation("io.github.bonigarcia:selenium-jupiter:4.3.2")
testImplementation("org.seleniumhq.selenium:selenium-java:4.7.2")
testImplementation("org.hamcrest:hamcrest-all:1.3")
testImplementation("org.mockito:mockito-all:1.10.19")
testImplementation("org.zaproxy.addon:network:0.1.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import io.github.bonigarcia.seljup.BrowserBuilder;
import io.github.bonigarcia.seljup.Options;
import io.github.bonigarcia.seljup.SeleniumExtension;
import io.github.bonigarcia.seljup.SeleniumJupiter;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
Expand Down Expand Up @@ -53,19 +53,21 @@ public abstract class BrowsersTest {

@Options
private static final ChromeOptions CHROME_OPTIONS =
new ChromeOptions()
.setHeadless(true)
.setAcceptInsecureCerts(true)
.addArguments("--proxy-bypass-list=<-loopback>", "--window-size=1024,768")
.setProxy(PROXY);
(ChromeOptions)
new ChromeOptions()
.setHeadless(true)
.setAcceptInsecureCerts(true)
.addArguments(
"--proxy-bypass-list=<-loopback>", "--window-size=1024,768")
.setProxy(PROXY);

@RegisterExtension SeleniumExtension seleniumExtension = new SeleniumExtension();
@RegisterExtension SeleniumJupiter seleniumJupiter = new SeleniumJupiter();

@BeforeAll
void setup() {
seleniumExtension.addBrowsers(BrowserBuilder.firefox().build());
seleniumJupiter.addBrowsers(BrowserBuilder.firefox().build());
// TODO uncomment once the tests are more reliable
// https://github.com/zaproxy/zap-hud/issues/344
// seleniumExtension.addBrowsers(BrowserBuilder.chrome().build());
// seleniumJupiter.addBrowsers(BrowserBuilder.chrome().build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
Expand Down Expand Up @@ -156,7 +158,7 @@ public void cannotUseZapApiFromTarget(WebDriver driver)
}

private static Object executeScriptWithRetry(WebDriver driver, String script) {
return new WebDriverWait(driver, 10L)
return new WebDriverWait(driver, Duration.of(10, ChronoUnit.SECONDS))
.ignoring(JavascriptException.class)
.until(wd -> ((JavascriptExecutor) wd).executeScript(script));
}
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/org/zaproxy/zap/extension/hud/ui/uimap/HUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.openqa.selenium.By;
Expand All @@ -52,7 +53,7 @@ public class HUD {

public HUD(WebDriver webdriver) {
this.webdriver = webdriver;
this.webdriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
this.webdriver.manage().timeouts().pageLoadTimeout(Duration.of(30, ChronoUnit.SECONDS));
}

public static String LEFT_PANEL_ID = "zap-hud-left-panel";
Expand Down Expand Up @@ -82,7 +83,7 @@ public WebElement getLeftPanel() {
}

public WebDriverWait wbWait() {
return new WebDriverWait(webdriver, 20);
return new WebDriverWait(webdriver, Duration.of(20, ChronoUnit.SECONDS));
}

public WebElement waitForElement(By by) {
Expand Down Expand Up @@ -187,7 +188,7 @@ public void openRelativePage(String page) throws URISyntaxException {
}

public void waitForPageLoad() {
Wait<WebDriver> wait = new WebDriverWait(webdriver, 30);
Wait<WebDriver> wait = new WebDriverWait(webdriver, Duration.of(30, ChronoUnit.SECONDS));
wait.until(HUD::documentReadyStateIsComplete);
}

Expand Down Expand Up @@ -236,7 +237,7 @@ public void log(String msg) {

private static ExpectedCondition<List<WebElement>> numberOfElementsToBeAtLeast(
By locator, int number) {
return new ExpectedCondition<List<WebElement>>() {
return new ExpectedCondition<>() {
private int currentNumber = 0;

@Override
Expand Down

0 comments on commit 9bc62e6

Please sign in to comment.