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.
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
--processeswith the same amount as your TestingBot plan allows (parallel test sessions). - Consider using
--processtimeoutto 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.