Robot Framework条件判断,初始化与清除

条件判断,初始化与清除

RF中用Run Keyword If 关键字做条件判断
条件表达式参数给python的eval函数

run keyword If  "2018" in $h tml     log to console  内容
	#如果2018在$html中,在控制台打印出内容        $html可能是字符串可能是列表

python 的写法: #链接的返回值是:Wed Oct 24 10:59:01 UTC 2018

def getWebInfo():
    response = requests.get(
        'http://mirrors.sohu.com/centos/timestamp.txt')
    return response.text

html = getWebInfo()
if "2018" in html:
    print("2018年的")
else:
    print("不是2018年的")

RF的写法:(关键字和条件之间要有两个以上的空格)
01(一个条件)

*** Settings ***
Library  mylib4         #getwebinfo关键字定义在mylib4模块中

*** Test Cases ***
测试1
    ${html}=    getwebinfo
    run keyword if    '2018' in $html   log to console   2018年的     #在控制台打印2018年的

02(多个条件)
如果条件判断更加多一点

*** Settings ***
Library  mylib4

*** Test Cases ***
测试1
    ${html}=    getwebinfo
    run keyword if  

你可能感兴趣的:(robotframework)