What is Given-When-Then?

Given-When-Then is a way of writing a test scenario in plain sentences instead of code: some starting state, When something happens, Then some outcome is true. It comes from behaviour-driven development (BDD), and the specific plain-text syntax for it is usually called Gherkin.

The point isn’t to replace real test code — it’s to give a team a shared sentence everyone can agree on before anyone writes the automation for it: a product owner, a tester, and a developer can all read "Given I am on the site, When I search, Then I see results" and agree that’s the behaviour that matters, without any of them needing to read JavaScript or Python first. The code underneath — however it’s written, in whichever tool — is what actually proves that sentence stays true.

The scenario

One scenario, written in Gherkin:

Given I am on https://google.com
When I type in the search box and click submit
Then I see search results

Below, the same three lines are carried out eight ways: two browser automation tools (Selenium and Playwright), each in four languages (JavaScript, Python, Rust, and C#). Each line of code is commented with which Given/When/Then step it belongs to, so you can trace the plain sentence straight into the code that implements it.

Back to home See more examples