python+robot

转载:robot环境部署:http://blog.51cto.com/7717647/2088634

Robot Run TestSuite
-d results  $FileDir$

$FileDir$

Robot Run SingleTestCase
-d results $FileName$
$FileDir$


python打开谷歌浏览器的代码:

from selenium import webdriver
import os

#谷歌浏览器
chromedriver = "D:/ruanjian/Chrome/chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("http://huohu.com")
driver.quit()

robot使用过程中的关键字定义:

python+robot

robot语法:if 判断语句:
注意:ELSE要大写
ELSE IF
多条判断项时用: and
用单引号或双引号括起来

参考:https://www.cnblogs.com/testlife007/p/5029101.html

注释:

    接口名称:

    [tags]   ignore

for循环:

  run keyword if '${message[1]["result"]["items"]}'=='[]' log 空

...              ELSE
...           log    不为空
...            ${list}   convert to list   ${message[1]["result"]["items"]}
...           :FOR  ${li}  IN  @{list}: ($和@ 都可以。。。@约定为集合,而$是变量,但是实际使用中不做区分)
...            \   log   ${li}
...            run keyword if   '${li}'=='pre_tax_commission'   log   pre_tax_commission true
...            run keyword if   '${li}'=='from'    log   from true
...            run keyword if   '${li}'=='principal'   log   principal true
...            run keyword if   '${li}'=='commission_rate'   log   commission_rate true
#将 ‘’中的值换成你返回值即可

正则表达式:待定

robotframework断言:
 语法:创建list列表: 

${list1}  create list   1  a  ${21}  21  ${true}
@{list2}  set variable   1.0   a  ${21}  21  21
${list3}  create list
${string}  set variable   woshistring
${name}    set variable  ppp

should contain   ${list2}  1.0
should not contain  ${list2}  111
should contain x times  ${list2}  21  2

should be empty  ${list3}
should not be empty  ${list1}

should be equal  ${list1[1]}   ${list2[1]}
should not be equal  ${list1}  ${list2}

should be equal as numbers  ${list2[0]}  1.0000
should not be equal as numbers  ${list2[0]}  1.1

should be equal as integers  ...
should not be equal as integers ...

should be true ...
should not be true ...

should start with  ${string}  woshi
should not start with ${string}  h

should end with  ...
should not end with ...

should match  ${name}  p??
should not match  ${name}  h??
#说明:模式匹配和shell中的通配符类似,区分大小写,  ‘*’匹配0到~无穷多个字符,‘?’表示单个字符

should match regexp  ${name}  ^\\w{3}$
should not match regexp  ${name}  ^\\d{3}$
#说明:反斜杠在测试数据是转义字符,因此模式中要使用双重转义; '^'和'$'可以用来表示字符串的开头和结尾
#${name}=plw  是由三个字母--w{3}组成,不是由三个数字--d{3}组成
${len}   get length  ${message[1]["id"]}
log    ${len}
获取当前时间
${time}    get time
${monthDate}    get time  ${time}.month
${dayDate}    get time  ${time}.day
${yearDate}     get time  ${time}.year
${val1}  set variable  https://dn-ifa-dev-avatar.qbox.me/
${val2}  set variable  ${yearDate}${monthDate}${dayDate}_
${val3}  set variable  73badac0c613c5a3e36b8c87225468b8189773a9.jpg 
${value1}    catenate  ${val1}${val2}${val3} 

should be equal as strings  ${value1}   ${message[1]["result"]}