简体   繁体   English

无法在 Cucumber-Maven(TestNG)中运行 testng.xml

[英]Can't run testng.xml in Cucumber-Maven(TestNG)

In eclipse IDE, I have created a basic cucumber framework by using Maven project.在 Eclipse IDE 中,我使用 Maven 项目创建了一个基本的黄瓜框架。

I have added all the dependencies required in pom.xml.For TestNG plugin added below dependencies.我已经添加了 pom.xml.For 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>

But 'TestNG Suite' option was not coming in preferences,so installed TestNG through Help->Install New Software.但是“TestNG Suite”选项没有出现在首选项中,所以通过 Help->Install New Software 安装了 TestNG。

Framework is having feature file(scenario is described),stepdefinitions(code/logic given) and runner class(To map feature with stepdefinitions file and run it).框架具有特征文件(描述了场景)、步骤定义(给出了代码/逻辑)和运行器类(使用步骤定义文件映射特征并运行它)。

Runner class :跑步者类:

package tests.report.runners;

import cucumber.api.CucumberOptions;


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

Like this I have one runner class for each module(End to End scenario)像这样我每个模块都有一个跑步者课程(端到端场景)

Ex :前任 :

  • Login, go to product page and logout登录,进入产品页面并退出

  • Login,generate report and logout登录、生成报告和注销

I am trying to run these runner class by testng.xml file我正在尝试通过 testng.xml 文件运行这些运行器类

testng.xml file 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>

But its throwing below error但它抛出错误

输出屏幕截图

Issue was because of incompatible junk jars stored in maven repositeries.问题是因为存储在 Maven 存储库中的不兼容的垃圾 jars。

Please follow below steps请按照以下步骤

  1. Clean old properties/maven dependencies(Open command prompt from yours project directory and run below commands)清理旧属性/maven 依赖项(从您的项目目录中打开命令提示符并运行以下命令)
    • mvn eclipse:clean mvn 日食:清洁
    • mvn eclipse:eclipse -Dwtpversion=2.0 mvn eclipse:eclipse -Dwtpversion=2.0
  2. Download below cucumber jar files and add in your project(don't add it in pom directly)下载下面的黄瓜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. Make sure that You have already TestNG library into project确保您已经将 TestNG 库添加到项目中

  4. Add below cucumber-testng dependencies in pom.xml file在 pom.xml 文件中添加以下 cucumber-testng 依赖项

    <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-testng</artifactId> <version>1.2.5</version> </dependency>
  5. Extend runner class with AbstractTestNGCucumberTests使用 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. Execute with below testng.xml file使用下面的 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>

Thanks!谢谢!

On the intellij Right pane - click Maven - Reload all maven projects.在 intellij 右窗格中 - 单击 Maven - Reload all maven projects。 Invalidate caches and restart from files.使缓存无效并从文件重新启动。 It will work它会工作

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

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