RobotFramework常用断言关键字
变量或者关键字内容判断关键字
1、内容包含或者不包含:should contain 、 should not contain 与should contain x times
*** Test Cases ***
claim1
${21} Set Variable 21
@{list1} Create List 1 a ${21} 21 12
@{list2} Create List 1 a ${21} 21 21
@{list3} Create List
${string} set variable pengliwen is in hangzhou
${name} set variable plw
should contain ${list1} 1.0 #false
should not contain ${list1} 1 #false
should contain x times ${list1} 21 2 #ture
2、判断内容为空或者不为空:should be empty 与 should not be empty
should be empty ${list1} #false
should not be empty ${list1} #ture
should not be empty ${list3} #false
3、判断内容是否相等:should be equal 与 should not be equal
should be equal ${list1[1]} ${list1[1]} #ture
should not be equal ${list1} ${list2} #false
4、比较值真或者假:Should Be True与Should not Be True
Should Be True ${list_a[0]} < 10 #ture
Should not Be True ${list_a[0]} < 1 #false
5、判断内容开头结尾:Should start With与Should not start With Should End With与Should not End With
Should start
With ${string} peng #ture
Should not start With ${string} h #false
Should End
With ${string} Hangzhou #ture
Should not End
With ${string} pengliwen #false
6、判断是否匹配:should match与should not match
should
match ${name} p?? #ture
should not match ${string} h?* #false
需要说明:模式匹配和shell中的通配符类似,它区分大小写,'*'匹配0~无穷多个字符,“?”单个字符。
selenium库的常用断言关键字
1、页面是否存在文本:Wait Until Page Contains和Wait Until Page Does Not Contain
Wait Until Page Contains不用元素定位,全页面等待某个文本,出现即为断言结果为True,在超时时间过了不出现即为False,适用于关键操作有页面提示的框架。
Wait Until Page Contains Element,适用于在业务状态变化后,页面某文字消失的情况。
2、判断页面内是否存在Element:Wait Until Page Contains Element和Wait Until Page Does Not Contain Element
Wait Until Page Contains Element在页面上等待符合定位的某元素出现,即为判断结果为True,在超时时间过了不出现即为False。
Wait Until Page Does Not Contain Element,使用方法和上面一样,这里就不再描述。
3、判断判断元素包含的文本:Wait Until Element Contains和Wait Until Element Does Not Contain
Wait Until Element Contains:判断元素包含的文本,其实这个有3个需要注意的地方:1. 元素先被找到,如果页面未包含元素,直接报false。2. 如果定位有多个符合的元素,就会依次查找。3. 文本是“包含”,比如目标文本内容为"123",断言的内容为"23",也会判断为True。所以这个关键字是判断某一瞬页面是中某元素是否包含某文本,如果文本在这一瞬没有出现,就会判断为False。
Wait Until Element Does Not Contain,使用方法和上面一样,这里就不再描述。