Gherkin

Gherkin Setup

A step is an ordinary method. GPAL.Gherkin runs the ones you hand it, in order, and owns no browser, application or state of its own, so whatever a step needs is whatever the workflow opened. Given, When, And and Then each take a step alone, or a step plus up to three arguments passed after it. The arguments are typed: Given(SearchFor, "laptops") compiles only when SearchFor takes one string. Past three, give the step a class or a grid and hand it that.

Examples

GPAL Fluent: High-level fluent C# API

//The first step is a lambda because it is one line and naming it would add nothing. The others are methods, which is what you want once a step is worth reading on its own or is used by more than one spec. ExpectResults is where the spec earns its keep: a Then that publishes a FAILURE when the page did not do what the spec said. GPAL does not assert for you, so a Then that checks nothing passes every time.

// a step takes arguments as well, up to three, passed beside it

void SearchFor(string term)

{

browser

.WithSelector("#search")

.FillInFrom(term);

}


void ExpectResults(string term, int atLeast)

{

IGPALGrid<string> found = GPAL.Grid.ToGPALObject();


browser

.WithSelector(".result")

.WithAllThatMatch(-1)

.GetGrid(ref found);


GPAL.PublishSimpleEvent(atLeast <= found.Count() ? GPALEventType.NOTICE : GPALEventType.FAILURE,

$"[{term}] found [{found.Count()}] results, wanted [{atLeast}] or more");

}


GPAL.Gherkin

.Given(() => browser.GoTo("https://example.com"))

.When(SearchFor, "GPAL library")

.Then(ExpectResults, "GPAL library", 1);

💬 Ask GPAL