我有一个带有标签的后台测试用例,我需要每次运行多个场景。
示例:
有3个场景和1个背景。简而言之,Background应该像@BeforeMethod测试一样
所以我的执行应该是这样的
- 背景然后Scenario1(@ Dev,@ tagteacher1)
- 再次背景然后Scenario2(@ Dev,@ tagteacher2)
- 再次背景,然后是场景3(@ Dev,@ tagteacher3)
@TestStory
Feature: Teachers' timesheet need to be filled
Background:
Scenario Outline: Open Webpage
Given User Open teacher application with given <ENDPOINT>
And Login into application with given <USERNAME> and <PASSWORD>
And User clicks on teacher submission link
@DEV
Examples:
| endpoint | USERNAME | PASSWORD |
| http://teachersheetdev.ggn.com | sdrdev| aknewdev|
@QA
Examples:
| endpoint | USERNAME | PASSWORD |
| http://teachersheetqa.ggn.com | sdrqa | aknewdev|
@tagteacher1
Scenario1: Open app home page and click the button1
Given I'm at the teachersheet homepage
When User clicks Add Task button
Then User should see the tasks schedule
@tagteacher2
Scenario1: Open app home page and click the button2
Given I'm at the teachersheet homepage
When User clicks Add Task button
Then User should see the tasks schedule
@tagteacher3
Scenario1: Open app home page and click the button3
Given I'm at the teachersheet homepage
When User clicks Add Task button
Then User should see the tasks schedule
import org.junit.runner.RunWith;
import com.optum.synergy.common.ui.controller.WebController;
import cucumber.api.CucumberOptions;
import cucumber.api.SnippetType;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = { "json:target/test_results/cucumber.json"},
features = { "src/main/resources/ui/features" },
tags ={"@Dev,@tagteacher"},
snippets = SnippetType.CAMELCASE
)
public class CucumberRunnerTest {
public static void tearDown(){
WebController.closeDeviceDriver();
}
}
当我想用Dev或QA env运行时如何使用标签?
通过在配置文件中设置您正在使用的站点(无论是dev还是qa站点),您可以更轻松地实现这一点,并将用户名和密码移动到步骤定义,使用与QA或QA相关的用户名和密码。开发。
在此之后,您将能够这样做:
Background:
Given the user has opened the teachers application
And they have logged in
@teacher
Scenario: Open app home page and view the task schedule
Given they are on the teachersheet homepage
When they start to add a task
Then they should see the task schedule
@teacher
Scenario: Open app home page and view the task schedule
Given they are on the teachersheet homepage
When they start to add a task
Then they should see the task schedule
如果您需要以不同的教师身份登录,则必须将登录步骤移至场景中,因为它们不一样,您必须提供登录用户的详细信息。
作为旁注,请考虑您正在使用的措辞。如果您正在测试网站的设计,那么单击按钮一切都很好,但使用Cucumber的主要原因是表达意图 - 描述用户应该如何在网站中移动,而不必担心实现细节。它是弥合业务和开发团队之间的沟通差距,因此他们可以找出正在测试的场景。实现细节隐藏了测试的意图。