Cucumber 如何在每个场景之前运行后台

Cucumber 如何在每个场景之前运行后台,cucumber,cucumber-java,Cucumber,Cucumber Java,我有一个带有标签的后台测试用例,每次我都需要在多个场景中运行它 例如: 有3个场景和1个背景。简而言之,背景的行为应该类似于@before测试方法 所以我的处决应该是这样的 背景然后场景1(@Dev,@tagteacher1) 再次是背景,然后是场景2(@Dev,@tagteacher2) 再次是背景,然后是场景3(@Dev,@tagteacher3) @TestStory 特点:需要填写教师时间表 背景: 场景大纲:打开网页 给定用户使用给定的 并使用给定的 用户点击教师提交链接 @发展 示例

我有一个带有标签的后台测试用例,每次我都需要在多个场景中运行它

例如:

有3个场景和1个背景。简而言之,背景的行为应该类似于@before测试方法

所以我的处决应该是这样的

  • 背景然后场景1(@Dev,@tagteacher1)
  • 再次是背景,然后是场景2(@Dev,@tagteacher2)
  • 再次是背景,然后是场景3(@Dev,@tagteacher3)
  • @TestStory
    特点:需要填写教师时间表
    背景:
    场景大纲:打开网页
    给定用户使用给定的
    并使用给定的
    用户点击教师提交链接
    @发展
    示例:
    |端点|用户名|密码|
    | http://teachersheetdev.ggn.com |sdrdev | aknewdev|
    @质量保证
    示例:
    |端点|用户名|密码|
    | http://teachersheetqa.ggn.com |sdrqa | aknewdev|
    @tagteacher1
    场景1:打开应用程序主页并单击按钮1
    考虑到我在教师名册主页上
    当用户单击“添加任务”按钮时
    然后用户应该看到任务计划
    @tagteacher2
    场景1:打开应用程序主页并单击按钮2
    考虑到我在教师名册主页上
    当用户单击“添加任务”按钮时
    然后用户应该看到任务计划
    @tagteacher3
    场景1:打开应用程序主页并单击按钮3
    考虑到我在教师名册主页上
    当用户单击“添加任务”按钮时
    然后用户应该看到任务计划
    导入org.junit.runner.RunWith;
    导入com.optum.synergy.common.ui.controller.WebController;
    进口cucumber.api.CucumberOptions;
    导入cumber.api.SnippetType;
    进口cucumber.api.junit.cucumber;
    @RunWith(cumber.class)
    @黄瓜选项(
    plugin={“json:target/test_results/cucumber.json”},
    features={“src/main/resources/ui/features”},
    tags={“@Dev,@tagteacher”},
    snippets=SnippetType.CAMELCASE
    )
    公营黄瓜试验{
    公共静态void拆卸(){
    WebController.closeDeviceDriver();
    }
    }
    

    当我想使用Dev或QA env运行时,如何使用tag?

    通过在配置中设置您正在使用的站点,可以更轻松地实现这一点 文件(无论是开发还是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的主要原因是为了表达意图——描述用户应该如何在网站中移动,而不必担心实现细节。这是为了弥合业务部门和开发团队之间的沟通鸿沟,以便他们能够了解正在测试的场景。实现细节隐藏了测试的意图。

    我有两个env来运行I、e-Dev和QA。如何在运行时使用基于标签的示例值@Kyle Fairns您可以运行该套件两次,使用环境变量说明正在使用的环境,使用外部脚本运行以更改该环境变量。如果您使用的是页面对象模型,您将能够轻松地为每个站点存储一个基本url,并且只需要页面url的结尾部分。是的,我只使用页面对象模型。如何使用环境变量仅运行Dev env?还有如何使用标签?使用标签:设置标签取决于您使用的是windows还是基于unix的系统(如Mac或Linux)。我在这里假设您在Windows上:您可以使用
    @Before
    钩子来实现这一点。看见
    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