使用RF的一些心得

上一篇 / 下一篇  2016-07-11 20:18:08 / 个人分类:Robotframework


l?d-M X|*[g0
一.元素识别
比较常用的id、name、xpath、css、jQuery
xpath一般情况下,xpath可忽略,但存在xpath=(……),即以括号开始的表达式时,需要加上前缀,不然RF无法识别
css也是比较常用的,css=div.view 
一般情况尽量不要使用绝对路径
执行js来获得元素并执行点击
Execute javascript.|document.getelementbyId().click()
如果元素不存在id属性,可以使用Assigen id to element 给元素分配id,在执行js
因为js本身对查找元素提供的方法有限,因此可以使用更加强大的jQuery
如:jQuery=div.my-class
或:excecute javascript.|$("ul.items").find("li").eq(2).click()
关于元素的可见性:
当元素或元素的祖先元素即上级所有包含它的元素的display=none,这时,即使如果使用一般方法来查找,则会报错element is not visibe
使用jquery可以轻松解决
jQuery=li[value=name]:visible
51Testing软件测试网dLMe8W k$FiE

s~^ I}1kKU,d0
二.文本框的输入
1.使用常规方法:input text
2.press key:
3.send(autolibrary库):直接给当前活动窗口的激活的元素发送字符串或模拟键盘,不太稳定
4.执行js赋值,如果文本框本身是只读的,可以使用remobeattribute去掉只读属性
document.getElementById("sss").removeAttribute("readonly")
document.getElementById("sss").value=""
51Testing软件测试网^{A f6{f|tj
三.等待
sleep:尽量减少使用
wait until page contains:waituntil element is visible等
wait for condition:等待js执行成功
如 wait for conditon |return document.readstate="complete"
也可以自己定义关键字,然后使用 Wait Until Keyword Succeeds

KRdoeD~;XS0m0
51Testing软件测试网@0y~;m*O7m.@*t
四.元素的拖拽
Drag and Drop:拖动到指定元素的上方
Drag and Drop by offset:拖动到指定坐标位置
get vriton position
get horizontion position获取元素的坐标
mouse click drag:(autoit library)从指定坐标处拖动到指定坐标处
如:mouse click drag|LEFT| orgx|orgy|tarX|tarY|dragspeed #最后1个参数设置拖动速度,默认为-1
51Testing软件测试网5h#CH#fuV9So
51Testing软件测试网Kk_'uoOo3f
五.变量的使用
1.使用系统关键字如set variable等创建
2.从关键字返回值
  关键字的返回值除可以在setting里设置外,还可以使用return from keyword从关键字直接返回
 如
     |${index}|set variable|0
     |  :|for|${item}|in|@{items}
     |   |run keyword if|'${item}'='${element}'|return from keyword|${index}
     |return from keyword|-1
  判断列表是否包含元素,包含则关键字的返回值为0,不包含返回为-1,
3.setting新建变量(add sclar),也可以在专门的资源文件中创建,然后引用资源文件
4.使用py文件创建变量文件,可以灵活的直接使用python的内置方法
如:from datetime import datetime
      import random
      #当前日期时间字符串
      curdate=datetime.strftimr(datetime.now(),'%Y%m%d%H%M%S')
      #列表变量
      LIST_VAR=[A,B,C]
      randomval=random.choice(LIST_VAR)
      如果是列表变量则必须以LIST__开头

TAG:

 

评分:0

我来说两句

Open Toolbar