0

我有 2 个场景的 Cucumber 功能文件,例如,请在下面找到示例文件。

@RunFeature
Feature: Sanity Testing of scenarios

@LoginFeature
Scenario: Test xyz feature
    Given The user is on login page
    When User enters credentials
    And clicks on login button
    Then homepage should be displayed

@InfoFeature
Scenario: Test abc feature
    Given The user is on home page
    When User enters employee name in textbox
    And clicks on get details button
    Then Employee details are displayed

我正在尝试使用 TestNG 运行此功能文件,

package TestNGClass;
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import cucumber.api.testng.TestNGCucumberRunner;

@Test(groups="cucumber")

@CucumberOptions(
        features ="src/main/resources",
        glue="stepDefinitions",
        tags="@RunFeature")

public class TestNGRunner extends AbstractTestNGCucumberTests{


    @Test(groups="cucumber",description="Runs Cucumber Features")
    public void run_Cukes()throws IOException{
        //new TestNGCucumberRunner(getClass()).runCukes();
    }
}

但我观察到,有时它会并行运行两种场景,有时会以顺序模式运行。我正在尝试以顺序模式运行场景。谁能告诉我需要在我的 testng runner 类中添加什么?

4

1 回答 1

1
  1. 无需将您的cukes runner标记为@Test,扩展AbstractTestNGCucumberTests就足够了
  2. 无需在此类中定义测试,使用步骤类和功能文件
  3. 如果您需要某些先决条件,请考虑@Before在步骤类中使用注释Background在功能文件中使用关键字。章节中描述的句子Background将针对该功能文件中的每个场景执行。像这样:

    Background: Test xyz feature
    Given The user is on login page
    When User enters credentials
    And clicks on login button
    Then homepage should be displayed
    
    Scenario: Test abc feature
    Given The user is on home page
    When User enters employee name in textbox
    And clicks on get details button
    Then Employee details are displayed
    
于 2016-08-19T18:08:38.140 回答