Compare commits
2 Commits
5cab207685
...
98089e8d14
| Author | SHA1 | Date | |
|---|---|---|---|
| 98089e8d14 | |||
| 81b1446e36 |
@@ -23,13 +23,14 @@
|
||||
|
||||
<!-- Dependencies -->
|
||||
<selenium.version>4.41.0</selenium.version>
|
||||
<junit.version>6.0.2</junit.version>
|
||||
<junit.version>5.10.3</junit.version>
|
||||
<webdrivermanager.version>6.3.3</webdrivermanager.version>
|
||||
<guice.version>7.0.0</guice.version>
|
||||
<jsoup.version>1.22.1</jsoup.version>
|
||||
<slf4j.version>2.0.17</slf4j.version>
|
||||
<logback.version>1.5.32</logback.version>
|
||||
<guava.version>33.5.0-jre</guava.version>
|
||||
<allure.version>2.29.1</allure.version>
|
||||
|
||||
<!-- Plugins -->
|
||||
<maven.compiler.version>3.15.0</maven.compiler.version>
|
||||
@@ -63,6 +64,12 @@
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.qameta.allure</groupId>
|
||||
<artifactId>allure-junit5</artifactId>
|
||||
<version>${allure.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Guice -->
|
||||
<dependency>
|
||||
|
||||
@@ -11,6 +11,10 @@ public class ChromeDriverFactory implements DriverFactory {
|
||||
final ChromeOptions options = new ChromeOptions();
|
||||
options.addArguments("--start-maximized");
|
||||
options.addArguments("--disable-notifications");
|
||||
final String binaryPath = System.getProperty("chrome.binary", "");
|
||||
if (!binaryPath.isBlank()) {
|
||||
options.setBinary(binaryPath);
|
||||
}
|
||||
final boolean headless =
|
||||
Boolean.parseBoolean(System.getProperty("selenide.headless", "false"));
|
||||
if (headless) {
|
||||
|
||||
@@ -8,6 +8,12 @@ import io.github.bonigarcia.wdm.WebDriverManager;
|
||||
import ru.kovbasa.config.TestConfig;
|
||||
import ru.kovbasa.listeners.HighlightElementListener;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class WebDriverProvider {
|
||||
|
||||
private WebDriver driver;
|
||||
@@ -27,8 +33,13 @@ public final class WebDriverProvider {
|
||||
|
||||
private WebDriver createDecoratedDriver() {
|
||||
if (!TestConfig.isSelenoidMode()) {
|
||||
final String chromeVersion = detectChromeMajorVersion().orElse(null);
|
||||
if (chromeVersion != null) {
|
||||
WebDriverManager.chromedriver().browserVersion(chromeVersion).setup();
|
||||
} else {
|
||||
WebDriverManager.chromedriver().setup();
|
||||
}
|
||||
}
|
||||
final WebDriver raw = driverFactory.createDriver();
|
||||
return new EventFiringDecorator(new HighlightElementListener())
|
||||
.decorate(raw);
|
||||
@@ -40,4 +51,45 @@ public final class WebDriverProvider {
|
||||
driver = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<String> detectChromeMajorVersion() {
|
||||
final String os = System.getProperty("os.name", "").toLowerCase();
|
||||
if (!os.contains("linux")) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
final String[] commands = new String[] {
|
||||
"chromium --version",
|
||||
"chromium-browser --version",
|
||||
"google-chrome --version"
|
||||
};
|
||||
for (String cmd : commands) {
|
||||
final Optional<String> version = runVersionCommand(cmd);
|
||||
if (version.isPresent()) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private Optional<String> runVersionCommand(String command) {
|
||||
try {
|
||||
final Process process = new ProcessBuilder("sh", "-c", command)
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
|
||||
final String output = reader.readLine();
|
||||
if (output == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
final Matcher matcher = Pattern.compile("(\\d+)\\.").matcher(output);
|
||||
if (matcher.find()) {
|
||||
return Optional.of(matcher.group(1));
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// Best-effort detection only.
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user