Testatoo

1. Introduction


The main purpose of this tutorial is to give you the way and the philosophy under Testatoo. As explained in the full documentation Testatoo is a strongly opinionated tool.

We take care through this tutorial to give you a full vision of the Testatoo way.

2. Installation


Clone the Testatoo Starter sample from github.

As you can see it’s a simple Java/Groovy/Maven project setup. The pom just import necessary libraries

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>
<dependency>
   <groupId>org.testatoo</groupId>
   <artifactId>testatoo</artifactId>
   <version>2.0.b26</version>
   <scope>test</scope>
</dependency>

Testatoo is build on top of Selenium 3: definitively turned to the future.

2.1. Run with locale Chrome

  1. Install Google chrome

  2. Install the driver Chrome Driver

  3. Run the test with mvn test -Ddriver='your driver location' (by default /usr/bin)

2.2. Run with remote Chrome

Nobody love to be bored by a browser who pop when he run a test. It’s a good practice in development to use a remote dockerised browser.

  1. Install Docker

  2. Run the docker container: docker run -d -p 4444:4444 selenium/standalone-chrome:3.0.1-aluminum

  3. Run the test with mvn test -Ddocker

Philosophy


Now take a look on the test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package starter

import org.junit.Before
import org.junit.ClassRule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.testatoo.core.component.Item
import starter.config.WebDriverConfig

import static starter.component.Factory.*
import static org.testatoo.core.Testatoo.*
import static org.testatoo.core.input.Key.RETURN

@RunWith(JUnit4)
class GoogleSearchTest {

    @ClassRule
    public static WebDriverConfig driver = new WebDriverConfig() (1)

    @Before
    void setup() {
        visit 'http://www.google.ca'
    }

    @Test
    void simple_search_test() {
        searchField.should { be visible }
        resultList.should { be missing }    (2)

        fill searchField with 'groovy'      (3)
        type RETURN

        resultList.should { be visible }

        Item item = resultList.items()[0]
        item.should {
            have title('The Groovy programming language')
            have reference('http://www.groovy-lang.org/')
        }
    }
}
1 Always externalise the Webdriver configuration. Here we added a JUnit class rule to manage the Webdriver configuration and lifecycle (see source for details).
2 As possible use a factory to fetch your UI component
3 Look how it’s easy in Testatoo to fill fields

Ok now take a closer look on the test. The goal of the test is simple: open google and search for GROOVY.

Here what we want is simple.

  1. GIVEN the search field is visible and the result list is not here.

  2. WHEN we enter the word groovy in the search field and press enter

  3. THEN we expect that the result list is here and contain a result with the expected item.

A test is an intention and need to express an intention. Testatoo is build around this idea. Write a test the more abstract possible who capture the intention.

What is the searchFile? The search field is, in this case, a simple HTML5 input text field. But we don’t want to use it as a detail (as a InputTypeText) but through it’s abstraction: A TextField.

What is the resultList? Hummm it’s more complicated here. In fact it’s a list of items. Pretty close of what you can find in HTML5 with UL/LI or OL/LI tags. But in this case it’s a soup of div of div.

All this details are hidden in the Factory class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package starter.component

import org.testatoo.bundle.html5.input.InputTypeText
import org.testatoo.core.component.ListView
import org.testatoo.core.component.field.TextField

import static org.testatoo.core.Testatoo.$

class Factory {

    static TextField getSearchField() {
        $('#lst-ib') as InputTypeText   // 1
    }

    static ListView getResultList() {
        $('#rso') as GoogleListView     // 2
    }

}

If the implementation of your application change the test stay the same you just need to update the factory. In Testatoo everything is a Component. Testatoo provide you the HTML5 bundle with all the HTML5 Component. But more important Testatoo give you the possibility to create you own component.

This is the cas here we create two component: GoogleListView