【问题标题】:Can't install Selenium locally on CircleCI无法在 CircleCI 上本地安装 Selenium
【发布时间】:2018-08-18 23:12:54
【问题描述】:

我想在应用程序中使用 Selenium,但在使用 CircleCI 时遇到了一些问题。

我在 lib/ 文件夹中有 3 个 jar 文件:client-combined-3.14.0.jar、htmlunit-driver-2.32.1-jar-with-dependencies.jar 和 core.jar。

前 2 个 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 存储库下载的一堆):

[信息] 将 /home/circleci/repo/lib/client-combined-3.14.0.jar 安装到 /home/circleci/.m2/repository/com/openqa/selenium/3.14.0/selenium-3.14.0.jar
[信息] 安装 /tmp/mvninstall8216458170018038185.pom 到 /home/circleci/.m2/repository/com/openqa/selenium/3.14.0/selenium-3.14.0.pom
[信息] --------------------------------------------- -------------------------
[信息] 构建成功
[信息] --------------------------------------------- -------------------------
[INFO] 总时间:1.993 秒
[INFO] 完成于:2018-08-18T23:00:14Z
[信息] --------------------------------------------- -------------------------

这是安装受控处理jar时消息的一部分:

[信息]
[信息] --------------------------------------------------------
[INFO] 建立利基-finder 1.0-SNAPSHOT
[信息] --------------------------------[ 罐子 ]------------ ---------------------
[信息]
[信息] --- maven-install-plugin:2.4:install-file (default-cli) @niche-finder ---
[信息] 将 /home/circleci/repo/lib/core.jar 安装到 /home/circleci/.m2/repository/processing/core/3.3.7/core-3.3.7.jar
[信息] 安装 /tmp/mvninstall6601326226754451883.pom 到 /home/circleci/.m2/repository/processing/core/3.3.7/core-3.3.7.pom
[信息] --------------------------------------------- -------------------------
[信息] 构建成功
[信息] --------------------------------------------- -------------------------
[INFO] 总时间:0.472 秒
[INFO] 完成于:2018-08-18T23:00:18Z
[信息] --------------------------------------------- -------------------------

但是,当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 服务器。

【问题讨论】:

  • mvn install 三个命令中是否有任何有用的控制台输出?那里有什么错误吗?
  • 只搜索mvnrepository.com 我希望失败的依赖可能不是最新的或不正确的
  • mvn install 命令看起来不错。

标签: java maven selenium circleci circleci-2.0


【解决方案1】:

我尝试不依赖从https://www.seleniumhq.org/ 下载的jar 文件,而是直接使用来自https://mvnrepository.com/artifact/org.seleniumhq.selenium 的maven 存储库thisthis 的存储库

那我就不完全安装本地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>

然后一切都构建得很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-20
    • 2020-09-24
    • 2021-04-12
    • 1970-01-01
    • 2013-09-17
    • 1970-01-01
    • 2019-10-27
    相关资源
    最近更新 更多