How about if we use Gherkin in a situation like smoke test, and we need to make sure that something exists in the database using only the user interface?
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
Reusing the same Then step twice is essentially an if-else that ensures that my box exists so that I can run my other tests in the smoke test package, which requires a field.
But it depends on the ability to stop the script from running in the test runner or do something extraneous:
ScenarioContext.Current["TestPassed"] = true;
and then at each stage if(ScenarioContext.Current.Get<bool>("TestPassed")) return;
source share