Introduction to Robot Framework and
Selenium2Library
Krishantha Samaraweera
WSO2 Inc.
Agenda
● Introduction to Robot
● Hello World Demo
● What is Selenium2library
● Ride IDE
● Maven and Ant plugin
● Demo time Again
Introduction
● Generic Test Automation Framework
● Keyword Driven Development
● Open source
○ Apache 2.0 License
○ Sponsored by Nokia Siemens networks and It was created by
Pekka Klärck as part of his master's thesis
● Based on Python
○ Can be extended using java or Python
○ Support for jython and ironPython
● Active Developer Community
● Hosted on Google code but moving to GIT now.
Demo - Hello World
image source : http://midches.com/for-customers/training-centers/
Installation on Linux
● Intall PIP
easy_install pip
● Install Python
pip install python
● Install Jyton (Optinal)
sudo apt-get install jython
● Install robot framework
pip install robotframework | easy_install robotframework
● Install ride (The IDE for robot test case writing)
pip install robotframework-ride | easy_install robotframework-ride
● Install Selenium2Library - Selenium implementation compatible with robot
pip install robotframework-selenium2library |
easy_install robotframework-selenium2library
Installation on Windows
- Windows Installer
● Separate graphical installers for 32 bit and 64 bit Windows systems
● robotframework-<version>.win-amd64.exe
- Stand-alone JAR package
● Robot Framework is also available as a stand-alone robotframework.
jar package.
● This package contains Jython and thus requires only JVM
○ java -jar robotframework.jar run [options] data_sources
- Use Python package installers
- Install from Source
Support for different runtimes
Environment Command
Python pybot
Jython jybot
Iron Python ipybot
Test Structure
Selenium Keyword
Open Browser <url> <browser>
Input Text <locator>
Click Button <locator>
Click Link
Close Browser
More Keywords
Add Cookie · Alert Should Be Present · Assign Id To Element · Capture Page Screenshot · Checkbox Should Be Selected · Checkbox Should Not
Be Selected ·Choose Cancel On Next Confirmation · Choose File · Choose Ok On Next Confirmation · Click Button · Click Element · Click Element
At Coordinates · Click Image · Click Link ·Close All Browsers · Close Browser · Close Window · Confirm Action · Create Webdriver · Current Frame
Contains · Current Frame Should Not Contain · Delete All Cookies ·Delete Cookie · Double Click Element · Drag And Drop · Drag And Drop By
Offset · Element Should Be Disabled · Element Should Be Enabled · Element Should Be Visible ·Element Should Contain · Element Should Not Be
Visible · Element Text Should Be · Execute Async Javascript · Execute Javascript · Focus · Frame Should Contain ·Get Alert Message · Get All
Links · Get Cookie Value · Get Cookies · Get Element Attribute · Get Horizontal Position · Get List Items · Get Location · Get Matching Xpath
Count ·Get Selected List Label · Get Selected List Labels · Get Selected List Value · Get Selected List Values · Get Selenium Implicit Wait · Get
Selenium Speed · Get Selenium Timeout ·Get Source · Get Table Cell · Get Text · Get Title · Get Value · Get Vertical Position · Get Window
Identifiers · Get Window Names · Get Window Size · Get Window Titles · Go Back ·Go To · Input Password · Input Text · List Selection Should Be ·
List Should Have No Selections · Location Should Be · Location Should Contain · Log Location · Log Source · Log Title ·Maximize Browser
Window · Mouse Down · Mouse Down On Image · Mouse Down On Link · Mouse Out · Mouse Over · Mouse Up · Open Browser · Open Context
Menu ·Page Should Contain · Page Should Contain Button · Page Should Contain Checkbox · Page Should Contain Element · Page Should
Contain Image · Page Should Contain Link ·Page Should Contain List · Page Should Contain Radio Button · Page Should Contain Textfield · Page
Should Not Contain · Page Should Not Contain Button ·Page Should Not Contain Checkbox · Page Should Not Contain Element · Page Should Not
Contain Image · Page Should Not Contain Link · Page Should Not Contain List ·Page Should Not Contain Radio Button · Page Should Not Contain
Textfield · Press Key · Radio Button Should Be Set To · Radio Button Should Not Be Selected ·Register Keyword To Run On Failure · Reload
Page · Select All From List · Select Checkbox · Select Frame · Select From List · Select From List By Index · Select From List By Label ·Select
From List By Value · Select Radio Button · Select Window · Set Browser Implicit Wait · Set Selenium Implicit Wait · Set Selenium Speed · Set
Selenium Timeout ·Set Window Size · Simulate · Submit Form · Switch Browser · Table Cell Should Contain · Table Column Should Contain ·
Table Footer Should Contain · Table Header Should Contain ·Table Row Should Contain · Table Should Contain · Textarea Should Contain ·
Textarea Value Should Be · Textfield Should Contain · Textfield Value Should Be · Title Should Be ·Unselect Checkbox · Unselect Frame ·
Unselect From List · Unselect From List By Index · Unselect From List By Label · Unselect From List By Value · Wait For Condition ·Wait Until
Element Is Visible · Wait Until Page Contains · Wait Until Page Contains Element · Xpath Should Match X Times
http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.
html
Tabular Format
● Simple tabular format
Robot Standard Libraries
● Included in normal installation
○ Operating System
○ Screenshot
○ Dialog
○ Telnet
○ XML
○ String
○ Process
○ Remote
Robot External Libraries
● Not Included in normal installation. Need to install
separately.
○ Selenium2Library
○ HTTP
○ Android
○ MongoDB
○ iOS
○ SSH
○ Database
○ AutoItLibrary
Page Should Contain Google
One Spacebar
Be Careful
Four Spacebars
Selenium2Library
● Web Testing Library for Robot Framework.
● Runs on Real Browser instance.
● InBuild API keywords for easy usage.
Selenium2Library Vs Webdriver API
Selenium 2 Webdriver Iterating Table
C# Example
public void VerifyTable(string header, string expected)
{
IWebElement table = _driverWithJs.FindElement(By.XPath("//div[@id='main']/table"));
ReadOnlyCollection<IWebElement> allRows = table.FindElements(By.TagName("tr"));
for (int z = 0; z < allRows.Count; z++)
{
ReadOnlyCollection<IWebElement> cells = allRows[z].FindElements(By.TagName("td"));
for (int y = 0; y < cells.Count; y++)
{
var value = allRows[z].FindElements(By.TagName("td"))[y].Text;
if (value.Equals(header))
{
Assert.AreEqual(expected, allRows[z].FindElements(By.TagName("td"))[y + 1].Text);
}
}
}
}
Robot keyword for Iterating Table
Table Should Contain table_locator, expected, loglevel=INFO
Selenium2Library
● Lookup Strategy
Test Data Editor - RIDE
Custom Keyword Library
Image source : http://midches.com/for-customers/training-centers/
Maven Plugin
● Robot Framework in a Maven project without the need to
install anything extra.
<plugin>
<groupId>org.robotframework</groupId>
<artifactId>robotframework-maven-plugin</artifactId>
<version>1.4.2</version>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Ant Task
● RobotAnt is a ant task for using robotframework inside
ant build scripts.
<robotant
data_sources="TestSelenium.html"
loglevel="INFO"
debugfile="jybot.log"
outputdir="results"
maxmemory="512m">
<classpath>
<pathelement location="libext/robotframework-2.5.5.jar"/>
<pathelement location="lib/Lib"/>
</classpath>
</robotant>
External variable files
● External file to declare variables.
● To follow DRY (Don’t repeat yourself)
● Can be created in python or java files.
*** Variables ***
${Weather} London Cloudy 25
${humidity} 75
${MARKS} 65.5
@{DAYS} Monday Wednesday Friday
Sunday
For more information
● The main information hub http://robotframework.org
● Quick Start Guide
– Executable guide demonstrating the key features
– http://code.google.com/p/robotframework/wiki/QuickStartGuide
● User Guide
– Detailed information about all features of the framework
– http://code.google.com/p/robotframework/wiki/UserGuide
Questions?
Thanks!
Image source : http://ciprianocounseling.com/frequently-asked-questions/

Robot framework and selenium2 library

  • 1.
    Introduction to RobotFramework and Selenium2Library Krishantha Samaraweera WSO2 Inc.
  • 2.
    Agenda ● Introduction toRobot ● Hello World Demo ● What is Selenium2library ● Ride IDE ● Maven and Ant plugin ● Demo time Again
  • 3.
    Introduction ● Generic TestAutomation Framework ● Keyword Driven Development ● Open source ○ Apache 2.0 License ○ Sponsored by Nokia Siemens networks and It was created by Pekka Klärck as part of his master's thesis ● Based on Python ○ Can be extended using java or Python ○ Support for jython and ironPython ● Active Developer Community ● Hosted on Google code but moving to GIT now.
  • 4.
    Demo - HelloWorld image source : http://midches.com/for-customers/training-centers/
  • 5.
    Installation on Linux ●Intall PIP easy_install pip ● Install Python pip install python ● Install Jyton (Optinal) sudo apt-get install jython ● Install robot framework pip install robotframework | easy_install robotframework ● Install ride (The IDE for robot test case writing) pip install robotframework-ride | easy_install robotframework-ride ● Install Selenium2Library - Selenium implementation compatible with robot pip install robotframework-selenium2library | easy_install robotframework-selenium2library
  • 6.
    Installation on Windows -Windows Installer ● Separate graphical installers for 32 bit and 64 bit Windows systems ● robotframework-<version>.win-amd64.exe - Stand-alone JAR package ● Robot Framework is also available as a stand-alone robotframework. jar package. ● This package contains Jython and thus requires only JVM ○ java -jar robotframework.jar run [options] data_sources - Use Python package installers - Install from Source
  • 7.
    Support for differentruntimes Environment Command Python pybot Jython jybot Iron Python ipybot
  • 8.
  • 9.
    Selenium Keyword Open Browser<url> <browser> Input Text <locator> Click Button <locator> Click Link Close Browser
  • 10.
    More Keywords Add Cookie· Alert Should Be Present · Assign Id To Element · Capture Page Screenshot · Checkbox Should Be Selected · Checkbox Should Not Be Selected ·Choose Cancel On Next Confirmation · Choose File · Choose Ok On Next Confirmation · Click Button · Click Element · Click Element At Coordinates · Click Image · Click Link ·Close All Browsers · Close Browser · Close Window · Confirm Action · Create Webdriver · Current Frame Contains · Current Frame Should Not Contain · Delete All Cookies ·Delete Cookie · Double Click Element · Drag And Drop · Drag And Drop By Offset · Element Should Be Disabled · Element Should Be Enabled · Element Should Be Visible ·Element Should Contain · Element Should Not Be Visible · Element Text Should Be · Execute Async Javascript · Execute Javascript · Focus · Frame Should Contain ·Get Alert Message · Get All Links · Get Cookie Value · Get Cookies · Get Element Attribute · Get Horizontal Position · Get List Items · Get Location · Get Matching Xpath Count ·Get Selected List Label · Get Selected List Labels · Get Selected List Value · Get Selected List Values · Get Selenium Implicit Wait · Get Selenium Speed · Get Selenium Timeout ·Get Source · Get Table Cell · Get Text · Get Title · Get Value · Get Vertical Position · Get Window Identifiers · Get Window Names · Get Window Size · Get Window Titles · Go Back ·Go To · Input Password · Input Text · List Selection Should Be · List Should Have No Selections · Location Should Be · Location Should Contain · Log Location · Log Source · Log Title ·Maximize Browser Window · Mouse Down · Mouse Down On Image · Mouse Down On Link · Mouse Out · Mouse Over · Mouse Up · Open Browser · Open Context Menu ·Page Should Contain · Page Should Contain Button · Page Should Contain Checkbox · Page Should Contain Element · Page Should Contain Image · Page Should Contain Link ·Page Should Contain List · Page Should Contain Radio Button · Page Should Contain Textfield · Page Should Not Contain · Page Should Not Contain Button ·Page Should Not Contain Checkbox · Page Should Not Contain Element · Page Should Not Contain Image · Page Should Not Contain Link · Page Should Not Contain List ·Page Should Not Contain Radio Button · Page Should Not Contain Textfield · Press Key · Radio Button Should Be Set To · Radio Button Should Not Be Selected ·Register Keyword To Run On Failure · Reload Page · Select All From List · Select Checkbox · Select Frame · Select From List · Select From List By Index · Select From List By Label ·Select From List By Value · Select Radio Button · Select Window · Set Browser Implicit Wait · Set Selenium Implicit Wait · Set Selenium Speed · Set Selenium Timeout ·Set Window Size · Simulate · Submit Form · Switch Browser · Table Cell Should Contain · Table Column Should Contain · Table Footer Should Contain · Table Header Should Contain ·Table Row Should Contain · Table Should Contain · Textarea Should Contain · Textarea Value Should Be · Textfield Should Contain · Textfield Value Should Be · Title Should Be ·Unselect Checkbox · Unselect Frame · Unselect From List · Unselect From List By Index · Unselect From List By Label · Unselect From List By Value · Wait For Condition ·Wait Until Element Is Visible · Wait Until Page Contains · Wait Until Page Contains Element · Xpath Should Match X Times http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library. html
  • 11.
  • 12.
    Robot Standard Libraries ●Included in normal installation ○ Operating System ○ Screenshot ○ Dialog ○ Telnet ○ XML ○ String ○ Process ○ Remote
  • 13.
    Robot External Libraries ●Not Included in normal installation. Need to install separately. ○ Selenium2Library ○ HTTP ○ Android ○ MongoDB ○ iOS ○ SSH ○ Database ○ AutoItLibrary
  • 14.
    Page Should ContainGoogle One Spacebar Be Careful Four Spacebars
  • 15.
    Selenium2Library ● Web TestingLibrary for Robot Framework. ● Runs on Real Browser instance. ● InBuild API keywords for easy usage.
  • 16.
    Selenium2Library Vs WebdriverAPI Selenium 2 Webdriver Iterating Table C# Example public void VerifyTable(string header, string expected) { IWebElement table = _driverWithJs.FindElement(By.XPath("//div[@id='main']/table")); ReadOnlyCollection<IWebElement> allRows = table.FindElements(By.TagName("tr")); for (int z = 0; z < allRows.Count; z++) { ReadOnlyCollection<IWebElement> cells = allRows[z].FindElements(By.TagName("td")); for (int y = 0; y < cells.Count; y++) { var value = allRows[z].FindElements(By.TagName("td"))[y].Text; if (value.Equals(header)) { Assert.AreEqual(expected, allRows[z].FindElements(By.TagName("td"))[y + 1].Text); } } } } Robot keyword for Iterating Table Table Should Contain table_locator, expected, loglevel=INFO
  • 17.
  • 18.
  • 19.
    Custom Keyword Library Imagesource : http://midches.com/for-customers/training-centers/
  • 20.
    Maven Plugin ● RobotFramework in a Maven project without the need to install anything extra. <plugin> <groupId>org.robotframework</groupId> <artifactId>robotframework-maven-plugin</artifactId> <version>1.4.2</version> <executions> <execution> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin>
  • 21.
    Ant Task ● RobotAntis a ant task for using robotframework inside ant build scripts. <robotant data_sources="TestSelenium.html" loglevel="INFO" debugfile="jybot.log" outputdir="results" maxmemory="512m"> <classpath> <pathelement location="libext/robotframework-2.5.5.jar"/> <pathelement location="lib/Lib"/> </classpath> </robotant>
  • 22.
    External variable files ●External file to declare variables. ● To follow DRY (Don’t repeat yourself) ● Can be created in python or java files. *** Variables *** ${Weather} London Cloudy 25 ${humidity} 75 ${MARKS} 65.5 @{DAYS} Monday Wednesday Friday Sunday
  • 23.
    For more information ●The main information hub http://robotframework.org ● Quick Start Guide – Executable guide demonstrating the key features – http://code.google.com/p/robotframework/wiki/QuickStartGuide ● User Guide – Detailed information about all features of the framework – http://code.google.com/p/robotframework/wiki/UserGuide
  • 24.
    Questions? Thanks! Image source :http://ciprianocounseling.com/frequently-asked-questions/