· BuiltIn
· OperatingSystem
· Screenshot
· Telnet
· Collections
· String
· Dialogs
· Remote
· XML (new in RF 2.7.4)
外部测试库:
This is a list of publicly available test libraries that can be used with Robot Framework but need to be installed separately. Please refer to the individual project pages for information about installing and using them.
· SeleniumLibrary - A web testing library that uses popular Selenium tool internally.
· Selenium2Library - A drop-in-replacement for SeleniumLibrary using newer Selenium 2 WebDriver API.
· Selenium2Library Java port - Java implementation of Se2Lib. Compatible with Jython 2.5.
· watir-robot - A web testing library that uses popular Watir tool via the remote library interface.
· WatinLibrary - A web testing library that uses Watin tool (a .NET port of Watir) via the remote library interface.
· SwingLibrary - A Swing GUI testing library.
· EclipseLibrary - A library for testing Eclipse RCP applications using SWT widgets.
· AutoItLibrary - Windows GUI testing library that uses AutoIt freeware tool as a driver.
· DatabaseLibrary (Java) - A test library that provides common functionality for testing database contents. Implemented using Java so works only with Jython.
· DatabaseLibrary (Python) - Another library for database testing. Implemented with Python and works also on Jython.
· SSHLibrary - A test library that enables SSH and SFTP.
· HTTP test library using livetest
· HTTP test library using Requests
· SudsLibrary - library for testing SOAP-based web services
· AndroidLibrary - Library for Android testing that uses Calabash Android internally.
· IOSLibrary - Library for iOS testing that uses Calabash iOS Server internally.
· Rammbock - Generic network protocol test library.
· How-To: Sikuli and Robot Framework Integration - This is not really a library but these instructions explain how to integrate Sikuli tool with Robot Framework Found these also, might be useful to add them as well (to the external libraries):
· PhantomJS and Zombie.js libraries (similar to SeleniumLibrary? but headless)
· Generic Network Protocol test library
· REST specific HTTP library
· SoapUI library (similar approach to Sikuli lib, but with SoapUI)
· IOS (Iphone/Ipad) test automation library (uses Calabash IOS Server to drive IOS device)
· Android test automation library (uses Calabash Android Server to drive android device)
· ADB (android) library
· VMWare and HyperV virtual machine libraries
· Library supporting debugging in robot framework
· Diff style file comparison library
· Closure webdriver library
· Sikuli integration libraries here and here (The how-to is helpful, but not exactly a library. Checkout here for code based on the how-to though)
· email library
· Image Comparison library
· HTML Check library (doesn't look maintained though, for shame Janne )
一些通用的关键字,如获取时间(Get Time)和应该等于(Should Be Equal)。这些关键字来自内建测试库BuiltIn。通过它的文档,可以看到一个完整可用关键字列表。
库关键字
所有最低级的关键字在测试库中定义,这些测试库使用标准编程语言实现。 Robot Framework带有一些库,包括OperatingSystem:支持常见的操作系统功能,Screenshot截图库。
除了这些标准库,还有其他开源项目,如SeleniumLibrary。如果没有合适的可用的库也很容易实现自己的库。
使用测试库的关键字之前需要导入,它必须考虑到使用。本文件中的测试需要导入标准OperatingSystem的库中的关键字(如Remove File)以及从自定义库LoginLibrary(如Attempt to login with credentials)。
*** Settings ***
Library Selenium2Library
Library DatabaseLibrary
*** Variables ***
${user} 13917745687 # 默认登陆用户
*** Test Cases ***
登陆
海淘登陆 ${user}
[Teardown] close all browsers
个人中心-消息中心
海淘登陆 ${user}
点击元素 //*[@id="user-center"]
点击元素 //*[@class="sf-b2c-mall-center-leftside"]/ul/li/a
wait until page contains 您暂未收到任何消息~
[Teardown] close all browsers
个人中心-我的收藏
海淘登陆 ${user}
点击元素 //*[@id="user-center"]
点击元素 //*[@class="sf-b2c-mall-center-leftside"]/ul/li[2]/a
wait until page contains 全部
[Teardown] close all browsers
个人中心-我的订单
海淘登陆 ${user}
点击元素 //*[@class="sf-b2c-mall-center-leftside"]/ul/li[3]/a
wait until page contains 所有订单
[Teardown] close all browsers
个人中心-我的优惠券
海淘登陆 ${user}
点击元素 //*[@id="user-center"]
点击元素 //*[@class="sf-b2c-mall-center-leftside"]/ul/li[4]/a
wait until page contains 未使用
[Teardown] close all browsers
个人中心-账户管理
海淘账户管理
[Teardown] close all browsers
个人中心-账户管理-修改昵称性别
海淘账户管理
${rand} 随机数
点击元素 //*[@id="user-info-modify-btn"]
wait until keyword succeeds 2 min 5 sec input text //*[@id="nickname"] ${rand}
Comment wait until keyword succeeds 2 min 5 sec input text //*[@id="user-name"] ${user}
select from list //*[@id="select-sex"] FEMALE
点击元素 //*[@id="user-info-confirm-btn"]
[Teardown] close all browsers
个人中心-收货地址
海淘登陆 ${user}
点击元素 //*[@id="user-center"]
点击元素 //*[@class="sf-b2c-mall-center-leftside"]/ul/li[6]/a
wait until page contains 添加收货地址
[Teardown] close all browsers
个人中心-积分管理
积分管理
[Teardown] close all browsers
个人中心-积分管理-收入
积分管理
点击元素 //*[@class="integral-tab-c1 fl"]/ul/li[2]/a #/html/body/div[2]/div[2]/div/div/div[2]/div/div[1]/div[2]/div[1]/ul/li[2]/a
[Teardown] close all browsers
个人中心-积分管理-支出
积分管理
点击元素 //*[@class="integral-tab-c1 fl"]/ul/li[3]/a #/html/body/div[2]/div[2]/div/div/div[2]/div/div[1]/div[2]/div[1]/ul/li[2]/a
[Teardown] close all browsers
个人中心-邀请有礼
海淘登陆 ${user}
点击元素 //*[@id="user-center"]
点击元素 //*[@class="sf-b2c-mall-center-leftside"]/ul/li[8]/a
wait until page contains 邀请有礼
[Teardown] close all browsers
*** Keywords ***
带状态登录
[Arguments] ${url}
open browser ${url} ff ff_profile_dir=${config}
Maximize Browser Window
sleep 1
重试
[Arguments] ${key} ${args1}=none
wait until keyword succeeds 2 min 7 s ${key} ${args1}
等待元素
[Arguments] ${locator} # 元素定位xpath、CSS、ID等
wait until page contains element ${locator}
点击元素
[Arguments] ${locator}
重试 等待元素 ${locator}
重试 click element ${locator}
填写
[Arguments] ${locator} ${content}=none
Selenium2Library.input text ${locator} ${content}
无视错误执行
[Arguments] ${key} ${args1}=none
Run Keyword And Ignore Error ${key} ${args1}
随机数
${num} evaluate random.randint(10000000,99999999) random
[Return] ${num}
连接海豚库
Connect To Database Using Custom Params pymysql database='CSCOnline', user='csc_a', password='dp!@DkbH3ABUv', host='10.1.77.69', port=3306
海豚登录
清理海豚登录状态
open browser http://csc-online-kefu-web01.beta/login.jsp
Maximize Browser Window
input text xpath=//*[@id="j-login-staffno"] ${global-staff-no}
input password xpath=//*[@id="j-login-password"] 123456
wait until element is visible xpath=//*[@id="j-login-button"]
点击元素 xpath=//*[@id="j-login-button"]
run keyword and ignore error wait until page contains element //*[@id="j-button-relogin"] 3
run keyword and ignore error click element //*[@id="j-button-relogin"]
wait until page contains 大众点评 30
sleep 1
更改接线人数
log 修改最大接线人数
click element xpath=//*[@id="j-button-reception"]
sleep 2
click element xpath=//*[@id="j-ul-reception"]/li[3]/a
提取数据
[Arguments] ${data}
${out} evaluate ${data}[0][0]
[Return] ${out} # 提取出的内容
清理海豚登录状态
连接海豚库
execute sql string Delete FROM icc_staff_online;
Comment Delete All Rows From Table icc_staff_online
sleep 2
后台sso
open browser https://sso.51ping.com/login?TARGET=http%3A%2F%2Fbackend.csc.dp%3A8080%2F ff
Maximize Browser Window
run keyword and ignore error input text //*[@id="username"] 0018169
run keyword and ignore error input password //*[@id="password"] Ceshi123
run keyword and ignore error click element //*[@id="fm1"]/div[5]/div[3]/input[4]
sleep 1
run keyword and ignore error reload page
run keyword and ignore error wait until page contains 后台管理 20
展开后台
wait until element is visible xpath=//*[@id="sidebar"]/ul/li[1]/a/span 20
click element xpath=//*[@id="sidebar"]/ul/li[1]/a/span
sleep 1
新增部门
后台sso
展开后台
点击元素 //*[@id="sidebar"]/ul/li[1]/ul/li[8]/a
wait until element is visible xpath=//*[@id="add_grid-table"]/div/span 30
点击元素 xpath=//*[@id="add_grid-table"]/div/span
点击元素 xpath=//*[@id="editmodgrid-table"]
select from list by value //*[@id="deptSelect2"] 10
${dept} evaluate random.randint(1111111,9999999) random
input text xpath=//*[@id="name"] ${dept}
sleep 0.5
log 提交新部门信息
点击元素 xpath=//*[@id="sData"]
sleep 1
连接海豚库
${data-check} query select id from CSC_Department where name='${dept}'
should not be empty ${data-check}
log 数据入库成功
[Return] ${dept} # 部门名称
新增技能组
后台sso
展开后台
点击元素 //*[@id="sidebar"]/ul/li[1]/ul/li[7]/a
Comment wait until element is visible //*[@id="select-btn"]/button[1]
Comment click button //*[@id="select-btn"]/button[1]
log 新增技能组
wait until element is visible //*[@id="add_grid-table"]/div/span
点击元素 //*[@id="add_grid-table"]/div/span
${skill-code} evaluate random.randint(10000,99999) random
sleep 0.6
log 新技能组名称
wait until element is visible //*[@id="name"]
input text //*[@id="name"] ${skill-code}
wait until element is visible //*[@id="code"] ${skill-code}
log 选择部门为商服
select from list by value //*[@id="deptSelect"] 20 #10user \ \ 20shop \ \ 30sales
sleep 0.6
log 提交
wait until element is visible //*[@id="sData"]/i
点击元素 //*[@id="sData"]/i
log 提交成功
sleep 1
[Return] ${skill-code} # 技能组
新增客服
后台sso
展开后台
log 打开员工页
点击元素 //*[@id="sidebar"]/ul/li[1]/ul/li[6]/a
点击元素 xpath=//*[@id="add_grid-table"]/div/span
sleep 0.5
${staff-no} evaluate random.randint(1111111,9999999) random
select checkbox //*[@id="staffNOEditable"]
log 输入客服名称
wait until element is visible xpath=//*[@id="staffName"]
input text xpath=//*[@id="staffName"] ${staff-no}
log 输入工号
wait until element is visible xpath=//*[@id="staffNO"]
input text xpath=//*[@id="staffNO"] ${staff-no}
log 输入密码
wait until element is visible xpath=//*[@id="password"]
input password xpath=//*[@id="password"] 123456
log 选择技能组
@{skill-code} set variable 2 3 8
sleep 1
Comment click element xpath=//*[@id="tr_skillIdListStr"]/td[2]/div/button
select from list xpath=//*[@id="deptSelect"] 10
click element //*[@id="tr_skillIdListStr"]/td[2]/div/button
log 最小接线人数
wait until element is visible xpath=//*[@id="minReceptionNum"]
input text xpath=//*[@id="minReceptionNum"] 5
log 最大接线人数
wait until element is visible xpath=//*[@id="maxReceptionNum"]
input text xpath=//*[@id="maxReceptionNum"] 10
log 输入昵称
wait until element is visible xpath=//*[@id="nickName"]
input text xpath=//*[@id="nickName"] ${staff-no}
click element xpath=//*[@id="sData"]
[Return] ${staff-no} # 员工工号
海淘登陆
[Arguments] ${user}
${bro} open browser http://www.fengqu.com/index.html ff
Maximize Browser Window
点击元素 //*[@id="user-login"]
select frame //*[@class="register"]/div[2]/iframe
wait until keyword succeeds 2 min 5 sec input text //*[@id="user-name"] ${user}
wait until keyword succeeds 2 min 5 sec input password //*[@id="user-pwd"] yiyi521
Comment input text //*[@id="user-name"] ${user}
Comment input password //*[@id="user-pwd"] yiyi521
点击元素 //*[@id="gotologin"]
unselect frame
wait until page contains 欢迎回来
[Return] ${bro} # 登陆页面driver
海淘账户管理
海淘登陆 ${user}
点击元素 //*[@id="user-center"]
点击元素 //*[@class="sf-b2c-mall-center-leftside"]/ul/li[5]/a
wait until page contains 基本资料
积分管理
海淘登陆 ${user}
点击元素 //*[@id="user-center"]
点击元素 //*[@class="sf-b2c-mall-center-leftside"]/ul/li[7]/a
wait until page contains 我的积分 setting中的内容为三方库,可以使用开源的也可以自己编写,如何自己编写自己的库见下文
*** Variables ***
${user} 13917745687 # 默认登陆用户 Test Cases中就是执行单元了,可以直接使用内置库、三方库、用户关键字
*** Test Cases ***
登陆
海淘登陆 ${user}
[Teardown] close all browsers
个人中心-消息中心
海淘登陆 ${user} #用户关键字
点击元素 //*[@id="user-center"]
点击元素 //*[@class="sf-b2c-mall-center-leftside"]/ul/li/a
wait until page contains 您暂未收到任何消息~ #三方库方法
[Teardown] close all browsers Keywords用户关键字,对于复用率高、可抽离公共熟悉的操作或者方法可以通过Keywords来将这些逻辑抽象出来,Keywords可以定义入参与返回值,这样可使得case中操作的连贯,也更易于case的维护
*** Keywords ***
带状态登录
[Arguments] ${url}
open browser ${url} ff ff_profile_dir=${config}
Maximize Browser Window
sleep 1
重试
[Arguments] ${key} ${args1}=none
wait until keyword succeeds 2 min 7 s ${key} ${args1}
等待元素
[Arguments] ${locator} # 元素定位xpath、CSS、ID等
wait until page contains element ${locator}
点击元素
[Arguments] ${locator}
重试 等待元素 ${locator}
重试 click element ${locator}
填写
[Arguments] ${locator} ${content}=none
Selenium2Library.input text ${locator} ${content}
无视错误执行
[Arguments] ${key} ${args1}=none
Run Keyword And Ignore Error ${key} ${args1} 组织测试用例