【问题标题】:Jenkins cannot find the external Jars added for the selenium project through EclipseJenkins 找不到通过 Eclipse 为 selenium 项目添加的外部 Jars
【发布时间】:2017-02-26 04:43:09
【问题描述】:

我在 Eclipse 中有一个 Maven 项目。我的项目是自动化测试。所以在我的 pom.xml 中,我添加了所有依赖项。

例如:Testng、Cucumber、Selenium-java 等。

我已经安装了 Jenkins 并使用 Jenkins 配置了我的自动化项目,因此当使用 Jenkins 执行时,该项目将被执行。

我已将所有依赖项添加到我的 pom.xml 中,因此没有问题。但是现在当我在 Eclipse 中外部添加 jar 文件时,Jenkins 无法识别它,因此脚本没有被执行。

这是我的测试用例:

package com.giveback360.tests.sampletest;

import org.openqa.selenium.WebDriver;
import com.giveback360.utils.OpenBrowserHelp;
import cucumber.api.java.en.When;
import org.openqa.selenium.firefox.FirefoxDriver;
import atu.testrecorder.ATUTestRecorder;
import atu.testrecorder.exceptions.ATUTestRecorderException;

public class SampleTest {

/**
* Initialize the webdriver.
*/
 private WebDriver driver = new FirefoxDriver();

/**
 * Initialize recorder.
 */
 ATUTestRecorder recorder;

 /**
 * Open browser.
 * @throws InterruptedException the InterruptedException.
 */
 @When("Open browser maximize")
  public void browserOpen() throws InterruptedException, ATUTestRecorderException {

 recorder = new ATUTestRecorder("/home/username/workspace/project/scriptVideos","TestVideo",false);
 recorder.start();

 driver.get("http://www.google.com");
 Thread.sleep(4000);
 driver.quit();

 recorder.stop();

 }

}

我在 Jenkins 中的控制台输出是:

java.lang.NoClassDefFoundError: atu/testrecorder/exceptions/ATUTestRecorderException
Caused by: java.lang.ClassNotFoundException: atu.testrecorder.exceptions.ATUTestRecorderException


Results :

Failed tests: 
 SampleTest>AbstractTestNGCucumberTests.setUpClass:16 » NoClassDefFound atu/tes...

Tests run: 3, Failures: 1, Errors: 0, Skipped: 2

[ERROR] There are test failures.

问题是因为我在 Eclipse 中为此项目添加了 ATUTestRecorder jar 文件。

问题是如何指示 Jenkins 找到那些 JAR 文件?我应该在 Jenkins 中配置还是应该如何配置?

非常感谢任何帮助。提前致谢。

【问题讨论】:

    标签: java eclipse maven selenium jenkins


    【解决方案1】:

    您只使用 eclipse 构建路径设置了一个 jar,因此它只能用于 eclipse

    在使用 Jenkins 时,您只需设置一个 maven 项目,因此 Jenkins 试图从 POM.xml 中找到它所需的依赖项。它无法找到来自 eclipse 构建路径的 jar。

    您必须找到该特定 jar 的 maven 声明,并且必须放入 POM.XML

    或者您可以使用以下命令在 maven 中添加 3rd 方 jar

    mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
    -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
    

    Find more information about adding 3rd party jar from here

    【讨论】:

      【解决方案2】:

      将第 3 方库放在项目的 lib 文件夹中。然后使用 &lt;scope&gt;system&lt;/scope&gt; 将它们添加到 maven 中

      <dependencies>
        <dependency>
          <groupId>com.example</groupId>
          <artifactId>mylib</artifactId>
          <version>1.0</version>
          <scope>system</scope>
          <systemPath>${basedir}/lib/mylib.jar</systemPath>
        </dependency>
      </dependencies>
      

      【讨论】:

        猜你喜欢
        • 2018-03-10
        • 1970-01-01
        • 1970-01-01
        • 2012-01-22
        • 2012-03-14
        • 2013-08-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多