无法在 CircleCI 上本地安装 Selenium
Can't install Selenium locally on CircleCI
我想在应用程序中使用 Selenium,但我在使用 CircleCI 时遇到了一些问题。
我在 lib/ 文件夹中有 3 个 jar 文件:client-combined-3.14.0.jar、htmlunit-driver-2.32.1-jar-with-dependencies.jar 和 core.jar .
前两个 jar 用于 Selenium 库,第三个是用于控制的处理语言核心 jar。
这是我的.circleci/config.yml:
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:8-jdk
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4
branches:
only:
- develop
working_directory: ~/repo
environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m
steps:
- checkout
# installing packages
- run: mvn install:install-file -Dfile="lib/client-combined-3.14.0.jar" -DgroupId="com.openqa" -DartifactId="selenium" -Dversion="3.14.0" -Dpackaging=jar -DgeneratePom=true
- run: mvn install:install-file -Dfile="lib/htmlunit-driver-2.32.1-jar-with-dependencies.jar" -DgroupId="com.openqa.selenium" -DartifactId="htmlunit" -Dversion="2.32.1" -Dpackaging=jar -DgeneratePom=true
- run: mvn install:install-file -DgroupId="processing" -DartifactId="core" -Dversion="3.3.7" -Dpackaging=jar -Dfile="lib/core.jar" -DgeneratePom=true
# run tests!
- run: echo "Testing"
- run: mvn test
这是我的 pom.xml:
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.157239n</groupId>
<artifactId>niche-finder</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openqa</groupId>
<artifactId>selenium</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>org.openqa.selenium</groupId>
<artifactId>htmlunit</artifactId>
<version>2.32.1</version>
</dependency>
<dependency>
<groupId>processing</groupId>
<artifactId>core</artifactId>
<version>3.3.7</version>
</dependency>
</dependencies>
</project>
在 CircleCI 上,所有 3 个 jar 都已正确安装。更具体地说,这是 mvn install
为 运行 时的消息部分(上面只是从 maven 存储库下载的一堆):
[INFO] Installing /home/circleci/repo/lib/client-combined-3.14.0.jar to /home/circleci/.m2/repository/com/openqa/selenium/3.14.0/selenium-3.14.0.jar
[INFO] Installing /tmp/mvninstall8216458170018038185.pom to /home/circleci/.m2/repository/com/openqa/selenium/3.14.0/selenium-3.14.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.993 s
[INFO] Finished at: 2018-08-18T23:00:14Z
[INFO] ------------------------------------------------------------------------
这是安装受控处理 jar 时的消息部分:
[INFO]
[INFO] --------------------------------------------
[INFO] Building niche-finder 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ niche-finder ---
[INFO] Installing /home/circleci/repo/lib/core.jar to /home/circleci/.m2/repository/processing/core/3.3.7/core-3.3.7.jar
[INFO] Installing /tmp/mvninstall6601326226754451883.pom to /home/circleci/.m2/repository/processing/core/3.3.7/core-3.3.7.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.472 s
[INFO] Finished at: 2018-08-18T23:00:18Z
[INFO] ------------------------------------------------------------------------
但是,当mvn test
为运行时,出现这个错误:
[ERROR] Failed to execute goal on project niche-finder: Could not resolve dependencies for project com.157239n:niche-finder:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: org.openqa:selenium:jar:3.14.0, org.openqa.selenium:htmlunit:jar:2.32.1: Could not find artifact org.openqa:selenium:jar:3.14.0 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
看来 2 个 selenium jar 没有正确安装,但 Processing jar 安装得很好。
那么这是 Selenium 方面的错误吗?或者我做错了什么?
请注意,目前我只想解决 Selenium 中的依赖关系,而不是 运行在 CircleCI 上安装 Selenium 服务器。
我尽量不依赖从 https://www.seleniumhq.org/ and use the repository directly from this and this from the maven repository at https://mvnrepository.com/artifact/org.seleniumhq.selenium
下载的 jar 文件
那我干脆不安装本地的jar文件,只安装受控的core.jar,把我的pom.xml的一部分改成
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.52.0</version>
</dependency>
然后一切都构建得很好。
我想在应用程序中使用 Selenium,但我在使用 CircleCI 时遇到了一些问题。
我在 lib/ 文件夹中有 3 个 jar 文件:client-combined-3.14.0.jar、htmlunit-driver-2.32.1-jar-with-dependencies.jar 和 core.jar .
前两个 jar 用于 Selenium 库,第三个是用于控制的处理语言核心 jar。
这是我的.circleci/config.yml:
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:8-jdk
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4
branches:
only:
- develop
working_directory: ~/repo
environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m
steps:
- checkout
# installing packages
- run: mvn install:install-file -Dfile="lib/client-combined-3.14.0.jar" -DgroupId="com.openqa" -DartifactId="selenium" -Dversion="3.14.0" -Dpackaging=jar -DgeneratePom=true
- run: mvn install:install-file -Dfile="lib/htmlunit-driver-2.32.1-jar-with-dependencies.jar" -DgroupId="com.openqa.selenium" -DartifactId="htmlunit" -Dversion="2.32.1" -Dpackaging=jar -DgeneratePom=true
- run: mvn install:install-file -DgroupId="processing" -DartifactId="core" -Dversion="3.3.7" -Dpackaging=jar -Dfile="lib/core.jar" -DgeneratePom=true
# run tests!
- run: echo "Testing"
- run: mvn test
这是我的 pom.xml:
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.157239n</groupId>
<artifactId>niche-finder</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openqa</groupId>
<artifactId>selenium</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>org.openqa.selenium</groupId>
<artifactId>htmlunit</artifactId>
<version>2.32.1</version>
</dependency>
<dependency>
<groupId>processing</groupId>
<artifactId>core</artifactId>
<version>3.3.7</version>
</dependency>
</dependencies>
</project>
在 CircleCI 上,所有 3 个 jar 都已正确安装。更具体地说,这是 mvn install
为 运行 时的消息部分(上面只是从 maven 存储库下载的一堆):
[INFO] Installing /home/circleci/repo/lib/client-combined-3.14.0.jar to /home/circleci/.m2/repository/com/openqa/selenium/3.14.0/selenium-3.14.0.jar
[INFO] Installing /tmp/mvninstall8216458170018038185.pom to /home/circleci/.m2/repository/com/openqa/selenium/3.14.0/selenium-3.14.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.993 s
[INFO] Finished at: 2018-08-18T23:00:14Z
[INFO] ------------------------------------------------------------------------
这是安装受控处理 jar 时的消息部分:
[INFO]
[INFO] --------------------------------------------
[INFO] Building niche-finder 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ niche-finder ---
[INFO] Installing /home/circleci/repo/lib/core.jar to /home/circleci/.m2/repository/processing/core/3.3.7/core-3.3.7.jar
[INFO] Installing /tmp/mvninstall6601326226754451883.pom to /home/circleci/.m2/repository/processing/core/3.3.7/core-3.3.7.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.472 s
[INFO] Finished at: 2018-08-18T23:00:18Z
[INFO] ------------------------------------------------------------------------
但是,当mvn test
为运行时,出现这个错误:
[ERROR] Failed to execute goal on project niche-finder: Could not resolve dependencies for project com.157239n:niche-finder:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: org.openqa:selenium:jar:3.14.0, org.openqa.selenium:htmlunit:jar:2.32.1: Could not find artifact org.openqa:selenium:jar:3.14.0 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
看来 2 个 selenium jar 没有正确安装,但 Processing jar 安装得很好。
那么这是 Selenium 方面的错误吗?或者我做错了什么?
请注意,目前我只想解决 Selenium 中的依赖关系,而不是 运行在 CircleCI 上安装 Selenium 服务器。
我尽量不依赖从 https://www.seleniumhq.org/ and use the repository directly from this and this from the maven repository at https://mvnrepository.com/artifact/org.seleniumhq.selenium
下载的 jar 文件那我干脆不安装本地的jar文件,只安装受控的core.jar,把我的pom.xml的一部分改成
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.52.0</version>
</dependency>
然后一切都构建得很好。