RobotFramework Demo with Web
翻译自:https://bitbucket.org/robotframework/webdemo
前提:
1. Robot Framework and Selenium2Library installed
2. 下载项目代码;
运行:
1. log全部实例:
robot login_tests
2. 指定实例
robot login_tests/valid_login.robot
robot framework 测试实例分析:
资源文件: "resource.robot" 定义了Keywords, 定义在test suits 之外, 这样可以通过导入的方式将keywords应用于整个工程; 原文如下:
"Keywords can be defined outside of the test suite and be imported as an external resources.This means you can collect generally useful keywords to one place and share them throughout your project,"
*** Settings *** Documentation A resource file with reusable keywords and variables. ... ... The system specific keywords created here form our own ... domain specific language. They utilize keywords provided ... by the imported Selenium2Library. Library Selenium2Library *** Variables *** ${SERVER} localhost:7272 ${BROWSER} Firefox ${DELAY} 0 ${VALID USER} demo ${VALID PASSWORD} mode ${LOGIN URL} http://${SERVER}/ ${WELCOME URL} http://${SERVER}/welcome.html ${ERROR URL} http://${SERVER}/error.html *** Keywords *** Open Browser To Login Page Open Browser ${LOGIN URL} ${BROWSER} Maximize Browser Window Set Selenium Speed ${DELAY} Login Page Should Be Open Login Page Should Be Open Title Should Be Login Page Go To Login Page Go To ${LOGIN URL} Login Page Should Be Open Input Username [Arguments] ${username} Input Text username_field ${username} Input Password [Arguments] ${password} Input Text password_field ${password} Submit Credentials Click Button login_button Welcome Page Should Be Open Location Should Be ${WELCOME URL} Title Should Be Welcome Page
有效登陆测试实例: "valid_login.robot"
// 所有这些keywords是定义了的,如下面的" Open Browser To Login Page ", 定义在上面的resource.robot里, 定义如下:
"Open Browser To Login Page"语句定义:
下面的Open Browser是库里的buildin关键字:
Open Browser ${LOGIN URL} ${BROWSER}
Maximize Browser Window
Set Selenium Speed ${DELAY}
Login Page Should Be Open
*** 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.robot *** 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
测试结果:
看valid_login.robot的结果:

下面是"Open Browser To Login Page"关键字的底层关键字, 过程与该关键字的定义过程一样,调用的是Selenium2Labrary库的接口;

浙公网安备 33010602011771号