Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BqvAC2FK] Update selenium dependencies (#3663) #3754

Draft
wants to merge 4 commits into
base: 4.4
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions extra-dependencies/selenium/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ jar {
}
}

def commonExclusions = {
exclude group: 'org.slf4j'
exclude group: 'org.apache.commons', module: 'commons-compress'
exclude group: 'org.apache.commons', module: 'commons-lang3'
exclude group: 'com.google.guava', module: 'guava'
}

dependencies {
// currently we cannot update to the latest version due to guava minimum version required (31.0.1-jre)
implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59', {
exclude group: 'com.google.guava', module: 'guava'
}
implementation group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '4.4.3'
implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.11.0' , commonExclusions
implementation group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.4.1', commonExclusions

}
17 changes: 13 additions & 4 deletions full/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,18 @@ dependencies {
implementation 'org.jsoup:jsoup:1.15.3'

// currently we cannot update selenium to the latest version due to guava minimum version required (31.0.1-jre)
compileOnly group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59', { exclude group: 'com.google.guava', module: 'guava' }
testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59', { exclude group: 'com.google.guava', module: 'guava' }
compileOnly group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.1.0'
testImplementation group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.1.0'
compileOnly group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.11.0', {
exclude group: 'com.google.guava', module: 'guava'
}
testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.11.0', {
exclude group: 'com.google.guava', module: 'guava'
}
compileOnly group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.4.1', {
exclude group: 'com.google.guava', module: 'guava'
}
testImplementation group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.4.1', {
exclude group: 'com.google.guava', module: 'guava'
}

implementation group: 'org.roaringbitmap', name: 'RoaringBitmap', version: '0.7.17'
implementation(group: 'org.apache.commons', name: 'commons-configuration2', version: '2.9.0') {
Expand Down Expand Up @@ -166,6 +174,7 @@ dependencies {
compileOnly group: 'com.sun.mail', name: 'javax.mail', version: '1.6.0'
testImplementation group: 'com.sun.mail', name: 'javax.mail', version: '1.6.0'
testImplementation group: 'org.zapodot', name: 'embedded-ldap-junit', version: '0.9.0'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.4.0'

configurations.all {
exclude group: 'org.slf4j', module: 'slf4j-nop'
Expand Down
2 changes: 1 addition & 1 deletion full/src/main/java/apoc/load/LoadHtml.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private Stream<MapResult> readHtmlPage(
} catch (UnsupportedCharsetException e) {
throw new RuntimeException("Unsupported charset: " + config.getCharset());
} catch (IllegalArgumentException | ClassCastException e) {
throw new RuntimeException("Invalid config: " + config);
throw new RuntimeException("Invalid config: " + e.getMessage());
} catch (FileNotFoundException e) {
throw new RuntimeException("File not found from: " + url);
} catch (Exception e) {
Expand Down
7 changes: 4 additions & 3 deletions full/src/main/java/apoc/load/LoadHtmlBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.openqa.selenium.By;
Expand All @@ -48,7 +49,7 @@ public static InputStream getChromeInputStream(
setupWebDriverManager(WebDriverManager.chromedriver(), config);

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(isHeadless);
chromeOptions.addArguments("--headless=new");
chromeOptions.setAcceptInsecureCerts(isAcceptInsecureCerts);
return getInputStreamWithBrowser(url, query, config, new ChromeDriver(chromeOptions));
}
Expand All @@ -62,7 +63,7 @@ public static InputStream getFirefoxInputStream(
setupWebDriverManager(WebDriverManager.firefoxdriver(), config);

FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setHeadless(isHeadless);
firefoxOptions.addArguments("-headless");
firefoxOptions.setAcceptInsecureCerts(isAcceptInsecureCerts);
return getInputStreamWithBrowser(url, query, config, new FirefoxDriver(firefoxOptions));
}
Expand Down Expand Up @@ -147,7 +148,7 @@ private static InputStream getInputStreamWithBrowser(

final long wait = config.getWait();
if (wait > 0) {
Wait<WebDriver> driverWait = new WebDriverWait(driver, wait);
Wait<WebDriver> driverWait = new WebDriverWait(driver, Duration.ofSeconds(wait));
try {
driverWait.until(webDriver -> query.values().stream()
.noneMatch(selector ->
Expand Down
17 changes: 11 additions & 6 deletions full/src/test/java/apoc/load/LoadHtmlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.junit.After;
import org.junit.Assert;
Expand Down Expand Up @@ -95,7 +96,7 @@ public void teardown() {

@Test
public void testParseGeneratedJs() {
testCallGeneratedJsWithBrowser("CHROME");
testCallGeneratedJsWithBrowser(CHROME);
}

@Test
Expand All @@ -117,7 +118,8 @@ private void assertWrongConfig(String msgError, Map<String, Object> config) {
map("url", URL_HTML_JS, "query", map("a", "a"), "config", config),
r -> fail("Should fails due to wrong configuration"));
} catch (RuntimeException e) {
assertTrue(e.getMessage().contains(msgError));
String message = e.getMessage();
assertTrue("Current message is: " + message, message.contains(msgError));
}
}

Expand Down Expand Up @@ -614,7 +616,7 @@ private void testCallGeneratedJsWithBrowser(String browser) {
"query",
map("td", "td", "strong", "strong"),
"config",
map("browser", browser, "driverVersion", "0.30.0")),
map("browser", browser)),
result -> {
Map<String, Object> value = (Map<String, Object>) result.get("value");
List<Map<String, Object>> tdList = (List<Map<String, Object>>) value.get("td");
Expand All @@ -640,10 +642,13 @@ public static void skipIfBrowserNotPresentOrCompatible(Runnable runnable) {
} catch (RuntimeException e) {
// The test don't fail if the current chrome/firefox version is incompatible or if the browser is not
// installed
Stream<String> notPresentOrIncompatible = Stream.of(
"cannot find Chrome binary",
"Cannot find firefox binary",
"browser start-up failure",
"This version of ChromeDriver only supports Chrome version");
final String msg = e.getMessage();
if (!msg.contains("cannot find Chrome binary")
&& !msg.contains("Cannot find firefox binary")
&& !msg.contains("This version of ChromeDriver only supports Chrome version")) {
if (notPresentOrIncompatible.noneMatch(msg::contains)) {
throw e;
}
}
Expand Down
Loading