Cucumber 使用TestNG执行Cumber-存在未定义的步骤

Cucumber 使用TestNG执行Cumber-存在未定义的步骤,cucumber,testng,cucumber-java,Cucumber,Testng,Cucumber Java,我想用TestNG运行cumber特性,以实现并行执行。我继续遇到testNG无法找到匹配的粘合代码的问题。尽管代码是通过步骤正确编写和映射的 将跳过测试执行,错误状态为存在需要定义的未定义步骤。 然后,我将步骤定义类移动到我的测试运行程序类所在的包中,并且执行成功 我无法理解为什么testNG不能识别不同包中的粘合代码。我也尝试处理不同的依赖项,但效果不太好。是否有其他方法确保testNG查看步骤定义的正确位置 以下是POM: <project xmlns="http://maven.a

我想用TestNG运行cumber特性,以实现并行执行。我继续遇到testNG无法找到匹配的粘合代码的问题。尽管代码是通过步骤正确编写和映射的

将跳过测试执行,错误状态为存在需要定义的未定义步骤。 然后,我将步骤定义类移动到我的测试运行程序类所在的包中,并且执行成功

我无法理解为什么testNG不能识别不同包中的粘合代码。我也尝试处理不同的依赖项,但效果不太好。是否有其他方法确保testNG查看步骤定义的正确位置

以下是POM:

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>CucumberPractice</groupId>
  <artifactId>CucumberPractice</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>CucumberPractice</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-core</artifactId>
    <version>4.7.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>4.7.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.7.2</version>
    <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm-deps -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-jvm-deps</artifactId>
    <version>1.0.6</version>
    <scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-core -->
<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-core</artifactId>
    <version>2.1</version>
    <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>gherkin</artifactId>
    <version>5.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-html -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-html</artifactId>
    <version>0.2.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-all</artifactId>
    <version>1.10.19</version>
    <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-testng</artifactId>
    <version>4.7.2</version>
</dependency>
</dependencies>
</project>
功能文件:

@NewTabFeature @Chrome
Feature: Opening the WebPage in New Tab


  @NewTabSnr1
  Scenario: Open the link in a New WebPage and Validate the Content
    Given User opens Salesforce.com
    And Home Page is sucessfully loaded
    When User clicks on Try For Free button
    Then New Tab is opened
    And Sign up form is visible

  @NewTabSnr2
  Scenario Outline: Validate the Content on HomePage after entering details on new tab
    Given User opens Salesforce.com
    And Home Page is sucessfully loaded
    When User clicks on Try For Free button
    And New Tab is opened
    And User enters SignUp "<firstname>" "<lastname>" "<jobtitle>" information
    Then User goes back to home page
    And validate home page content

    Examples: 
      | firstname | lastname | jobtitle  |
      | Kovid |Mehta | Sales Manager |
      | Vikas |Bhat | IT Manager |
@NewTabFeature@Chrome
功能:在新选项卡中打开网页
@新ABSNR1
场景:在新网页中打开链接并验证内容
给定用户打开Salesforce.com
主页已成功加载
当用户单击“免费试用”按钮时
然后打开新选项卡
并且注册表格是可见的
@新ABSNR2
场景大纲:在新选项卡上输入详细信息后验证主页上的内容
给定用户打开Salesforce.com
主页已成功加载
当用户单击“免费试用”按钮时
新标签页打开
用户输入注册“”信息
然后用户返回主页
并验证主页内容
示例:
|名|姓|职务|
|科维德|梅塔|销售经理|
|Vikas | Bhat | IT经理|

如果您删除了不使用的依赖项,或者通过过渡方式拉入,并让Maven为您执行依赖项管理,您将看到您必须替换:

import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.CucumberOptions.SnippetType;
与:

目前,您可以删除:

junit
cucumber-junit
cucumber-jvm-dep
gherkin
cucumber-html

如果您删除了不使用的依赖项,或者以过渡方式拉入,并让Maven为您执行依赖项管理,您将看到您必须替换:

import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.CucumberOptions.SnippetType;
与:

目前,您可以删除:

junit
cucumber-junit
cucumber-jvm-dep
gherkin
cucumber-html

嗨@mpkorstanje谢谢你。因此,如果我理解正确,这是因为我使用了不正确的Cumber选项,应该指向testNG而不是junit。所以,如果我理解正确的话,这主要是因为我使用了对Cucumber选项的错误引用,这些选项应该指向testNG而不是junit。
junit
cucumber-junit
cucumber-jvm-dep
gherkin
cucumber-html