Vous êtes sur la page 1sur 33

Automating With! Robot Framework and Selenium 2 Library!

Eliza Leong QA Engineer Kiva Microfunds, San Francisco, CA Email: elizabeth@kiva.org

AGENDA

! ! ! !

Requirements Why Robot Framework? Typical challenges with Selenium2 Problems beyond Selenium2

!"#$"%&#%"'$"(&)#*+,-.&
! Kiva.org is a website which allows you to lend to an entrepreneur who needs a loan ! Through Kiva, you loan as little as $25 to an entrepreneur at 0% interest

REQUIREMENTS

! ! ! ! !

Cross-browser Navigate between different websites Salesforce, MySQL Free Active user community

WHY ROBOT FRAMEWORK

! Choices

OR

WHY ROBOT FRAMEWORK

! ! ! ! ! ! !

A generic test framework Open sourced by Nokia in 2008 https://code.google.com/p/robotframework/ Use keyword-driven approach Lots of built-in libraries Extensible via Python and Java Documentation (User Guide)

WHY ROBOT FRAMEWORK

! Extension: Selenium2Library ! Other extensions:


! Watir-robot ! SwingLibrary ! EclipseLibrary

WHY ROBOT FRAMEWORK

! Checklist of desired capabilities


! Logging ! Screen shots ! Reports ! Tagging

EXAMPLE: TEST CASE

You want to check if in an HTML table, cell A plus cell B equals cell C. Robots Selenium2 documentation says:

EXAMPLE: TEST SCRIPT


*** Settings *** Library Selenium2Library *** Testcases *** Addition Test Open Browser ${CURDIR}\\sample_table.html browser=firefox ${cell_A} Get Table Cell budget 2 1 loglevel=TRACE ${cell_B} Get Table Cell budget 2 2 ${expected_sum} Get Table Cell budget 2 3 ${actual_sum} Evaluate ${cell_A} + ${cell_B} Should Be Equal As Numbers ${expected_sum} ${actual_sum}

10

EXAMPLE: Output

Run the test: pybot.bat sample_test.txt 3 files are produced: log.html report.html output.xml

11

SAMPLE HTML TABLE

12

SAMPLE RUN

13

SAMPLE TEST CASE

14

SAMPLE REPORT.HTML

15

16

17

COMMON CHALLENGES WITH SELENIUM2

No locator Modal popups Waits and sleep Native OS popups Switching focus between windows

18

Selenium2Library: No element locator!


*** Settings *** Library Selenium2Library *** Testcases *** Addition Test Open Browser ${CURDIR}\\sample_table.html browser=firefox Assign Id to Element css=table temp_id ${cell_A} Get Table Cell temp_id 2 1 loglevel=TRACE ${cell_B} Get Table Cell temp_id 2 2 ${expected_sum} Get Table Cell temp_id 2 3 ${actual_sum} Evaluate ${cell_A} + ${cell_B} Should Be Equal As Numbers ${expected_sum} ${actual_sum}

19

Selenium2Library: Modal popups

! Modal popups ! WebDriverException: Message: ugetUrl execution failed; An open modal dialog blocked the operation

20

Selenium2Library: Popups

Dismiss alerts and confirmation popups with: ! Alert Should Be Present ! Confirm Action

21

Selenium2Library: Wait, Sleep

! ! ! ! !

Sleep Wait Until Page Contains Set Selenium Implicit Wait Set Selenium Timeout Set Browser Implicit Wait

22

Selenium2Library: window focus

! Click a link, it opens in a new tab or window


@{mywin} = Get Window Titles Select Window @{mywin}[1] Close Window Select Window @{mywin}[0]

23

PROBLEMS BEYOND Selenium2Library

! File upload
! Choose File keyword

24

PROBLEMS BEYOND Selenium2Library

Problem: File download native OS popup dialog! Solution: extend with python code Tip: read Python Tutorial for Robot Framework Test Library Developer
https://code.google.com/p/robotframework/wiki/PythonTutorial

25

PROBLEMS BEYOND Selenium2Library

! Security certificate errors on IE9/Win7

! Can see a link to click BUT selenium cant click it

26

PROBLEMS BEYOND Selenium2Library

Solution 1: AutoItLibrary ! This is a Robot Framework wrapper for AutoIt tool ! I didnt find the keyword I needed (like Click Link)

27

PROBLEMS BEYOND Selenium2Library

Solution #2: use AutoIt to build an exe


1.! Install AutoIt on Win7 2.! Write a native AutoIt script to open browser and click on the link 3.! Compile this script for 32/64 bit Win7 4.! Copy the .exe to robot suite of tests 5.! In robot test script, when you call Open Browser, when its IE you run this execute by calling Run

28

PROBLEMS BEYOND Selenium2Library

! How can I get to databases? Robotframework-database-library ! utilities... allow you to query your database after an action has been made to verify the results.

29

PROBLEMS BEYOND Selenium2Library

! How can I execute a shell script in the middle of my tests? robotframework-sshlibrary

30

PROBLEMS BEYOND Selenium2Library

! Continuous Integration with Jenkins


https://wiki.jenkins-ci.org/display/JENKINS/Robot+Framework+Plugin

! STEPS: 1.!Install plugin to Jenkins 2.!Decide where output files should live 3.!Write a shell script to kick off robot tests 4.!Configure frequency of job 5.!Build!

31

RESOURCES

! https://bitbucket.org/robotframework/ webdemo/wiki/Home ! https://code.google.com/p/robotframework/ wiki/UserGuide ! https://code.google.com/p/robotframework/ wiki/TestLibraries

32

///01$2*0,-(& & &&&3,*"4&56*5&76*"(%&3$2%4

Vous aimerez peut-être aussi