关于python:Robot Framework嵌套if语句 | 珊瑚贝

Robot Framework nested if statement


我需要在我的测试用例中有一个嵌套的 if 语句。

我需要检查变量 a 是否等于 X,如果是,我需要检查变量 b 是否等于 Y.

我试着做这样的事情:

1
2
3
4
5
6
7
8
9
Click on button
Run Keyword If                      ‘${var_a}’ == ‘X’
…         Run Keyword If                      ‘${var_b}’ == ‘Y’
…                 Click Element               Locator_a
…                 ELSE
…                 Click Element               Locator_b

…         ELSE
…         Click Element                       Locator_c

我收到的错误是点击元素需要 1 个参数并得到 4 个。
这意味着一旦它为第一个 if 语句 (var_a == X) 返回 False,它就会尝试使用所有后面的关键字作为参数调用第一个 ELSE 语句(单击元素,Arg1 = locator_b,Arg2 = Else,Arg3 = Click Element,Arg5 = Locator_c ).

有没有一种机器人方法可以做到这一点,而无需自己编写自定义关键字?


严格来说,不,没有办法做你想做的事。但是,您可以将 if 语句组合成一个大语句,其中三个条件由”ELSE IF”和”ELSE”连接:

1
2
3
4
5
6
7
8
       Run keyword if  ‘${var_a}’ == ‘X’ and ‘${var_b}’ == ‘Y’
…    Click Element    Locator_a

…    ELSE IF         ‘${var_a}’ == ‘X’ and ‘${var_b}’ != ‘Y’
…    Click Element    Locator_b

…    ELSE
…    Click Element    Locator_c

  • 你是说机器人框架中没有嵌套 if else 的方法吗?
  • @AnshumanJayaprakash:当我 7 年前写下那个答案时,你无法回头。你现在可以做


来源:https://www.codenong.com/34590001/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8666.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?