2

I need to have a nested if statement in my test case.

I need to check if variable a equals X and if it does I need to check if variable b equals 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).

Is there a Robot way to do this without writing a custom keywords by myself?

1 Answer 1

6

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":

       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
Sign up to request clarification or add additional context in comments.

2 Comments

Are you saying there is no way for nested if else in Robot framework??
@AnshumanJayaprakash: you couldn't back when I wrote that answer 7 years ago. You can do it now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.