Skip to main content

Robot Framework Automated WebDriver Testing

See our Robot Framework example repository for a first example on how to run Robot Framework tests on TestingBot.

With SeleniumLibrary you can run WebDriver tests with Robot Framework.
Robot Framework is a test automation framework to run acceptance tests.

The Robot test framework allows you to build easy to read test cases, using keyword driven and behavior-driven approaches.
The framework provides reports, in HTML format.

Setting up Robot Framework

Make sure you've installed pip, then install the necessary libraries:

pip install robotframework-seleniumlibrary requests

Running your first test

Below is an example on how to run a simple test on Chrome. When the test has finished, the test name and success state is sent to TestingBot so you can see the test success/failures in our dashboard.

Save the example below in a test.robot file:

*** Settings ***

Library  SeleniumLibrary
Library  TestingBot

Test Setup  Open test browser
Test Teardown  Close test browser

*** Variables ***

${CREDENTIALS}  key:secret

*** Test Cases ***

Simple Test
    Go to  https://www.google.com
    Page should contain  Google

*** Keywords ***

Open test browser
    Open browser  about:  chrome
    ...  remote_url=http://${CREDENTIALS}@hub.testingbot.com/wd/hub
    ...  desired_capabilities=browserName:${BROWSER},browserVersion:${VERSION},platformName:${PLATFORM}

Close test browser
    Report TestingBot status
    ...  ${SUITE_NAME} | ${TEST_NAME}
    ...  ${TEST_STATUS}  ${CREDENTIALS}
    Close all browsers

Save the code below in a TestingBot.py file:

import requests
from robot.libraries.BuiltIn import BuiltIn

def report_testingbot_status(name, status, credentials):
    selenium = BuiltIn().get_library_instance('SeleniumLibrary')
    session_id = selenium.driver.session_id

    payload = {'test[name]': name, 'test[success]': int(status == 'PASS')}
    key, secret = credentials.split(':')

    url = f'https://api.testingbot.com/v1/tests/{session_id}'
    response = requests.put(url, data=payload, auth=(key, secret))
    assert response.status_code == 200, response.text

To run the test, run this command:

PYTHONPATH=$PYTHONPATH:. robot --variable BROWSER:chrome --variable VERSION:latest --variable PLATFORM:WIN11 test.robot

Once the test finished running, you should see it in the member dashboard. Use the variables to run the test on different platforms/browsers/versions.

*** Settings ***

Library  SeleniumLibrary
Library  TestingBot
Library  BrowserOptions

Test Setup  Open test browser
Test Teardown  Close test browser

*** Test Cases ***

Simple Test
    Go to  https://www.google.com
    Page should contain  Google

*** Keywords ***

Open test browser
    ${options}=    Get Browser Options    ${BROWSER}

    # Set capabilities
    Call Method    ${options}    set_capability    platformName    ${PLATFORM}
    Call Method    ${options}    set_capability    browserName    ${BROWSER}
    Call Method    ${options}    set_capability    browserVersion    ${VERSION}

    # Set custom TestingBot capabilities using tb:options
    ${tb_options}=    Create Dictionary    key=${TB_KEY}    secret=${TB_SECRET}    name=test    build=MyTestBuild
    Call Method    ${options}    set_capability    tb:options    ${tb_options}

    # Open browser with options
    Open Browser    remote_url=https://hub.testingbot.com/wd/hub    options=${options}

Close test browser
    Report TestingBot status
    ...  ${SUITE_NAME} | ${TEST_NAME}
    ...  ${TEST_STATUS}  ${TB_KEY}:${TB_SECRET}
    Close all browsers

Save the code below in a TestingBot.py file:

import requests
from robot.libraries.BuiltIn import BuiltIn

def report_testingbot_status(name, status, credentials):
    selenium = BuiltIn().get_library_instance('SeleniumLibrary')
    session_id = selenium.driver.session_id

    payload = {'test[name]': name, 'test[success]': int(status == 'PASS')}
    key, secret = credentials.split(':')

    url = f'https://api.testingbot.com/v1/tests/{session_id}'
    response = requests.put(url, data=payload, auth=(key, secret))
    assert response.status_code == 200, response.text

Now we'll need to specify the multiple browser options in a file called BrowserOptions.py:

from selenium.webdriver import ChromeOptions, FirefoxOptions, EdgeOptions, SafariOptions

def get_browser_options(browser):
    if browser.lower() == 'chrome':
        return ChromeOptions()
    elif browser.lower() == 'firefox':
        return FirefoxOptions()
    elif browser.lower() == 'edge':
        return EdgeOptions()
    elif browser.lower() == 'safari':
        return SafariOptions()
    else:
        raise ValueError(f"Unsupported browser: {browser}")

To run the test, run this command:

PYTHONPATH=$PYTHONPATH:. robot --variable BROWSER:chrome --variable VERSION:latest --variable PLATFORM:WIN11 --variable TB_KEY:API_KEY --variable TB_SECRET:API_SECRET test.robot

Once the test finished running, you should see it in the member dashboard. Use the variables to run the test on different platforms/browsers/versions.

Specifying the operating system, browser and version

To let TestingBot know on which browser/platform you want to run your test on, you need to specify the browsername, version, OS and other optional options in the capabilities field.

desired_capabilities=browserName:${BROWSER},browserVersion:${VERSION},platformName:${PLATFORM}

To see how to do this, please select a combination of browser, version and platform in the drop-down menus below.

Testing Internal Websites

We've built TestingBot Tunnel, to provide you with a secure way to run tests against your staged/internal webapps.
Please see our TestingBot Tunnel documentation for more information about this easy to use tunneling solution.

The example below shows how to easily run a Robot Framework test with our Tunnel:

1. Download our tunnel and start the tunnel:

java -jar testingbot-tunnel.jar key secret

2. Adjust your test: instead of pointing to 'hub.testingbot.com/wd/hub' like the example above - change it to point to your tunnel's IP address.
Assuming you run the tunnel on the same machine you run your tests, change to 'localhost:4445/wd/hub'. localhost is the machine running the tunnel, 4445 is the default port of the tunnel.

This way your test will go securely through the tunnel to TestingBot and back.

Parallel Testing

You can run multiple Robot Framework tests in parallel by using the Pabot library.

First install Pabot using pip:

pip install -U robotframework-pabot

Then run your tests using the pabot command instead of robot:

PYTHONPATH=. pabot --processes 2 --loglevel TRACE --variable BROWSER:chrome --variable VERSION:latest --variable PLATFORM:WIN11 --variable TB_KEY:API_KEY --variable TB_SECRET:API_SECRET test.robot

Some recommendations when running tests in parallel:

  • Make sure each test case is independent and does not rely on shared state.
  • Specify the --processes with the same amount as your TestingBot plan allows (parallel test sessions).
  • Consider using --processtimeout to set a timeout for each process.

Queuing

Every plan we provide comes with a limit of parallel tests.
If you exceed the number of parallel tests assigned to your account, TestingBot will queue the additional tests (for up to 6 minutes) and run the tests as soon as slots become available.

Mark tests as passed/failed

As TestingBot has no way to determine whether your test passed or failed (it is determined by your business logic), we offer a way to send the test status back to TestingBot. This is useful if you want to see if a test succeeded or failed from the TestingBot member area.

You can use our Python API client to report back test results.

from testingbotclient import TestingBotClient

client = TestingBotClient('API_KEY', 'API_SECRET')
client.tests.update_test(
    driver.session_id,
    name='My Test',
    passed=True,
    build='build-123'
)

Other Python Framework examples

  • PyTest

    PyTest makes it easy to run Selenium tests with Python.

  • Behave

    Behave is behaviour-driven development, Python style.

  • Lettuce

    Lettuce is a Python BDD plugin based on Ruby's Cucumber, offering Gherkin stories.

  • PyUnit

    PyUnit is the standard unit testing framework module for Python, described as a Python version of JUnit.

  • Helium

    Helium is a tool that makes it easy to test websites and automate browsers.

  • Pylenium

    Pylenium brings the best of Selenium, Cypress and Python into one package.

  • SeleniumBase

    SeleniumBase is a Python package that simplifies Selenium testing.

Was this page helpful?

Looking for More Help?

Have questions or need more information?
You can reach us via the following channels: