【问题标题】:How to run a Scenario as a Given step before further scenarios如何在进一步场景之前将场景作为给定步骤运行
【发布时间】:2021-12-06 05:12:19
【问题描述】:

我正在使用 Cypress & Cucumber 自动化一个网站,允许用户搜索、然后打开和编辑列表中的内容...所以我有一个像这样的通用初始场景;

Scenario: A valid user can navigate to & Search Things
    Given I have submitted "valid" user credentials
    When I am taken to the dashboard
    And I navigate to Manage Things
    Then I make a generic search for things

步骤定义;

Given('I have submitted {string} user credentials', (userType)=>{
    let user = userType === 'valid' ? testUser1 : new User('test@test.test', 'test1234')
    userLogin(user)
})

When('I am taken to the dashboard', ()=>{
    homepage.mainHome().should('be.visible')
})


And('I navigate to Manage Things', () =>{
    homepage.homeThings().click()
    homepage.thingsManageThings().click()
    cy.get('.form-header').should('contain', 'Things')
})

Then('I make a generic search for things', () =>{
    thingsMenu.manageThingsSearch().click()
    thingsMenu.manageThingsTable().should('be.visible')
})

展望未来,我希望接下来的几个场景/测试在继续执行更多步骤之前运行此场景 - 理想情况下,我将有类似 Given A valid user can navigate to & Search Things 的内容,然后是 When I select edit on the first thing 等......我将如何包装这个 @987654325 @ as Given 一步?我看过使用 before() 语句,但之前似乎没有回答运行整个场景的问题......?

【问题讨论】:

  • 您可以在所有场景中使用BackgroundBackground: A valid user can navigate to & Search Things Given I have submitted "valid" user credentials When I am taken to the dashboard And I navigate to Manage Things Then I make a generic search for things
  • @HamzaFarooq 是正确的。我们使用 Selenium 运行 cucumber-java 功能,其中 80% 的功能内的所有场景都使用背景场​​景。

标签: testing automation cucumber cypress


【解决方案1】:

您可以通过使用功能文件中的背景部分来实现此目的。
见信息here

Feature: My feature

    Description of my feature

    Background: this will run before each scenario
        Given A valid user can navigate to & Search Things
        And .....
        
    Scenario: #1
        When I select edit on the first thing
        Then ...

    Scenario: #2
        Given ...
        When ...
        Then ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 2015-02-27
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    相关资源
    最近更新 更多