Executing scenario even if one of the step is failed

…衆ロ難τιáo~ 提交于 2019-12-11 18:55:18

问题


Following is just normal example, If Test failed at Step
Then I see Level2 MenuLinks It skip all next steps. I would like to know if there is any option to keep executing other steps?

Thank you

Feature: Menu
    In order to check MenuLinks

Scenario Outline: Open a Page
    Given I have open the Page
    Given I see MenuLinks
    When I click on Level1 in MenuLinks
    Then I see Level2 MenuLinks
    And I go back to pagetemplate
    Given I see Level2 in MenuLinks
    When I click on Level2
    Then I see Level3 MenuLinks

回答1:


I'm not sure why you would want to do this. Doing this will make it harder to see that the Then step has failed. If this is not actually important, why are you checking it?
But this one way to approach this, using a try catch:

In your step Then I see Level2 MenuLinks

[Then(@"I see Level2 MenuLinks")]
public void ISeeLevel2MenuLinks()
{
  try 
  {
         Execute your test here
  }
  catch
  {
         NotifyMeOnFailure();
         //A method that will notify you that the step failed. 
         //Because in specflow it will show as succesfully passed 
  }

}

Furthermore I would advise against the approach you have in your post. It would be better to create two different scenarios.

Scenario: Check for level2 menu links
  Given I have open the Page
  And I see MenuLinks
  When I click on Level1 in MenuLinks
  Then I see Level2 MenuLinks

Scenario: Check for level3 menu links
  Given I have open the Page
  When I click on Level1
  And I click on Level2
  Then I see Level3 MenuLinks

This way it is much easier to quickly detect where something went wrong.



来源:https://stackoverflow.com/questions/54690054/executing-scenario-even-if-one-of-the-step-is-failed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!