【问题标题】:Getting "testng.xml is not a valid file" error in Jenkins在 Jenkins 中出现“testng.xml 不是有效文件”错误
【发布时间】:2020-04-17 17:40:51
【问题描述】:

尝试从 Jenkins 运行 Selenium/TestNg 测试时出现以下错误。

[错误] 套件文件 /development/apps/config/jenkins/jobs/teste-automatizado/workspace/Juvo/testng.xml 不是有效文件

下面是我的 POM 和 testng.xml 文件。我能够从 Eclipse 和命令行成功启动 testng.xml,但是从 Jenkins 我得到了这个错误。

有什么帮助吗?提前致谢。

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>br.com.aoki</groupId>
  <artifactId>Juvo</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <properties>
        <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
  </properties>

  <build>
  <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
            <encoding>ISO-8859-1</encoding>
        </configuration>

    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M4</version>
        <configuration>
            <suiteXmlFiles>
                <suiteXmlFile>testng.xml</suiteXmlFile>
            </suiteXmlFiles>
        </configuration>        
    </plugin>   
  </plugins>
  </build>

  <dependencies>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.14.3</version>
    </dependency>

    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.10.4</version>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>com.oracle.ojdbc</groupId>
        <artifactId>ojdbc8</artifactId>
        <version>19.3.0.0</version>
    </dependency>

  </dependencies>

</project>

testng.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test">
    <classes>
      <class name="tests.TestCreateAssistTest"/>
    </classes>
  </test>
</suite>

【问题讨论】:

    标签: maven selenium jenkins testng


    【解决方案1】:

    这个问题已经在 stackoverflow 中报告过了。 我猜你的文件 testng.xml 出现在 src/test/resources 中。 错误说

    套件文件 /development/apps/config/jenkins/jobs/teste-automatizado/workspace/Juvo/testng.xml 不是一个有效的文件

    它没有说 Juvo/src/test/resources/testng.xml

    显然不能,因为您将文件放在 src/test/resources 中,但配置说文件是从根目录读取的:

    <suiteXmlFile>testng.xml</suiteXmlFile>
    

    你必须重写配置

    <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
    

    因为它必须匹配文件的真实位置。

    在 Maven 中,路径用于相对于项目根目录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-25
      • 2023-04-01
      • 1970-01-01
      • 2019-06-20
      • 1970-01-01
      • 2019-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多