條件判斷:run keyword if 后面變量類型為condition,和should be true一樣,用 $var 或 '${var}',詳情看RF--基礎 中的should be true
run keyword if 后條件成立的情況下,只能執行一個關鍵字,如下,只能執行一個動作
嵌套循環和多重判斷放在python中寫,rf調用
1、run keyword if+條件表達式+動作 寫在同一行:
*** Test Cases *** 條件判斷1 ${var} set variable 2020 run keyword if $var=='2020' log to console 測試通過 結果: 測試通過
2、run keyword if 后的動作換行寫,寫 三個點 加兩個以上空格
*** Test Cases *** 條件判斷2 ${date} get time #get time為rf內置獲取當前時間函數 run keyword if '2020' in $date and '07' in $date #'2020' in $date and '07' in $date中間空格最多一個,表示為一個表達式整體
... log to console 當前為2020年07月
結果:
當前為2020年07月
3、run keyword if ELSE 寫在一行 #ELSE為大寫
*** Test Cases *** 條件判斷3 ${date} get time #get time為rf內置獲取當前時間函數 run keyword if '2021' in $date log to console 今年為2021年 ELSE log to console 今年不是2021年 結果: 今年不是2021年
4、條件分支判斷:run keyword if ELSE 換行寫 #ELSE為大寫
*** Test Cases *** 條件判斷4 ${date} get time #get time為rf內置獲取當前時間函數 run keyword if '2021' in $date log to console 今年為2021年 ... ELSE log to console 今年不是2021年 結果: 今年不是2021年
5、條件多分支判斷:run keyword if + ELSE IF + ELSE 注意大寫
*** Test Cases *** 條件判斷5 ${date} get time #get time為rf內置獲取當前時間函數 run keyword if '2021' in $date log to console 今年為2021年 ... ELSE IF '05' in $date log to console 現在是05月 ... ELSE log to console 現在不是2021年也不是05月 結果: 現在不是2021年也不是05月