任何自動化測試框架或實例中斷言是必不可少的,Robotframework同樣如此,那下面就介紹下其常用斷言關鍵字。
1、Should Be Empty
判斷是否為空,如果不為空,執行失敗,示例:
${value} Set Variable hello
Should Be Empty ${value} 斷言結果不為空
2、Should Start With
判斷某個字符串是否以預期執行的字符串開始,如果以指定的字符串開頭,則執行成功,否則執行失敗,示例:
${value} Set Variable hello
Should Start With ${value} kemi 斷言字符串${value}不以kemi開頭
3、Should Not Start With
與Should Start With剛好相反,如果以指定的字符串開頭,則執行失敗,否則執行成功,示例:
${value} Set Variable hello
Should Not Start With ${value} kemi 斷言字符串${value}是以kemi開頭
4、Should Match
判斷某個字符串是否與預期指定的字符串相匹配,如果可以匹配,則執行成功,否則執行失敗,示例:
${value} Set Variable hello
Should Match ${value} kemi 斷言字符串${value}不可以匹配qq
5、Should Not Match
與Should Match剛好相反,如果字符串匹配,則執行失敗,否則執行成功,示例:
${value} Set Variable hello
Should Not Match ${value} kemi 斷言字符串${value}可以匹配hello
6、Should Be Equal As Integers
以整數的形式來進行比較,示例:
${value} Set Variable 11
Should Be Equal As Integers ${value} 12 斷言11和12不相等
7、Should Be Equal As Strings
以字符串的形式來進行比較,示例:
${value} Set Variable hello
Should Be Equal As Strings ${value} kemi 斷言hello和kemi不相等
8、Should Be Equal As Numbers
以number的形式來進行比較,示例:
${value} Set Variable 1.0
Should Be Equal As Numbers ${value} 1 斷言1.0等於1
9、Should Not Be Equal
與should be equal 用法相反,當帶比較的兩個值相等時,執行失敗,否則執行成功,示例:
${value} Set Variable 1.0
Should Not Be Equal ${value} 1.0 斷言1.0等於1.0
10、Should Not Be Empty
與should be empty 用法相反,如果為空,執行失敗,示例:
${value} Set Variable hello
Should Not Be Empty ${value} 斷言字符串${value}為空
