How to run multiple keywords in the if condition

12,195 views
Skip to first unread message

din...@139.com

unread,
Aug 9, 2016, 2:36:06 AM8/9/16
to robotframework-users
When ${a} == True, perform keyword1, keyword2, when ${a} == True keyword3, keyword4.
How to implement??

Patricio Iglesias

unread,
Aug 9, 2016, 3:46:59 AM8/9/16
to robotframework-users
not very polite but what about building a keyword that return the keyword you need to execute in every case:

${result} Evaluate "whatever"
${status} ${value} Run Keyword And Ignore Error Should Be Equal As Integers ${result} 0
Return From Keyword If '${status}' == 'PASS' "keyword1"
${status} ${value} Run Keyword And Ignore Error Should Be Equal As Integers ${result} 1
Return From Keyword If '${status}' == 'PASS' "keyword2"
${status} ${value} Run Keyword And Ignore Error Should Be Equal As Integers ${result} 2
Return From Keyword If '${status}' == 'PASS' "keyword3"
${status} ${value} Run Keyword And Ignore Error Should Be Equal As Integers ${result} 3
Return From Keyword If '${status}' == 'PASS' "keyword4"

All you have to do is recover keyword name and run it like
Run Keyword And Continue On Failure ${Keywordrecovered}

din...@139.com

unread,
Aug 9, 2016, 4:09:56 AM8/9/16
to robotframework-users
Thank you very much,.
sorry for my  not polite,i'm not very good at English, what is the place where I need to pay attention to?

在 2016年8月9日星期二 UTC+8下午3:46:59,Patricio Iglesias写道:

Patricio Iglesias

unread,
Aug 9, 2016, 4:28:46 AM8/9/16
to robotframework-users
I was talking about my solution. 

Is not polite cause could be expensive in time and resources but it works fine :)


El martes, 9 de agosto de 2016, 8:36:06 (UTC+2), din...@139.com escribió:

J Wipf

unread,
Aug 9, 2016, 6:23:38 AM8/9/16
to robotframework-users
Another option would be to create a custom keyword that wraps up all of your subsequent tasks.

So 
When ${a} == True, perform keyword1, keyword2, when ${a} == True keyword3, keyword4.
Becomes
*** Settings ***
Resource    /path/to/keyword1
Resource    /path/to/keyword2
Resource    /path/to/a

*** Keywords ***
Custom Keyword From If
   
[Documentation]    Left to the user to extrapolate keyword3 & keyword4
    keyword1
    keyword2

*** Test Cases ***
Test Custom Keyword From If
   
Run Keyword If    '${a}'=='True'    Custom Keyword From If

This is especially useful when you're looking to do bulk actions off one condition I find.

Bryan Oakley

unread,
Aug 9, 2016, 8:12:31 AM8/9/16
to robotframework-users

You can use "run keywords"

run keyword if    ${a} == True    run keywords
    ...    keyword 1
    ...    AND    keyword 2
    ...    AND    keyword 3
    ...    AND    keyword 4

Though, it might be better to create a new keyword that has those other keywords so that you only have to call one keyword.

On Tue, Aug 9, 2016 at 1:36 AM, <din...@139.com> wrote:
When ${a} == True, perform keyword1, keyword2, when ${a} == True keyword3, keyword4.
How to implement??

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Amritansh Diwakar

unread,
Jul 12, 2018, 1:18:11 PM7/12/18
to robotframework-users
In such case, if keyword 1 returns a value and I need to use it in keyword 2, can you I do that? Please help.


On Tuesday, August 9, 2016 at 5:42:31 PM UTC+5:30, Bryan Oakley wrote:

You can use "run keywords"

run keyword if    ${a} == True    run keywords
    ...    keyword 1
    ...    AND    keyword 2
    ...    AND    keyword 3
    ...    AND    keyword 4

Though, it might be better to create a new keyword that has those other keywords so that you only have to call one keyword.
On Tue, Aug 9, 2016 at 1:36 AM, <din...@139.com> wrote:
When ${a} == True, perform keyword1, keyword2, when ${a} == True keyword3, keyword4.
How to implement??

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.

Aleh Barysevich

unread,
Jul 12, 2018, 4:13:13 PM7/12/18
to robotframe...@googlegroups.com

The only option to pass values between keywords is to use global/suite/test variable, but it sounds as very bad practise.

On Thu, 12 Jul 2018, at 11:36, Amritansh Diwakar wrote:
In such case, if keyword 1 returns a value and I need to use it in keyword 2, can you I do that? Please help.

On Tuesday, August 9, 2016 at 5:42:31 PM UTC+5:30, Bryan Oakley wrote:

You can use "run keywords"

run keyword if    ${a} == True    run keywords
    ...    keyword 1
    ...    AND    keyword 2
    ...    AND    keyword 3
    ...    AND    keyword 4

Though, it might be better to create a new keyword that has those other keywords so that you only have to call one keyword.


Aleh Barysevich


Geist Eng

unread,
Jul 12, 2018, 5:52:45 PM7/12/18
to robotframe...@googlegroups.com
I might be misunderstanding what is being asked...

Run Keywords is what one uses to execute a number of other KWs as Bryan pointed out above.  But if one KW returns a value another KW needs than  as others pointed out another KW should be called and not use Run Keywords.

...

| | run keyword if | ${a} == True | someTaskKW |

...

someTaskKW
| | ${some data}= | keyword1 |
| | keyword2  | ${some data} |
| | keyword 3 |
| | keyword 4 |



Passing values between KWs is fairly common.

Example from my code:


Set Text Param
| | [Documentation] | Only set a text type param on a page already open. Save Parm is not called |
| | [Arguments] | ${page name} | ${param name} | ${value} |
| | ${param id}= | Toucan Input Field Name To ID | ${page name} | ${param name} |
| | Wait Until Element Is Visible | id=${param id} | timeout=${TIMEOUT} |
| | Input Text | id=${param id} | ${value} |



Reply all
Reply to author
Forward
0 new messages