2
votes

How to use templatize a Robot Keyword than a whole testcase using [Template] syntax?

Need is:

A resource file creates a Keyword in keywords.robot :

*** Keywords ***
Do Something
  [Arguments]    ${arg1}   ${arg2}
  Print args    ${arg1}   ${arg2}

A Robot test case file imports this resource and uses above keyword as:

Resource keywords.robot
*** Test cases ***
Some test case
   Execute test step 1
   Execute test step 2
   Execute test step 3
   #Now use the Keyword defined in resource file with [Template]
   Do Something
   [Template]
    1   2
    3   4

Is there a way to achieve above requirement? As there are test steps which need to be repeated with arguments, not the whole test case. Thanks.

1
can you explain further what it is you're trying to do? It doesn't make a great deal of sense to me. If test steps need repeated with arguments, why not create a keyword to do what you want and pass it whatever you need?shicky

1 Answers

0
votes

One possible solution is to break the test case into two parts, where first would have the steps 1-3 and second part would have the template. You can condition it that the second part fails at the start if the first part fails.

You can test both variants by changing the 'Should be equal' to either pass or fail:

*** Variables ***
${Failed}   ${False}

*** Test cases ***
Some test case part 1
  Log   Keyword 1
  Log   Keyword 2
  Should Be Equal   1   1
  [Teardown]  Run Keyword If Test Failed    Set Suite Variable   ${Failed}   ${true}

Some test case part 2
  [Setup]   Run Keyword If   ${Failed}    Fail   Previous part failed
  [Template]   Do Something
    1   2
    3   4

*** Keywords ***
Do Something
  [Arguments]    ${arg1}   ${arg2}
  Log     ${arg1}, ${arg2}

Also, you can also add the first 3 steps into the setup if the simpler solution meets your needs.