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

test: Use WebDriverManager to manage chromedriver (#12897) (CP: 2.8) (#13801) (CP: 2.7) #13866

Merged
merged 1 commit into from
May 26, 2022
Merged
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
35 changes: 35 additions & 0 deletions flow-test-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,41 @@
<artifactId>vaadin-testbench-core</artifactId>
<version>${testbench.version}</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.1.1</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpg-jdk15on</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.databind.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>

<!-- override scope for junit -->
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,94 +16,47 @@

package com.vaadin.flow.testutil;

import java.io.IOException;
import java.io.File;
import java.io.UncheckedIOException;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.stream.Collectors;

import io.github.bonigarcia.wdm.WebDriverManager;

/**
* Locates chromedriver binary in the project and sets its valu
* Locates a chromedriver binary.
*
* @author Vaadin Ltd
* @since 1.0.
*/
final class ChromeDriverLocator {
private static final String WEBDRIVER_CHROME_DRIVER = "webdriver.chrome.driver";
private static final String CHROMEDRIVER_NAME_PART = "chromedriver";
// examples: driver\windows\googlechrome\64bit\chromedriver.exe
private static final int MAX_DRIVER_SEARCH_DEPTH = 4;

private ChromeDriverLocator() {}
private ChromeDriverLocator() {
}

/**
* Fills {@link ChromeDriverLocator#WEBDRIVER_CHROME_DRIVER} system property
* with chromedriver path, does not override already existing value.
*
* @throws UncheckedIOException
* on io exceptions of the
* {@link Files#find(Path, int, BiPredicate, FileVisitOption...)}
* method
*/
static void fillEnvironmentProperty() {
if (System.getProperty(WEBDRIVER_CHROME_DRIVER) == null) {
Optional.ofNullable(getDriverLocation())
.ifPresent(driverLocation -> System.setProperty(
WEBDRIVER_CHROME_DRIVER, driverLocation));
}
}

private static String getDriverLocation() {
Path driverDirectory = Paths.get("../../driver/");
if (!driverDirectory.toFile().isDirectory()) {
System.out.println(String.format(
"Could not find driver directory: %s", driverDirectory));
return null;
}

List<Path> driverPaths = getDriverPaths(driverDirectory);

if (driverPaths.isEmpty()) {
System.out.println("No " + CHROMEDRIVER_NAME_PART + " found at \""
+ driverDirectory.toAbsolutePath() + "\"\n"
+ " Verify that the path is correct and that driver-binary-downloader-maven-plugin has been run at least once.");
return null;
if (AbstractTestBenchTest.USE_HUB) {
return;
}

if (driverPaths.size() > 1) {
System.out.println(String.format(
"Have found multiple driver paths, using the first one from the list: %s",
driverPaths));
String chromedriverProperty = System
.getProperty(WEBDRIVER_CHROME_DRIVER);
if (chromedriverProperty == null
|| !new File(chromedriverProperty).exists()) {
// This sets the same property
WebDriverManager.chromedriver().setup();
} else {
System.out
.println("Using chromedriver from " + chromedriverProperty);
}
return driverPaths.get(0).toAbsolutePath().toString();

}

private static List<Path> getDriverPaths(Path driverDirectory) {
List<Path> driverPaths;
try {
driverPaths = Files
.find(driverDirectory, MAX_DRIVER_SEARCH_DEPTH,
ChromeDriverLocator::isChromeDriver)
.collect(Collectors.toList());
} catch (IOException e) {
throw new UncheckedIOException("Error trying to locate "
+ CHROMEDRIVER_NAME_PART + " binary", e);
}
return driverPaths;
}

private static boolean isChromeDriver(Path path,
BasicFileAttributes attributes) {
return attributes.isRegularFile()
&& path.toString().toLowerCase(Locale.getDefault())
.contains(CHROMEDRIVER_NAME_PART);
}
}
32 changes: 0 additions & 32 deletions flow-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,38 +158,6 @@
</filesets>
</configuration>
</plugin>
<!--This plugin's configuration is used to store Eclipse
m2e settings only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
com.lazerycode.selenium
</groupId>
<artifactId>
driver-binary-downloader-maven-plugin
</artifactId>
<versionRange>
[${driver.binary.downloader.maven.plugin.version},)
</versionRange>
<goals>
<goal>selenium</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand Down
31 changes: 0 additions & 31 deletions flow-tests/servlet-containers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,37 +105,6 @@
<module>felix-jetty</module>
</modules>
</profile>
<profile>
<id>local-run</id>
<activation>
<property>
<name>!test.use.hub</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>${driver.binary.downloader.maven.plugin.version}</version>
<configuration>
<onlyGetDriversForHostOperatingSystem>true</onlyGetDriversForHostOperatingSystem>
<rootStandaloneServerDirectory>${project.rootdir}/driver</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>${project.rootdir}/driver_zips</downloadedZipFileDirectory>
<customRepositoryMap>${project.rootdir}/drivers.xml</customRepositoryMap>
</configuration>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>test-application-theme</artifactId>
<groupId>com.vaadin</groupId>
Expand Down Expand Up @@ -63,38 +61,4 @@
</plugins>
</build>

<profiles>
<profile>
<id>local-run</id>
<activation>
<property>
<name>!test.use.hub</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>${driver.binary.downloader.maven.plugin.version}</version>
<configuration>
<onlyGetDriversForHostOperatingSystem>true</onlyGetDriversForHostOperatingSystem>
<rootStandaloneServerDirectory>${project.rootdir}/driver</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>${project.rootdir}/driver_zips</downloadedZipFileDirectory>
<customRepositoryMap>${project.rootdir}/drivers.xml</customRepositoryMap>
</configuration>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>test-application-theme</artifactId>
<groupId>com.vaadin</groupId>
Expand Down Expand Up @@ -86,37 +84,4 @@
</plugins>
</build>

<profiles>
<profile>
<id>local-run</id>
<activation>
<property>
<name>!test.use.hub</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>${driver.binary.downloader.maven.plugin.version}</version>
<configuration>
<onlyGetDriversForHostOperatingSystem>true</onlyGetDriversForHostOperatingSystem>
<rootStandaloneServerDirectory>${project.rootdir}/driver</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>${project.rootdir}/driver_zips</downloadedZipFileDirectory>
<customRepositoryMap>${project.rootdir}/drivers.xml</customRepositoryMap>
</configuration>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
37 changes: 1 addition & 36 deletions flow-tests/test-application-theme/test-theme-live-reload/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>test-application-theme</artifactId>
<groupId>com.vaadin</groupId>
Expand Down Expand Up @@ -80,37 +78,4 @@
</plugins>
</build>

<profiles>
<profile>
<id>local-run</id>
<activation>
<property>
<name>!test.use.hub</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>${driver.binary.downloader.maven.plugin.version}</version>
<configuration>
<onlyGetDriversForHostOperatingSystem>true</onlyGetDriversForHostOperatingSystem>
<rootStandaloneServerDirectory>${project.rootdir}/driver</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>${project.rootdir}/driver_zips</downloadedZipFileDirectory>
<customRepositoryMap>${project.rootdir}/drivers.xml</customRepositoryMap>
</configuration>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Loading