Skip to content

Writing the first test

guilhermechapiewski edited this page Sep 13, 2010 · 15 revisions

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
Given
    I go to "http://www.google.com"
When
    I fill "q" textbox with "Hello World"
    And I click "btnG" button
Then
    I see "Hello World - Google Search" title

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

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: Given, When and Then. Each of those areas can have as many actions as you want.

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

Pyccuracy’s stories need to begin with a As a/I want to/So that header. More information about User Stories templates can be found on the Wikipedia page for User Story.

Scenarios

Each story (which will turn into one test file) can contain as much scenarios as you want/need.

Scenarios are the executable pieces of your test. They will be executed by Pyccuracy in the order that you defined them, even though you should not have scenarios that depend on the order they are executed. If you need thing to happen before a test, write pre-conditions/Given statements instead (see also Creating custom Actions).

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 and 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. Having actions in the wrong section may lead readers to misinterpret your intentions and make your tests difficult to read and maintain.

Actions

Actions are the cream and butter of Pyccuracy. They are the language bits that drive the browser for you. Actions can be 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:

I click "some" button

This will make Pyccuracy click on a button where the name or id is equal to “some”.

There are loads of actions to learn. In order to know which have been implemented so far, you have two ways:

1) Documentation

Make sure you take a look at the “Actions Reference” section

2) Command line tool

Execute the following command to see all available actions:

$ pyccuracy_help

To search for specific commands, for instance, commands related to textboxes:

$ pyccuracy_help --term textbox

Sample result:

----- Found 5 results for "textbox" -----

textbox_clean                       = (And )I clean "textbox_name" textbox
textbox_is_empty                    = (And )I see "textbox_name" textbox is empty
textbox_is_not_empty                = (And )I see "textbox_name" textbox is not empty
textbox_type                        = (And )I fill "textbox_name" textbox with "text"
textbox_type_keys                   = (And )I slowly fill "textbox_name" textbox with "text"

----- Found 5 results for "textbox" -----