Table Of Contents

Previous topic

Installation

Next topic

API

This Page

Usage

Important

We assume at this stage that you already read and understand the part of the Robot Framework User Guide dedicated to tests suite authors.

About Selenium2Library

The only RobotFramework library exposed by robotframework-drupallibrary is called DrupalLibrary. Using its keywords in any test case requires to set up and open a browser using its Open Browser keyword.

Indeed, DrupalLibrary keywords use the Selenium browser instance that is provided by Selenium2Library. And running any DrupalLibrary without having previously opened a Selenium2Library browser may drive to unpredictable results and behaviour.

Demos

Demo files are provided in the demos/ folder of the source bundle distributed in our Git repository. Here are some of them that you could use as a starter for your test suites.

Hint

Please read the DrupalLibrary keywords in another browser window while reading the demos code.

The resources

The common resources are provided by the file resources.robot. It just defines a set of variables and an utility keyword.

*** Variables ***
# A Drupal demo site
${HOME URL}       http://demo.opensourcecms.com/drupal/
${WM NAME}        admin
${WM PASS}        demo123
# Params for Selenium2Library
${BROWSER}        firefox
${DELAY}          0

*** Keywords ***
Open On Page
    [Arguments]    ${url}
    [Documentation]    Bla bla
    ...    Blo blo
    Open Browser    ${url}    firefox
    Maximize Browser Window

Adding members

The suite from the file addmembers.robots adds - as its name says - 3 members, using the Sign In and Add Member keywords provided by DrupalLibrary. As you can notice as warned above, the suite opens a browser with the Open Browser keyword from the Selenium2Library.

*** Settings ***
Documentation     Adding members to the Drupal demo site
Resource          resources.robot
Library           Selenium2Library
Library           DrupalLibrary    ${HOME URL}

*** Test Cases ***
Open Home Page
    Open Browser    ${HOME URL}    ${BROWSER}
    Maximize Browser Window

Signing In
    Sign In    ${WM NAME}    ${WM PASS}    stop_on_failure=${false}

Adding Some Members
    Comment    Add regular member johndoe
    Add Member    johndoe    johndoe@foo.com    bigsecret
    Comment    Add janedoe as administrator
    Add Member    janedoe    janedoe@foo.com    bigsecret    extra_roles=administrator
    Comment    Add inactive member foobar
    Add Member    foobar    foobar@foo.com    bigsecret    active=${false}

Attempt To Duplicate A Member
    [Documentation]    We know johndoe is already registered, we don't consider following
    ...    member addition as an error since we are just checking that Drupal denies adding
    ...    this user again.
    Add Member    johndoe    johndoe@foo.com    bigsecret    exit_on_failure=${false}

Removing these members

The suite from the file removemembers.robot removes the member previously added in various fashions.

*** Settings ***
Documentation     Remove members added by the addmembers.robot suite
Resource          resources.robot
Library           Selenium2Library
Library           DrupalLibrary    ${HOME URL}

*** Test Cases ***
Open Home Page
    Open Browser    ${HOME URL}    ${BROWSER}
    Maximize Browser Window

Signing In
    Sign In    ${WM NAME}    ${WM PASS}    stop_on_failure=${false}

Removing Some Members
    Comment    Remove completely member johndoe
    Remove Member    johndoe    policy=user_cancel_delete
    Comment    Blockin member janedoe with default behaviour
    Remove Member    janedoe
    Comment    Blockin member foobar and reassign its content
    Remove Member    foobar    policy=user_cancel_reassign

Attempt to remove a unknown user
    Comment    We know this will fail
    Remove Member    nosuchanuser    exit_on_failure=${false}

Running the demos

Attention

Don’t forget to activate your robots virtualenv before running these commands. See the Installation chapter.

The test suite targets a public Drupal 7 demo site. You may prefer using your own development site changing the variables $HOME URL alongside with $WM NAME (the username of an administrator) and $WM PASS (his password).

Of course you start with addmembers.robot :

(robots)$ cd demos
(robots)$ pybot addmember.robot
==============================================================================
Addmembers :: Adding members to the Drupal demo site
==============================================================================
Open Home Page                                                        | PASS |
------------------------------------------------------------------------------
Signing In                                                            | PASS |
------------------------------------------------------------------------------
Adding Some Members                                                   | PASS |
------------------------------------------------------------------------------
Attempt To Duplicate A Member :: We know johndoe is already regist... | FAIL |
Something went wrong when creating user johndoe. (Have been waiting for 5 seconds)
------------------------------------------------------------------------------
Addmembers :: Adding members to the Drupal demo site                  | FAIL |
4 critical tests, 3 passed, 1 failed
4 tests total, 3 passed, 1 failed
==============================================================================
Output:  /Users/glenfant/projets/robotframework-drupallibrary/demos/output.xml
Log:     /Users/glenfant/projets/robotframework-drupallibrary/demos/log.html
Report:  /Users/glenfant/projets/robotframework-drupallibrary/demos/report.html

The console log reports briefly the test session in log.html and report.html.

:file`report.html` provides a per suite summary of the run. Links are provided :to the details published in log.html.

You can notice that the failure details in log.html shows the browser screenshot at the moment of the failure.

In addition an file named output.xml is issued by the session. It carries the equivalent informations of the ones provided by report.html you can parse in a custom QA application.

Note

output.xml is not suitable to Jenkins PIC. Use the --xunit option to provide a Jenkins suitable report file.

Type rebot –help to display some usages of this output.xml file.

Now let’s remove our users:

(robots)$ pybot removemembers.robot
==============================================================================
Removemembers :: Remove members added by the addmembers.robot suite
==============================================================================
Open Home Page                                                        | PASS |
------------------------------------------------------------------------------
Signing In                                                            | PASS |
------------------------------------------------------------------------------
Removing Some Members                                                 | PASS |
------------------------------------------------------------------------------
Attempt to remove a unknown user                                      | FAIL |
KeywordError: It seems there is no user named nosuchanuser
------------------------------------------------------------------------------
Removemembers :: Remove members added by the addmembers.robot suite   | FAIL |
4 critical tests, 3 passed, 1 failed
4 tests total, 3 passed, 1 failed
==============================================================================
Output:  /Users/glenfant/projets/robotframework-drupallibrary/demos/output.xml
Log:     /Users/glenfant/projets/robotframework-drupallibrary/demos/log.html
Report:  /Users/glenfant/projets/robotframework-drupallibrary/demos/report.html

As in the previous session new output.xml, log.html and report.html files have been created. Comments about these files are superfluous since the above discussion says all at that level.