Lessons in this course (10)

8. BDD with Reqnroll (SpecFlow successor)

IntermediateMediumLesson 8 of 10
gherkin
Feature: Login
  Scenario Outline: Login with different users
    Given I am on the login page
    When I log in as "<email>" with password "<password>"
    Then I should see "<result>"
    Examples:
      | email            | password  | result            |
      | qa@example.com   | Secret#1  | Dashboard         |
      | qa@example.com   | wrong     | Invalid password  |
csharp
[Binding]
public class LoginSteps(ScenarioContext ctx, IWebDriver driver)
{
    private readonly LoginPage _login = new(driver);
    [Given("I am on the login page")] public void Open() => _login.Open();
    [When("I log in as {string} with password {string}")] public void Login(string e, string p) => _login.Submit(e, p);
    [Then("I should see {string}")] public void Check(string text) => Assert.That(driver.PageSource, Does.Contain(text));
}

BDD value: shared language with business (Three Amigos), living documentation. Cost: an extra layer — use it when business people actually read the feature files. Hooks: [BeforeScenario], [AfterScenario] (screenshot on failure), tags (@smoke) to filter runs.