无法在CircleCI上本地安装Selenium

时间:2018-08-18 23:12:54

标签: java maven selenium circleci circleci-2.0

我想在应用程序中使用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是用于控制的处理语言核心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]将/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
    [INFO]将/tmp/mvninstall8216458170018038185.pom安装到/home/circleci/.m2/repository/com/openqa/selenium/3.14.0/selenium-3.14.0.pom
    [INFO] ----------------------------------------------- -------------------------
    [INFO]建立成功
    [INFO] ----------------------------------------------- -------------------------
    [INFO]总时间:1.993 s
    [INFO]结束于:2018-08-18T23:00:14Z
    [INFO] ----------------------------------------------- -------------------------

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

    [INFO]
    [INFO] --------------------------------------------
    [INFO]构建小众搜索器1.0-SNAPSHOT
    [INFO] -------------------------------- [jar] ------------ ---------------------
    [INFO]
    [INFO] --- maven-install-plugin:2.4:install-file(default-cli)@ niche-finder ---
    [INFO]将/home/circleci/repo/lib/core.jar安装到/home/circleci/.m2/repository/processing/core/3.3.7/core-3.3.7.jar
    [INFO]将/tmp/mvninstall6601326226754451883.pom安装到/home/circleci/.m2/repository/processing/core/3.3.7/core-3.3.7.pom
    [INFO] ----------------------------------------------- -------------------------
    [INFO]建立成功
    [INFO] ----------------------------------------------- -------------------------
    [INFO]总时间:0.472 s
    [INFO]结束于: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中的依赖关系,而不是实际上在CircleCI上运行Selenium服务器。

1 个答案:

答案 0 :(得分:0)

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

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

然后一切正常。