Testing

If you have ever wondered what kind of tests I write on the UI level, wondr no more. At the end of this post there’s enclosed a current version of a test script that I use for ship and vehicle designer. The script is written for Robot Framework and it in turn uses Selenium WebDriver to actually interact with a browser.

In addition of just having test script, I have sprinkled a little bit of background information in between of the tests. These snippets of prose hopefully remind me in the future what I was thinking about when I wrote them.

There’s four sections. First one is for including some resource files and configuring setup and teardown activity. It is marked with *** Settings *** line. Next section, starting with *** Variables *** is very short. It only defines one single variable that is used to name vehicle design.

Third section is marked with *** Keywords *** and like name implies it defines some keywords. These encapsulate actions with multiple steps and give them names. These keywords can then be used in tests, making the tests less verbose and more understandable.

Last sections, marked with *** Test Cases *** is the longest and contain actual test cases. Robot Framework excutes these and verifies that all wanted conditions are fullfilled. If there are any errors, a screenshot is taken and saved for later viewing.

.. code:: robotframework

*** Settings ***
Resource            ./settings.rst
Library             SeleniumLibrary
Suite Setup         Designer Setup
Suite Teardown      Designer Teardown
Test Teardown       Error Bar Should Not Be Visible

.. code:: robotframework

*** Variables ***
${test_vehicle_name}        Test Vehicle

.. code:: robotframework

*** Keywords ***
Designer Setup
    Login As    ${VALID USER}   ${VALID PWD}


Designer Teardown
    Logout

Designer

Designer is used to design blueprints for ships and vehicles. These blueprints are faction specific.

Keywords

Design can be opened by clicking the respective row on the designs list.

.. code:: robotframework

View Design on Row
    [Arguments]   ${design_row_id}
    ${id}=   Catenate   SEPARATOR=   design-entry-   ${design_row_id}
    Click Element   id:${id}
    Wait Until Data Has Finished Loading

Close Design Without Saving
    Click Element   id:clear-button
    Wait Until Data Has Finished Loading

Chassis is can be selected from a list that shows all currently available chassis.

.. code:: robotframework

Select Chassis
    [Arguments]   ${chassis_name}
    Click Element   xpath=//*[@id="chassis-list"]/tbody/tr/td[text()[contains(., '${chassis_name}')]]
    Wait Until Data Has Finished Loading

Components are added to design by clicking them. Currently available components are filtered by available technology and selected chassis.

.. code:: robotframework

Add Component
    [Arguments]   ${component_name}
    Click Element   xpath=//div[contains(@class, 'available-component')][div//div//div//text()[contains(., '${component_name}')]]
    Wait Until Data Has Finished Loading

Name Design
    [Arguments]   ${design_name}
    Input Text   id:ship-name-input   ${design_name}

A valid design can be saved by clicking save button. This saves the design, but does not close the designer. In order to return to main view of the designer, user has to click clear button. Deleting a design can be done from the main view.

.. code:: robotframework

Save Design And Return
    Click Element   id:save-button
    Wait Until Data Has Finished Loading
    Click Element   id:clear-button
    Wait Until Data Has Finished Loading

Delete Design
    [Arguments]   ${design_name}
    Click Element   xpath://*[@id="design-table"]/tbody/tr[td//text()[contains(., '${design_name}')]]/td[4]/i[2]
    Wait Until Data Has Finished Loading

Test cases

Designer can always be opened from the top menu.

.. code:: robotframework

*** Test Cases ***
Opening Designer
    [Tags]   designer   smoke
    Click Link   Designer
    Wait Until Data Has Finished Loading

A design is created by first selecting suitable chassis and then filling in components and name. Until required components have been filled in, the design can’t be saved.

.. code:: robotframework

Creating a New Design
    [Tags]   designer
    Select Chassis   SUV
    Add Component   Wheeled
    Name Design   ${test_vehicle_name}
    Wait Until Page Contains   Design ok
    Save Design And Return
    Wait Until Page Contains   ${test_vehicle_name}

Existing design can be opened by clicking its entry on the list.

.. code:: robotframework

Viewing Existing Design
    [Tags]   designer
    View Design on Row   1
    Close Design Without Saving

Clicking remove button will immediately delete the design.

.. code:: robotframework

Deleting an Existing Design
    [Tags]   designer
    Delete Design   ${test_vehicle_name}
    Wait Until Data Has Finished Loading
    Page Should Not Contain    ${test_vehicle_name}