*** Settings ***
Test Teardown kill_process
Library Selenium2Library
Library OperatingSystem
Library DatabaseLibrary
*** Variables ***
${name} xiaoqian
@{lsit1} xiaoqian daqian
&{dict1} name=xiaoqian age=19
*** Test Cases ***
test_01
Open Browser http://www.baidu.com gc
${size} Get Window Size #获取当前百度窗口的大小
log ${size} #(940, 540)
test_02
log ${name} #log打印的意思 #全局变量
Log Many @{lsit1} #打印列表
Log Many &{dict1} #打印字典
#打印全局变量用Log #全局$ 列表@ 字典&
#打印列表和字段用:log many
#rf中注释也可以使用#号
#ctrl +3注释
#ctrl +4取消注释
#上下移动:alt +上下按钮
test_03
${name1} Set Variable daqian #自定义一个全局变量
log ${name1} #打印全局
Comment 定义一个列表
@{list2} Create List zhangshan lisi
log many @{list2}
Comment 定义一个字典
&{dict2} Create Dictionary name=daqian age=10
log many &{dict2}
test_04
Open Browser http://www.baidu.com gc #通过谷歌打开百度
Input Text id=kw python #id定位
#name定位
Input Text name=wd python
#class 定位
Input Text class=s_ipt python
Input Text autocomplete=off python 直接引用此方法定位报错
Execute Javascript document.getElementById('kw').value='python' #JS定位
test_05
Open Browser http://www.baidu.com gc
#xpath 定位方法
Input Text xpath=//*[@id="kw"] python #复制的路径
Input Text xpath=//*[@name="wd"] python #通过name定位
Input Text xpath=//input[@id="kw"] python
Input Text xpath=//*[@class="s_ipt"] python #通过class定位
Input Text xpath=//*[@autocomplete="off"] python
Input Text xpath=//*[@id="form"]/span[1]/input[1] python #找父级方法
Input Text xpath=//*[@name="wd" and @class="s_ipt"] python #and方法进行查询
test_06
Open Browser http://www.baidu.com/ gc
#css定位
Input Text css=#kw python #id加#号
Input Text css=.s_ipt python #class 加一个.
Input Text css=[id=kw] python #通过ID完整语法定位
Input Text css=[name=wd] python #通过name方法定位
Input Text css=[class=s_ipt] python #通过clss定位
Input Text css=[autocomplete=off] python
Input Text css=[name=wd][class=s_ipt] python #拼接
Input Text css=span>input python #通过一个大于号找父级
Input Text css=form>span>input python
Input Text css=[id ~=kw] python
test_07
Open Browser http://www.baidu.com gc
Maximize Browser Window #窗口最大化
sleep 3 #线程等待
Input Text id=kw python
sleep 3
Reload Page #重新加载
go to http://www.jd.com #当前窗口进入新的网站
sleep 2
Go Back #返回上一步
test_08
Open Browser http://192.168.254.129:8080/cms gc #打开网站
Maximize Browser Window #窗口最大化
Input Text id=userAccount admin #输入账号
Input Password id=loginPwd 123456 #输入密码
sleep 2 #等待
Comment Click Button 登录
Click Element id=loginBtn #点击登录
test_09
Open Browser http://www.baidu.com gc
Maximize Browser Window
Click Link hao123 #点击链接
Click Link name=tj_trhao123 #通过元素定位点击链接
Click Link 新闻
test_10
Open Browser http://www.baidu.com gc a #取别名
Maximize Browser Window
Open Browser http://www.jd.com gc c #取别名
${title1} Get Title #获取当前title
log ${title1} #京东(JD.COM)-正品低价、品质保障、配送及时、轻松购物!
Switch Browser a #通过别名来获取title值
${title2} Get Title #获取title属性
log ${title2} #百度一下,你就知道
sleep 1
Comment Close Window #关闭窗口
Close Browser
test_11
Open Browser http://www.jd.com gc
Maximize Browser Window
sleep 3
${title4} Get Title
log ${title4}
Open Browser http://www.baidu.com gc
Close Browser #关闭当前浏览器
Close Window #根据当前title位置来进行关闭
Close All Browsers #关闭所有浏览器
test_12
Open Browser http://www.jd.com gc
Maximize Browser Window
sleep 2
Click Link 优惠券
${title} Get Title #获取当前title
log ${title} #京东(JD.COM)-正品低价、品质保障、配送及时、轻松购物!
Select Window 领券中心 #切换窗口
${tilet1} Get Title #获取title
log ${tilet1} #领券中心
sleep 1
Input Text id=quan-key 香水
Close Window
test_13
Open Browser http://www.jd.com gc
Maximize Browser Window
sleep 2
Click Link 优惠券
${tilte} Get Title
log ${tilte} #获取的title为京东
${hederl} Get Window Handles #获取当前所有的句柄
Comment [u'CDwindow-3EB8D1CF4408652F3C0594B5F33FBC8F', u'CDwindow-C44852A01DF6BD7097916CDDE2383D10'
log ${hederl}
Select Window ${hederl[1]} #通过索引来取句柄来进行切换
log ${hederl[1]} #CDwindow-C44852A01DF6BD7097916CDDE2383D10
Select Window ${hederl[0]} #CDwindow-7FD27EC19C721CB2D819249BE1508865
log ${hederl[0]} #通过句柄获取:索引安装pyhton中一致正向索引:0 \ 负向:-1
test_14
Open Browser http://www.baidu.com gc
${tite} Get Title
log ${tite} #百度一下,你就知道
Title Should Be 百度一下,你就知道! #断言当前title是否一致 #不是则报错 \ 是则OK
Title Should Be 百度一下,你就知道
test_15
Open Browser http://www.baidu.com gc
Maximize Browser Window
${text} Get Text xpath=//*[@id="u1"]/a[8] #通过元素获取对应的文本
log ${text} #登录 #通过变量进行接收
${vale} Get Value xpath=//*[@id="su"] #通过值获取对应文本的值
log ${vale} #百度一下
test_16
Open Browser http://www.jd.com/ gc
Maximize Browser Window
sleep 3
Execute Javascript window.scrollTo(0,1000) #滑动(距离需要自己调试)
sleep 1
Execute Javascript window.scrollTo(0,0) #返回最顶端
test_17
Open Browser file:///E:/第二月课件/robotframework自动化/table.html gc
Maximize Browser Window
sleep 2
Select Radio Button sex girl #单选框定位
Click Element xpath=/html/body/form/table/tbody/tr[5]/td[2]/input[1] #单选框定位通过 xpath
Select Checkbox css=[value=linux] #复选框定位
Click Element xpath=/html/body/form/table/tbody/tr[6]/td[2]/input[3] #复选框定位通过xpath
test_18
Open Browser https://mail.163.com/ gc
Maximize Browser Window
sleep 2
Click Element id=lbNormal
sleep 2
Input Text id=auto-id-1588643920693 q13316533316 #id定位(此id为动态id)
Input Text name=email q13316533316 #name 定位
Input Text xpath=//*[@id="auto-id-1588643920693"] q13316533316 #xpath定位
Select Frame xpath=//*[@id="loginDiv"]/iframe[1] #进入frame 框
Input Text id=auto-id-1588643920693 q13316533316
Input Text name=email q13316533316 #输入账号
Input Password name=password 776995909 #输入密码
Click Element id=dologin #点击登录
Unselect Frame #退出frame框
sleep 1
Click Link 退出
test_19
Open Browser https://www.ctrip.com/?sid=15595 ... 4897&ouid=index gc
Maximize Browser Window #窗口最大化
sleep 6
Comment Click Element class=fl_wrap_close
Input Text id=HD_CityName 深圳 #输入目的地
Input Text id=HD_CheckIn 2020-5-5 #选择入住日期
Input Text id=HD_CheckOut 2020-05-09 #选择退房日期
sleep 2
Select From List By Index id=J_roomCountList 4 #索引取值
Select From List By Value id=J_roomCountList 4 #通过value值取
Select From List By Label id=J_roomCountList 5间
sleep 3
Click Element id=J_RoomGuestInfoTxt #点击住客数
Click Element class=icon_numplus #添加成人数
Click Element id=J_RoomGuestInfoBtnOK #点击确定
Execute Javascript document.getElementById('J_RoomGuestInfoTxt').value='5成人' #js语法
sleep 1
Input Text id=HD_TxtKeyword 会展中心
Select From List By Index id=searchHotelLevelSelect 3 #通过索引进行选择下拉值
Click Button 搜索
test_20
Open Browser https://www.ctrip.com/?sid=15595 ... 4897&ouid=index gc
Maximize Browser Window
Mouse Over xpath=/html/body/div[5]/div/ul[1]/li/a/span #鼠标移动到某个元素上面
Click Element id=ctrip_hk #点击进入
test_21
Open Browser file:///E:/第二月课件/robotframework自动化/alert弹框.html gc
sleep 2
Handle Alert accept #点击确定
handle alert dismiss #点击取消
sleep 2
Alert Should Be Present 好! #断言当前结果是否相匹配
Comment Alert Should Not Be Present 好
test_22
Open Browser http://www.baidu.com gc
Page Should Contain 登录 #断言当前百度是否包含了此文本
Page Should Contain Element id=kw #断言当前页面是否包含此元素
Page Should Not Contain 多测师 #断言当前页面不包含此文本 #如包含则报错,不包含则OK
Page Should Not Contain Element id=duoceshi #断言当前页面不包含此元素 #包含则报错,不包含则OK
Page Should Contain Link hao123 #d断言当前页面包含此链接 #包含就OK不包含报错
Assign Id To Element kw duoceshi #将某个元素进行替换
Page Should Contain Element duoceshi #断言当前页面是否存在此元素
test_23
Open Browser file:///E:/第二月课件/robotframework自动化/table.html gc
${tet} Get Table Cell class=_table 1 1
log ${tet} \ #第一行 #第一列
test_24
Open Browser http://www.baidu.com gc
Comment Wait Until Page Contains 登录 #判断当前界面包含此文本,如果存在则执行下面结果,如不存在则报错不执行以下结果
Comment Input Text id=kw 多测师
Comment Wait Until Page Does Not Contain 多测师 #断言不包含此文本,如不包含则执行以下用例,如包含则报错
Comment Input Text id=kw 多测师
Comment Click Element id=su
Comment Wait Until Page Contains Element id=kw #判断是否包含元素,包含执行结果,不包含NO
Comment Input Text id=kw 多测师
Comment Click Element id=su
Wait Until Page Does Not Contain Element id=duoceshi #判断不包含此元素,不包含执行用例,包含NO
Input Text id=kw 多测师
Click Element id=su
*** Keywords ***
kill_process
OperatingSystem.Run taskkill /f \ /im chromedriver.exe
|
|