Introduction to Robot Framework

31
INTRODUCTION TO ROBOT FRAMEWORK Carl Su 18 May 2014

description

In this session, we'll focus on the essential parts of the Robot Framework and illustrate how the famous web testing tool Selenium can be integrated.

Transcript of Introduction to Robot Framework

Page 2: Introduction to Robot Framework

Hi

Page 3: Introduction to Robot Framework

歡迎來到 PyCon APAC 2014

Page 4: Introduction to Robot Framework

Hackpad 討論串 #pyconapac2014r4

Page 5: Introduction to Robot Framework

Who!am!I?

Photo credit: paurian CC BY-NC 2.0

Page 6: Introduction to Robot Framework
Page 7: Introduction to Robot Framework

甚麼是 Robot

Framework?

Page 8: Introduction to Robot Framework

通⽤用⾃自動化測試框架

Page 9: Introduction to Robot Framework

⾼高度彈性

Page 10: Introduction to Robot Framework

開放原始碼

Page 11: Introduction to Robot Framework

Why?

Page 12: Introduction to Robot Framework

Clear• 表格式語法,淺顯易懂

• 可根據現有關鍵字建⽴立新的關鍵字

test

cligui

config

r3

r7

r4

doc

examples

quickstart

lib

parallel

retry

robot

Page 13: Introduction to Robot Framework

Easy• 不相依特定平台或應⽤用程式

• 透過 CLI 進⾏行測試,輸出精美報表

Page 14: Introduction to Robot Framework

Modular• 提供⼀一組 API,可輕易擴充關鍵字

• ⽀支援整合 Selenium, Telnet, SSH 等環境

• ⽀支援變數,⽅方便測試不同環境

Page 15: Introduction to Robot Framework

EXAMPLES

Page 16: Introduction to Robot Framework

System Under Test

Robot Framework

Selenium2Library

Test Implementation (test suites, resource files)

Web browser

Page 17: Introduction to Robot Framework

carl@pyconapac2014 ~/D/WebDemo> pip install \ robotframework \ robotframework-selenium2library

Page 18: Introduction to Robot Framework

carl@pyconapac2014 ~/D/WebDemo> python demoapp/server.py Demo server starting on port 7272.

Page 19: Introduction to Robot Framework

carl@pyconapac2014 ~/D/WebDemo> xvfb-run pybot login_tests

Page 20: Introduction to Robot Framework
Page 21: Introduction to Robot Framework

*** Settings *** Documentation A test suite with a single test for valid login. ... ... This test has a workflow that is created using keywords in ... the imported resource file. Resource resource.txt !*** Test Cases *** Valid Login Open Browser To Login Page Input Username demo Input Password mode Submit Credentials Welcome Page Should Be Open [Teardown] Close Browser

Page 22: Introduction to Robot Framework

*** Settings *** Suite Setup Open Browser To Login Page Suite Teardown Close Browser Test Setup Go To Login Page Test Template Login With Invalid Credentials Should Fail Resource resource.txt !*** Test Cases *** User Name Password Invalid Username invalid ${VALID PASSWORD} Invalid Password ${VALID USER} invalid Invalid Username And Password invalid whatever Empty Username ${EMPTY} ${VALID PASSWORD} Empty Password ${VALID USER} ${EMPTY} Empty Username And Password ${EMPTY} ${EMPTY} !*** Keywords *** Login With Invalid Credentials Should Fail [Arguments] ${username} ${password} Input Username ${username} Input Password ${password} Submit Credentials Login Should Have Failed !Login Should Have Failed Location Should Be ${ERROR URL} Title Should Be Error Page

Page 23: Introduction to Robot Framework

def open_browser(self, url, browser=b, alias=a):

return self._cache.register(browser, alias)

open_browser(‘http://localhost:7272/’)

Open Browser http://localhost:7272/

function

keyword

Page 24: Introduction to Robot Framework

*** Keywords *** Login With Invalid Credentials Should Fail [Arguments] ${username} ${password} Input Username ${username} Input Password ${password} Submit Credentials Login Should Have Failed !Login Should Have Failed Location Should Be ${ERROR URL} Title Should Be Error Page

Nested!

Page 25: Introduction to Robot Framework
Page 26: Introduction to Robot Framework
Page 27: Introduction to Robot Framework

THE LIBRARIESOperatingSystem

Screenshot

Telnet

String

Remote

Process

AndroidLibrary

iOSLibrary

DatabaseLibrary

HTTPLibrary

Selenium2Library

SSHLibrary

Page 28: Introduction to Robot Framework

THE TOOLS

Rebot

Testdoc

Libdoc

Sublime plugin

Vim plugin

Jenkins plugin

Page 29: Introduction to Robot Framework

Pros & Cons• 優點

• 簡單易⽤用好上⼿手

• ⾃自動產出精美圖表

• 缺點

• 對測試撰寫⼈人員要求較⾼高

• 空格可能會讓新⼿手產⽣生困惑

Page 30: Introduction to Robot Framework

More…

Page 31: Introduction to Robot Framework

Thank you!