【问题标题】:Build failed in JENKINS while trying to execute a automation script (Selenium WebDriver) Maven project尝试执行自动化脚本(Selenium WebDriver)Maven 项目时在 JENKINS 中构建失败
【发布时间】:2015-10-27 03:57:24
【问题描述】:

我创建了一个带有 TestNG 测试用例的 Maven 项目:

这是TestCase的代码

package example;        

import org.testng.annotations.Test;
import org.testng.AssertJUnit;
import org.openqa.selenium.By;      
import org.openqa.selenium.WebDriver;       
import org.openqa.selenium.firefox.FirefoxDriver;       
import org.testng.Assert;       
import org.testng.annotations.Test; 
import org.testng.annotations.BeforeTest;   
import org.testng.annotations.AfterTest;        
public class NewTest {      
    private WebDriver driver;       
    @Test              
    public void testEasy() {    
        driver.get("http://www.guru99.com/selenium-tutorial.html");  
        String title = driver.getTitle();                
        AssertJUnit.assertTrue(title.contains("Free Selenium Tutorials"));       
    }   
    @BeforeTest
    public void beforeTest() {  
        driver = new FirefoxDriver();  
    }       
    @AfterTest
    public void afterTest() {
        driver.quit();          
    }       
}   

这是 pom.xml 的代码

<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>WebdriverTest</groupId>
<artifactId>WebdriverTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
    <source>1.7</source>
    <target>1.7</target>
    </configuration>
    </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <inherited>true</inherited>
            <configuration>
                <suiteXMLFiles>
                    <suiteXMLFile>WebdriverTest/testng.xml</suiteXMLFile>
                </suiteXMLFiles>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.45.0</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.8</version>
        <scope>test</scope>
    </dependency>
</dependencies>
</project>

这里是testng.xml的代码

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test">
   <classes>
     <class name="example.NewTest"/>
   </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

我在 JENKINS 中配置了这个 pom.xml 并创建了一个新的 Maven 项目并尝试执行,但是构建失败了。但是当我在 Eclipse IDE 中将其作为 Maven 测试执行时,构建成功并执行了测试脚本。

在 JENKINS 中,控制台输出是这样说的

T E S T S

结果:

测试运行:0,失败:0,错误:0,跳过:0

等待 Jenkins 完成数据收集 [错误] 无法在项目 WebdriverTest 上执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.19:test (default-test):创建用于分叉的属性文件时出错:没有这样的文件或目录-> [帮助 1 ] [错误] [错误] 要查看错误的完整堆栈跟踪,请使用 -e 开关重新运行 Maven。 [错误] 使用 -X 开关重新运行 Maven 以启用完整的调试日志记录。

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

【问题讨论】:

  • 请提供带有-e 选项的maven 输出。那么WebdriverTest/testng.xml在哪里呢?在项目根文件夹?
  • 如何使用 -e 选项提供 maven 输出?是的。 testng.xml 位于项目根文件夹中。项目名称是 WebdriverTest
  • 改用&lt;suiteXMLFile&gt;testng.xml&lt;/suiteXMLFile&gt;
  • 试过了,但是没用。

标签: java maven jenkins selenium-webdriver testng


【解决方案1】:

1) 尝试以下方法而不是编写 WebdriverTest/testng.xml 给出绝对路径或只给出 testng.xml

2) 为项目文件夹添加权限。

TestNG 创建一个属性文件,在 jenkins 情况下无法这样做,这通常是权限问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    • 2021-07-26
    • 2021-11-15
    • 2013-05-23
    • 2016-12-02
    • 1970-01-01
    相关资源
    最近更新 更多