Robot Framework is a generic open source automation framework. It can be used for test automation and robotic process automation (RPA).
Install python 3:
$ brew install python3
verify python version:
$ python3 --version
Install Robot Framework:
$ pip3 install robotframework
Install Selenium library:
$ pip3 install robotframework-seleniumlibrary
Install geckodriver for firefox:
$ brew install geckodriver
Install chromedriver:
$ brew install --cask chromedriver
if you are using MAC and you get error: "chromedriver cannot be opened because the developer cannot be verified"
Allow execution:
$ cd /usr/local/Caskroom/chromedriver/<version>/ && xattr -d com.apple.quarantine chromedriver
Install python3: Download and install python 3 software from python website Check "Add Python to PATH" during installation
Check python and pip installation from command line:> python --version && pip --version
Install robot framework:
> pip install robotframework
Check robot framework installation:
> robot --version
Robot Framework can be used on multiple different testing scenarios:
Let's create simple testcase for web testing. You can get it also from here
*** Settings ***
Documentation Example testcase 1: Robot Framework with SeleniumLibrary
Library SeleniumLibrary*** Variables ***${LOGIN URL} https://www.google.com${BROWSER} Chrome${TITLE} Google*** Test Cases ***Example 1[Documentation] open webpage and verify page titleOpen Browser To Search PageVerify Page Title[Teardown] Close Browser*** Keywords ***Open Browser To Search PageOpen Browser ${LOGIN URL} ${BROWSER}Verify Page TitleTitle Should Be ${TITLE}
execute testcase:
$ robot -d /tmp example1.robot
==============================================================================
Example1 :: Example testcase 1: use SeleniumLibrary and Robot Framework for...
==============================================================================
Example 1 :: open webpage and verify page title | PASS |
------------------------------------------------------------------------------
Example1 :: Example testcase 1: use SeleniumLibrary and Robot Fram... | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: /tmp/output.xml
Log: /tmp/log.html
Report: /tmp/report.html
On testcase we launch browser (chrome) on https://www.google.com and verify that page title is Google
SeleniumLibrary uses the Selenium WebDriver modules internally to control a web browser. All keywords in SeleniumLibrary that need to interact with an element on a web page take an argument typically named locators that specifies how to find the element. SeleniumLibrary supports finding elements based on the element id, XPath expressions, or CSS selectors
Few examples below or see this testcase
Input Text username ${USERNAME} # locator with id called usernamr
Input Text class=usernameclass ${USERNAME} # locator with class name usernameclass
Input Text //*[@class='usernameclass'] ${USERNAME} # locator with xpath, use class
Input Text //input[contains(@name,'passw')] ${USERNAME} # xpath locator with partial name
Click Button //*[@type='submit' or @name='reset'] ${USERNAME}
# xpath identifies the elements whose single or both conditions are true
Nice - with selenium web testing is easy. Let's check how to test REST API. Example is also here. First install REST library for robot. RESTinstance is great library for API testing. See RESTinstance documentation
$ pip3 install RESTinstance # install RESTinstancerobot library
*** Settings ***
Documentation EXAMPLE REST testcase
Library REST https://jsonplaceholder.typicode.com*** Variables ***
${EXPECTED_ID} 1
${EXPECTED_NAME} Leanne Graham
${EXPECTED_USERNAME} Bret*** Test Cases ***
GET USER VALIDATE ID, NAME AND USERNAME
GET /users/1 # new instance
Output schema response body # this will print out response
Object response body # values are fully optional
Integer response body id ${EXPECTED_ID} # verify id value
String response body name ${EXPECTED_NAME} # verify name value
String response body username ${EXPECTED_USERNAME} # verify username
execute testcase:
$ robot -d /tmp rest.robot![]()
REST api testcase: GET REST api (https://jsonplaceholder.typicode.com) and validate id, name and username values. Testcase passed.
With Robot Framework and Appium you can test iOS and Android mobile applications. Install Appium and appium library for robot
$ npm install -g appium
$ pip3 install robotframework-appiumlibrary
Connect Android device and start appium service:
$ appium
# Example Robot Framework code for mobile
*** Settings ***
Library AppiumLibrary
*** Test Cases ***
Open Application On Android Device
Open Application http://localhost:4723 udid=< your deviceid here > platformName=Android deviceName=AndroidDevice app=app.example.com appActivity= com.example.com.MainActivity[Teardown] Close Application
now run testcase:
$ robot -d /tmp mobile.robot
Mobile eexample testcase launches and closes application (app.example.com) on mobile device.
With Robot Framework and DatabaseLibrary you can for example query database table content after browser connection. Install required libraries with pip:
$ pip3 install robotframework-databaselibrary
$ pip3 install pymysql
*** Settings ***Library DatabaseLibrary*** Variables ***
${DBNAME} customers
${DBUSER} root
${DBPASSWD} example
${DBHOST} localhost
${DBPORT} 3306
${DBTABLE} customer
${DBMODULE} pymysql
@{QUERY RESULTS}*** Test Cases ***
Verify Table On Database
Connect To Database ${DBMODULE} ${DBNAME} ${DBUSER} ${DBPASSWD} ${DBHOST} ${DBPORT}
Table Must Exist ${DBTABLE}
Check If Exists In Database SELECT * FROM ${DBTABLE}
@{queryResults} Query SELECT * FROM ${DBTABLE}
Log to console @{QUERY RESULTS}[0]
now execute testcase:
$ robot -d /tmp db.robot
Test connects to database, verifies customer table and queries data
With Robot Framework and RequestsLibrary you can utilize HTTP client with keywords. Install required library with pip:
$ python3 -m pip install robotframework-requests
example code:
execute testcase:
$ robot -d /tmp requests.robot
Test executes GET request to api.github, verifies that connection succeeded and response contains text SaaristoAntti