cucumber - 如何在每个场景之前运行后台
问题描述
我有一个带有标签的背景测试用例,每次都需要在多个场景中运行。
例子 :
有3个场景和1个背景。简而言之,Background 应该表现得像 @BeforeMethod 的测试
所以我的执行应该像
- 背景然后场景 1 (@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 环境运行时如何使用标签?
解决方案
您可以通过在配置文件中设置您正在使用的站点(无论是 dev 还是 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 的主要原因是表达意图 - 描述用户应该如何在网站中移动,而不用担心实现细节。这是为了弥合业务和开发团队之间的沟通鸿沟,这样他们就可以弄清楚正在测试哪些场景。实现细节隐藏了测试的意图。
推荐阅读
- mysql - mysql 5.7 中的查询比 5.1 慢 2 倍或更多倍
- c# - 从其他较小的 DataTable 填充 DataTable
- python - 在不删除注释的情况下更改 python 中的配置文件
- java - 如何高效地读写 Parquet 文件?
- neo4j - 使用 neo4j 计算 DBLP 中的自引计数
- revit-api - revit Api:FamilyInstance(door) 的 FacingFlipped 属性给出不同的值?
- jenkins - 詹金斯条件构建
- jquery - 获取输入类型时间的值
- c# - Python 使用 pythonnet 调用 C++/CLI dll 函数
- node.js - Mongoose,ExpressJs - 暴露 mongo 文档