简体   繁体   English

Jenkins 无法通过 Eclipse 找到为 selenium 项目添加的外部 Jars

[英]Jenkins cannot find the external Jars added for the selenium project through Eclipse

I have a Maven project in Eclipse.我在 Eclipse 中有一个 Maven 项目。 My project is for Automation Testing.我的项目是自动化测试。 So in my pom.xml I've all dependencies added.所以在我的 pom.xml 中,我添加了所有依赖项。

For example: Testng, Cucumber, Selenium-java etc..例如:Testng、Cucumber、Selenium-java 等。

I have installed Jenkins and configured my automation project with Jenkins, so that when executed with Jenkins this project will be executed.我已经安装了 Jenkins 并用 Jenkins 配置了我的自动化项目,这样当用 Jenkins 执行时,这个项目就会被执行。

I have all dependencies added to my pom.xml so no issues was there.我已将所有依赖项添加到我的 pom.xml 中,因此没有问题。 But now when I added the jar files externally in Eclipse, it is not recognized by Jenkins and therefore, script is not executed.但是现在当我在 Eclipse 中外部添加 jar 文件时,Jenkins 无法识别它,因此不会执行脚本。

Here is my test case:这是我的测试用例:

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();

 }

}

My Console output in Jenkins is:我在 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.

The issue is because of ATUTestRecorder jar files I've added in Eclipse for this project.问题是因为我在 Eclipse 中为此项目添加了 ATUTestRecorder jar 文件。

Problem is how to instruct Jenkins to find those JAR files?问题是如何指示 Jenkins 找到那些 JAR 文件? Should I configure it in Jenkins or How should I do it?我应该在 Jenkins 中配置它还是应该怎么做?

Any help is greatly appreciated.任何帮助是极大的赞赏。 Thanks in advance.提前致谢。

You have set up a jar only with the eclipse build path so it only accessible for eclipse您仅使用 eclipse 构建路径设置了一个 jar,因此它只能供 eclipse 访问

while with the Jenkins you only setup a maven project so Jenkins is trying to find it's required dependency from POM.xml.而使用 Jenkins,您只设置了一个 Maven 项目,因此 Jenkins 试图从 POM.xml 中找到它所需的依赖项。 it is not able to find the jar that is from eclipse build path.它无法找到来自 eclipse 构建路径的 jar。

You have to find maven declaration of that particular jar and have to put in POM.XML您必须找到该特定 jar 的 maven 声明,并且必须放入 POM.XML

or you can add 3rd party jar in maven using the following command或者您可以使用以下命令在 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 从此处查找有关添加 3rd 方 jar 的更多信息

Put 3rd party libraries in lib folder of your project.Then add them to maven with <scope>system</scope>将第 3 方库放在项目的lib文件夹中。然后将它们添加到带有<scope>system</scope> 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM