Features

Robot Framework Automated WebDriver Testing

See our RobotFramework example repository for a first example on how to run RobotFramework 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 to install the necessary libs:

Copy code
pip install robotframework-seleniumlibrary requests

Running your first test

Below is an example on how to run a simple test on Firefox. 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:

Copy code
*** 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:  firefox
	...  remote_url=http://${CREDENTIALS}@hub.testingbot.com/wd/hub
	...  desired_capabilities=browserName:${BROWSER},version:${VERSION},platform:${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:

Copy code
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 = 'https://api.testingbot.com/v1/tests/{0}'.format(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:

Copy code
PYTHONPATH=$PYTHONPATH:. robot --variable BROWSER:chrome --variable VERSION:latest --variable PLATFORM:MAC 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.

Copy code
*** 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    name=test    build=MyTestBuild
	Call Method    ${options}    set_capability    tb:options    ${tb_options}

	# Open browser with options
	Open Browser    remote_url=https://${TB_KEY}:${TB_SECRET}@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:

Copy code
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 = 'https://api.testingbot.com/v1/tests/{0}'.format(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:

Copy code
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:

Copy code
PYTHONPATH=$PYTHONPATH:. robot --variable BROWSER:chrome --variable VERSION:latest --variable PLATFORM:MAC --variable TB_KEY:<your TestingBot Key> --variable TB_SECRET:<your TestingBot 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.

Copy code
desired_capabilities=browserName:${BROWSER},version:${VERSION},platform:${PLATFORM}

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

Copy code