简体   繁体   English

机器人框架嵌套if语句

[英]Robot Framework nested if statement

I need to have a nested if statement in my test case. 我需要在测试用例中嵌套一个if语句。

I need to check if variable a equals X and if it does I need to check if variable b equals Y. 我需要检查变量a等于X ,如果需要,我需要检查变量b等于Y。

I tried doing something like this: 我试图做这样的事情:

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

The error that I receive is that click element expected 1 argument and got 4. Meaning once it returned False for the first if statement ( var_a == X ) it tried to call the first ELSE statement with all the later keywords as arguments (Click Element, Arg1 = locator_b, Arg2 = Else, Arg3 = Click Element, Arg5 = Locator_c). 我收到的错误是click元素期望有1个参数,并得到4。这意味着一旦它为第一个if语句( var_a == X )返回False,它就会尝试使用所有后来的关键字作为参数来调用第一个ELSE语句(Click元素) ,Arg1 = locator_b,Arg2 =其他,Arg3 =点击元素,Arg5 = Locator_c)。

Is there a Robot way to do this without writing a custom keywords by myself? 有没有一种机器人方法可以做到这一点而无需自己编写自定义关键字?

Strictly speaking, no, there's no way to do what you want. 严格来说,不,没有办法做你想做的事。 However, you can combine your if statements into one large statement with three conditions joined by "ELSE IF" and "ELSE": 但是,您可以将if语句合并为一个大语句,并用“ ELSE IF”和“ ELSE”三个条件连接:

       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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM