我有Cucumber功能文件有2个场景,例如请在下面找到示例文件。
@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跑步者课程中需要添加什么?
答案 0 :(得分:1)
@Test
,延长AbstractTestNGCucumberTests
已足够如果您需要某些先决条件,请考虑在步骤类中使用@Before
注释 OR 在功能文件中使用关键字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