Print

Selenium Robot Framework Introduction

Robot Framework is a generic test automation framework for acceptance testing and acceptance test-driven development (ATDD). It has easy-to-use tabular test data syntax and it utilizes the keyword-driven testing approach. Its testing capabilities can be extended by test libraries implemented either with Python or Java, and users can create new higher-level keywords from existing ones using the same syntax that is used for creating test cases. (Source: http://robotframework.org/).

 

Robot framework project is hosted on Google code, where users can find technical documentation and source code. Robot framework Python language bindings are hosted at Pypi

Robot framework has following features:

Print

Selenium Robot Framework Installation with Python

To use Robot Framework with Python, you need to install Python, robot framework, Selenium2Library and other supporting libraries. 

 

Step 1: Install Python 2.7 version

        Before installing Robot Framework, you need to install Python 2.5 or later. Robot Framework has not been updated to work with Python 3 or above, so you should certainly install Python 2.7 version. Visit the link to download and install Python 2.7 version. After installing Python 2.7, add your python installation to your system environment path. 

on Windows, add "c:\Python27\;c:\Python27\Scripts\;" to your path. On Windows vista or Windows 7 environment, it is recommended to install Python to all users, and to run the installation as an administrator. After installing, you can confirm python installation with the command below. 

Print

Selenium Robot Framework Python Test Case with RIDE

In this example, you will learn how to use RIDE in Selenium Robot Framework Python test automation. 

Test Case: authorized users are able to login Mahara Demo site. Here are test steps.

 

1. Navigate to demo.mahara.org and verify that web page title "Home-Mahara" displays.

2. Enter "student2" in the Username filed.

3. Enter "Testing1" in the Password field.

4. Click on the Login button

5. Assert that Dashboard Title is "Dashboard - Mahara".

Note: if the above username and password do not work, try registering one and use your own user account for testing because the demo user password may have been changed by others.

Selenium Python Robot Framework Implementation

Print

Page Object Model in Selenium Robot Framework Python

In this example, you will learn how to use Page Object Model in Selenium Robot Framework Python test automation. We use RIDE to create Site Element resource file and Test Case. For RIDE example, please see other articles in this category. 

 

Test Case: authorized users are able to login Mahara Demo site. Here are test steps.

1. Navigate to demo.mahara.org and verify that web page title "Home-Mahara" displays.

2. Enter "student2" in the Username filed.

3. Enter "Testing1" in the Password field.

4. Click on the Login button

5. Assert that Dashboard Title is "Dashboard - Mahara".

Note: if the above username and password do not work, try registering one and use your own user account for testing because the demo user password may have been changed by others.

Selenium Python Robot Framework Implementation with Page Object Model

Print

Selenium Robot Framework Element Locator

Locating elements on the website under test is very important for all keywords in Selenium2Library to interact with the element. In general, finding an element on the page take an argument, locator. By default, when a locator is provided, it is matched against the key attribute of the particular element type. For example, id and name are key attribute to all elements, and locating elements is easy using just the id as a locator. 

 

When id or name is not present, Selenium2Library supports other strategies to locate the element. See the chart below for other strategies: 

Print

Robot Framework Selenium2Library Keywords

Selenium2Library is a web testing library for Robot Framework, and it runs tests in a real browser instance. It should work in most modern browsers and can be used with both Python and Jython interpreters. Before running tests that use Selenium2Library, Selenium2Library must be imported into your Robot test suite. Selenium2Library provides keywords to interact with cookies, web elements, browser windows and pages. Here is the full list of keywords in Selenium2Library.

Print

Selenium Robot Framework Python Cookie Example

In this example, you will learn how to use Selenium2Library to handle cookies in web application testing. Selenium2Library has keywords: Add Cookie, Delete All Cookie, Delete Cookie, Get Cookie Value, and Get Cookies.

 

Print

Selenium Robot Framework Alert Example

In this example, you will learn how to use Selenium2Library to handle Alerts in web application testing. Selenium2Library has keywords: Alert Should Be Present and Get Alert Message.

 

Print

Selenium Robot Framework Assign Element Id

In this example, you will learn how to use Selenium2Library to handle web elements with no Id or with dynamic locators in web application testing. Selenium2Library has keywords: Assign Id To Element. This keyword is very important if you need to define static id to elements that has very dynamic value or no id locator.

 

Print

Selenium Robot Framework Table Verification

In this example, you will learn how to use Selenium2Library to verify tables in web application testing.

 

Selenium2Library has keywords: Get Table Cell, Table Cell Should Contain, Table Column Should Contain, Table Footer Should Contain, Table Header Should Contain and etc. In this table below, we verify that the first cell (row id=1 , column id=1) contains text "Test Case ID".

Robot Framework Table Test

Test Case ID Application Module Test Result Tester
TestCase001 Sign Up Pass TesterA
TestCase002 Login Fail TesterB
TestCase003 Logout Did not run TesterC