Scout Examples

Form examples

Entering text

The type command will enter the specified text in the first element that matches the specified selector.

<input name="q">
type    [name="q"]    Hello, world

Clicking checkboxes and radiobuttons

To select a particular checkbox or radiobutton, you can often target them by their unique name/value combination.

<input type="radio" name="gender" value="m"> Male
<input type="radio" name="gender" value="f"> Female
click    [name="gender"][value="m"]

However, if the page uses <label> elements correctly, you can target input elements with their label's text content:

<label>
    I agree with the terms &amp; conditions
    <input type="checkbox" name="terms">
</label>
click    "I agree with the terms & conditions"

Choosing an option in a select

With the choose action, you can choose a <select>'s option by text:

<select name="country">
    <option value="NL">The Netherlands</option>
</select>
choose    [name="country"]    "The Netherlands"

Submitting a form

Submitting a form is done in the same way as a real user would do it. Click the submit button:

click    :submit

Or, if the form is set up in that way, hit the enter key inside a text input:

type    [name="message"]    goodbye<Enter>

Combined example

Here's a combined example that opens the Twitter advanced search form, and searches for positive tweets about functional testing in English:

open      https://twitter.com/search-advanced
type      [name="ands"]        functional testing
choose    [name="lang"]        English (English)
click     "Positive :)"
click     "Include retweets"
click     "Search"

Screenshot examples

Saving a screenshot

The screendump command will save the current state of the page as a png file.

screendump    entire_page.png

When an additional selector is passed, the first visible element matching the selector will be saved.

screendump    page_header.png    .header

Comparing screenshots

The assertResembles command will compare a new screenshot to one that was previously made. This is useful to check the appearance of an element (or entire page) is consistent between different tests.

The following code will compare the entire page to a previously saved screenshot with filename page_base.png. Only an exact pixel-by-pixel match will pass the assertion.

assertResembles    page_base.png

If a selector is passed, the image is compared to the first visible element matching the selector.

assertResembles    header_base.png    .header

If the no image with the specified filename exists, the image will be created and the assertion will pass.

Assertion examples

Visibility

The assertVisible command checks if an element matching the selector is visible, i.e. not hidden and non-zero values for width, height and opacity.

assertVisible    .autocomplete-popup

The assertHidden command checks if there are no elements matching the selector that are visible.

assertHidden    .autocomplete-popup

In viewport

The assertInViewport command will check if the element is not only visible, but also in the viewport.

assertInViewport    h1

Text content

The command assertText checks if a visible element matching the selector contains the specified text.

assertText    h1    Lorem ipsum

Checking the location

There are two ways to check we're currently at the correct location. The easiest is assertPage, which checks if the argument is a substring of the current URL.

assertPage    /home.html

Combined example

Here's a combined example that follows and checks some links on reddit.com:

open          http://reddit.com

click         "new"
assertPage    /new

click         "rising"
assertPage    /rising

back
assertPage    /new