Gherkin

Gherkin Steps

Gherkin is a fluent wrapper for writing a workflow as a specification. Given sets up the precondition, the starting state. When describes the action. And chains another action or condition at the same level. Then describes the expected outcome. Each one takes a step, which is any Action: a method by name, or a lambda. GPAL.Gherkin holds no browser and no application of its own, so the automation is done by whatever the workflow opened and the step can reach.

NOTE

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 runs as the chain reaches it. Nothing is collected to run later, so a spec reads top to bottom in the order it happens. What each call answers is what decides the shape: Given answers a When, When answers an And, And answers a Then, and Then answers another Then or another And. A spec cannot say Then before When, and the compiler is what tells you so rather than a failing run.

// the workflow owns the browser, and each step is a plain method that uses it

IBrowser browser = GPAL.Browser

.WithBrowserType(BrowserType.Chrome)

.WithDriverLocation(@"C:drivers")

.ToGPALObject();


void OpenLoginPage()

{

browser.GoTo("https://example.com/login");

}


void EnterCredentials()

{

browser

.WithSelector("#username")

.FillInFrom("admin");

}


void ClickLogin()

{

browser

.WithSelector("#submit")

.LeftClick();

}


void VerifyDashboard()

{

browser

.WithSelector(".dashboard-header")

.WaitFor(5_000);

}


// Given, When, And, Then. each takes a step and answers with what may follow it

GPAL.Gherkin

.Given(OpenLoginPage)

.When(EnterCredentials)

.And(ClickLogin)

.Then(VerifyDashboard);

💬 Ask GPAL