Gherkin

Gherkin Steps

Given, When, And, and Then - the four fluent methods that map to standard Gherkin BDD syntax for structuring automation workflows as human-readable specifications.

Given, When, And, and Then - the four fluent methods that map to standard Gherkin BDD syntax for structuring automation workflows as human-readable specifications.

Gherkin provides a fluent wrapper for writing automation workflows in BDD (Behavior Driven Development) style. Given sets up the precondition - the starting state. When describes the action being performed. And chains additional actions or conditions at the same level. Then describes the expected outcome or verification step. Each method accepts a delegate (action or method reference) and optional arguments. The underlying automation is performed by the Browser or Application instance configured in ForBrowser or ForApplication.

TIP

Gherkin does not change how GPAL automation works - it is a structural pattern that makes workflows read like plain English specifications. Each delegate you pass to Given, When, And, and Then is a method that performs the actual browser or application automation.

Examples

GPAL Fluent: High-level fluent C# API

//Each step method (Given, When, And, Then) executes the delegate immediately and returns the Gherkin instance for the next step. There is no deferred execution - each step runs as the chain advances.

// Write a login test in Gherkin style void OpenLoginPage() { GPAL.Browser.GoTo("https://example.com/login"); } void EnterCredentials() { GPAL.Browser .WithSelector("#username") .FillInFrom("admin"); } void ClickLogin() { GPAL.Browser .WithSelector("#submit") .LeftClick(); } void VerifyDashboard() { GPAL.Browser .WithSelector(".dashboard-header") .WaitFor(".dashboard-header"); } GPAL.Gherkin .ForBrowser(BrowserType.Chrome, "C:\drivers") .Given(OpenLoginPage) .When(EnterCredentials) .And(ClickLogin) .Then(VerifyDashboard);