Robot framework and selenium2 library

24
Introduction to Robot Framework and Selenium2Library Krishantha Samaraweera WSO2 Inc.

description

 

Transcript of Robot framework and selenium2 library

Page 1: Robot framework and selenium2 library

Introduction to Robot Framework and Selenium2Library

Krishantha SamaraweeraWSO2 Inc.

Page 2: Robot framework and selenium2 library

Agenda

● Introduction to Robot ● Hello World Demo

● What is Selenium2library

● Ride IDE

● Maven and Ant plugin

● Demo time Again

Page 3: Robot framework and selenium2 library

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.

Page 4: Robot framework and selenium2 library

Demo - Hello World

image source : http://midches.com/for-customers/training-centers/

Page 5: Robot framework and selenium2 library

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

Page 6: Robot framework and selenium2 library

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

Page 7: Robot framework and selenium2 library

Support for different runtimes

Environment Command

Python pybot

Jython jybot

Iron Python ipybot

Page 8: Robot framework and selenium2 library

Test Structure

Page 9: Robot framework and selenium2 library

Selenium Keyword

Open Browser <url> <browser>Input Text <locator>Click Button <locator>Click LinkClose Browser

Page 10: Robot framework and selenium2 library

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

Page 11: Robot framework and selenium2 library

Tabular Format

● Simple tabular format

Page 12: Robot framework and selenium2 library

Robot Standard Libraries

● Included in normal installation

○ Operating System ○ Screenshot○ Dialog○ Telnet○ XML○ String○ Process○ Remote

Page 13: Robot framework and selenium2 library

Robot External Libraries

● Not Included in normal installation. Need to install separately.

○ Selenium2Library○ HTTP○ Android○ MongoDB○ iOS○ SSH○ Database○ AutoItLibrary

Page 14: Robot framework and selenium2 library

Page Should Contain Google

One Spacebar

Be Careful

Four Spacebars

Page 15: Robot framework and selenium2 library

Selenium2Library

● Web Testing Library for Robot Framework.

● Runs on Real Browser instance.

● InBuild API keywords for easy usage.

Page 16: Robot framework and selenium2 library

Selenium2Library Vs Webdriver API

Selenium 2 Webdriver Iterating TableC# 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

Page 17: Robot framework and selenium2 library

Selenium2Library

● Lookup Strategy

Page 18: Robot framework and selenium2 library

Test Data Editor - RIDE

Page 19: Robot framework and selenium2 library

Custom Keyword Library

Image source : http://midches.com/for-customers/training-centers/

Page 20: Robot framework and selenium2 library

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>

Page 21: Robot framework and selenium2 library

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>

Page 22: Robot framework and selenium2 library

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

Page 23: Robot framework and selenium2 library

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

Page 24: Robot framework and selenium2 library

Questions?Thanks!

Image source : http://ciprianocounseling.com/frequently-asked-questions/