Test Syntax

Here we discuss Pyccuracy's tests syntax.

Overall test structure

The best way to learn about the test structure is to look at an example test.

As a Google User
I want to search Google
So that I can test Pyccuracy

Scenario 1 - Searching for Hello World
  I go to "http://www.google.com"
  I fill "q" textbox with "Hello World"
  And I click "btnG" button
  I see "Hello World - Google Search" title

Scenario 2 - Searching for Monty Python
  I go to "http://www.google.com"
  I fill "q" textbox with "Monty Python"
  And I click "btnG" button
  I see "Monty Python - Google Search" title

All the words in blue are keywords and each of them will be explained in the sections below.

The important thing to notice here is how Pyccuracy test files are organized.

Each file can contain one and only one story. That story is identified by the header (As a/I want to/So that).

It can, though, contain as many scenarios as you want. Each scenario needs to feature a title that identifies it and an index. You can see the lines identifying scenarios like "Scenario 2 - Searching for Monty Python".

Each scenario is divided in three areas: givens, whens and thens. Each of those areas can have as many actions as you want.

If all those names feel weird, keep reading and you'll understand each of the concepts.

Tests Header - As a / I want to / So that

Following BDD's structure all Pyccuracy's stories need to begin with a As a/I want to/So that header. More about that is discussed in the test conventions page.


Each story (test file) can contain as much scenarios as you want/need.

Scenarios are the executable pieces of your test. They will get executed by Pyccuracy in the order that you defined them, even though you should TRY REALLY HARD not to have scenarios that depend on the order they are executed.

Every scenario begins with a line that says the index and purpose of this scenario, like "Scenario 1 - Testing something".

Having proper naming of your scenarios not only improves your tests, but makes the end-run report more readable.

Given / When / Then

Each scenario is composed of three sections: given, when, then.

These sections correspond to the pre-conditions, the value being tested and the post-conditions, respectively.

Even though Pyccuracy will run the actions independently of which section you put them in, it's of major importance to have them in the proper section.

The impact of having actions in the wrong section are unreadable and unmaintainable tests.


Actions are the cream and butter of Pyccuracy.

They are the language bits that drive the browser for you. Actions are things like clicking a button or typing some text.

They are expressed in a much more natural language so you can have more readable tests.

Let's look at an example, the click of a button.

I click "some" button

Notice how natural that reads, even though you are just executing python code.

There are loads of actions to learn. In order to know which have been implemented so far just go to the docs for the release you are using and you can learn details of each action.

Pyccuracy is an open-source Python project with an OSI license.

The entry barrier for coding in Pyccuracy is really small, since the codebase is itself small as you can see in the stats above.

If you think you can contribute, join our dev list, check our JIRA server for the open tickets for the current release and start coding.