【问题标题】:Can't run testng.xml in Cucumber-Maven(TestNG)无法在 Cucumber-Maven(TestNG)中运行 testng.xml
【发布时间】:2018-12-28 05:01:16
【问题描述】:

在 Eclipse IDE 中,我使用 Maven 项目创建了一个基本的黄瓜框架。

我已经在 pom.xml 中添加了所有需要的依赖项。对于 TestNG 插件添加在依赖项下面。

 <dependency>       
      <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>              
        <version>6.14.3</version>
        <scope>test</scope>         
</dependency> 
<dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>1.2.5</version>   
 </dependency>

但是“TestNG Suite”选项没有出现在首选项中,所以通过 Help->Install New Software 安装了 TestNG。

框架有特征文件(描述了场景),stepdefinitions(给定的代码/逻辑)和运行器类(用stepdefinitions文件映射特征并运行它)。

跑步者类:

package tests.report.runners;

import cucumber.api.CucumberOptions;


@CucumberOptions(features = "src/test/resources/features",glue= {"tests"},tags= {"@Report"})
public class ReportRunner  {
    }

像这样,每个模块都有一个跑步者课程(端到端场景)

例如:

  • 登录,进入产品页面并退出

  • 登录、生成报告和注销

我正在尝试通过 testng.xml 文件运行这些运行器类

testng.xml 文件

 <?xml version="1.0" encoding="UTF-8"?> 
 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
   <suite name="First Suite" parallel="classes"> 
    <test name="Chrome Test" parallel="classes">
       <classes> 
           <class name ="tests.report.runners.ReportRunner"></class>
       </classes> 
   </test> 
</suite>

但它抛出错误

【问题讨论】:

标签: java maven selenium-webdriver cucumber testng


【解决方案1】:

问题是因为存储在 maven 存储库中的垃圾 jar 不兼容。

请按以下步骤操作

  1. 清理旧属性/maven 依赖项(从你的项目目录打开命令提示符 并运行以下命令)
    • mvn eclipse:clean
    • mvn eclipse:eclipse -Dwtpversion=2.0
  2. 下载下面的黄瓜jar文件并添加到你的项目中(不要添加到pom中 直接)

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>1.2.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
    </dependency
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm-deps</artifactId>
        <version>1.0.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>gherkin</artifactId>
        <version>2.12.2</version>
        <scope>provided</scope>
    </dependency>
    
  3. 确保您已将 TestNG 库添加到项目中

  4. 在 pom.xml 文件中添加以下 cucumber-testng 依赖项

    <dependency>
       <groupId>info.cukes</groupId>
       <artifactId>cucumber-testng</artifactId>
       <version>1.2.5</version>
    </dependency>
    
  5. 使用 AbstractTestNGCucumberTests 扩展运行器类

  package tests.report.runners;
  import org.testng.annotations.Test;
  import cucumber.api.testng.AbstractTestNGCucumberTests;
  import cucumber.api.CucumberOptions;
  @Test
  @CucumberOptions(features = "src/test/resources/features",glue= {"tests"},tags= 
  {"@Report"})
  public class ReportRunner extends AbstractTestNGCucumberTests {
  }
  1. 使用下面的 testng.xml 文件执行
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="First Suite" >
<test name="Chrome Test" >
<classes>
<class name ="tests.report.runners.ReportRunner"></class>
</classes> 
</test>
</suite>

谢谢!

【讨论】:

    猜你喜欢
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多