Does if else concept available in feature file (Gherkin language)?

后端 未结 4 1043
暖寄归人
暖寄归人 2021-01-18 21:32

Is there anyway where we can use if/else concept in feature file? For example:

  Scenario: User should be able to check login page
  Given I am on login pag         


        
4条回答
  •  攒了一身酷
    2021-01-18 22:31

    What about if we are using Gherkin in a smoke test type situation and we need to ensure something exists in the database using only the UI?

    Scenario: I need to create one (and only one) Box before I run the rest of my smoke tests
    Given I login as Admin
    When I am on the Box list Page
    Then the test passes if the Box named "QA SmokeTest" exists
    When I click the Add New Box Button
    And enter the details for a New Box
    And press Save New Box
    Then the test passes if the Box named "QA SmokeTest" exists
    

    The re-use of the same Then step twice is essentially an if-else that will make sure my Box exists so that I can run my other tests in the smoke test suite that require a Box.

    But that is dependent on being able to stop the Scenario execution in the test runner or doing something extraneous like:
    ScenarioContext.Current["TestPassed"] = true;
    and then in each of the steps
    if(ScenarioContext.Current.Get("TestPassed")) return;

提交回复
热议问题