0
votes

I want to pass multiple arguments to my TEST CASE in the most "elegant" way possible in Robot Framework. Scenario outline used in many framework allows to replace variable/keywords with the value from the table. Each row in the table is considered to be a scenario.

Is there any equivalent for scenario outline in Robot Framework?

For example we have test case like this:

Given users email is ${email}
And users password is ${password}
When user is on login page
Then user can sign in 

And we want to pass multiple emails and passwords to this test case as an array for example and run as many times as there is rows in this array. Can I do that without converting test case to a keyword to use templates?

3
Test cases don't take arguments. Can you be a bit more clear about what you mean by "pass arguments to my test case"? Are you asking about how to use test templates? - Bryan Oakley
I added an example of what I meant, I hope now it's clear. :) - Ewa

3 Answers

2
votes

You can't mix a BDD-style test with a data driven test. The closest you could come would be to write a keyword in the BDD style and then use that one keyword in the actual test case.

For example, you could do something like this:

*** Keywords ***
users email is 
    [Arguments]  ${email}
    set test variable  ${current email}  ${email}

users password is
    [Arguments]  ${password}
    set test variable  ${current password}  ${password}

User is on login page
    log  pretend we are on the login page

User can sign in
    should contain  ${current password}  !
    ...  password for ${current email} doesn't contain '!' (${current password})
    ...  values=False

User login template
    [Arguments]  ${email}  ${password}

    Given users email is  ${email}
    And users password is  ${password}
    When user is on login page
    Then user can sign in

*** Test Cases ***
Scenario: user can sign in with valid credentials
    [Template]  User login template

    # username        # password
    [email protected]   heymo!
    [email protected]     wiseguy!
    [email protected]   nyuknyuk!
1
votes

See this excelent blog about using Gherkin like Data tables in Robot Framework (it is an elegant workaround).

This is the example code:

*** Settings ***
Force Tags        OnlyThisOne
Resource          BDD.robot

*** Test Case ***     \          Closed Period             Open Period               Run Import On    Old Manager Stops    New Manager Starts
1                     Example    1.11.2009 - 30.11.2009    1.12.2009 - 31.12.2009    11.11.2009       30.11.2009           1.12.2009

2                     Example    1.11.2009 - 30.11.2009    1.12.2009 - 31.12.2009    1.11.2009        31.10.2009           1.11.2009

3                     Example    1.11.2009 - 30.11.2009    1.12.2009 - 31.12.2009    1.12.2009        30.11.2009           1.12.2009

*** Keyword ***
Example
    [Arguments]    ${periodClosed}    ${periodOpenAndModified}    ${importDay}    ${oldManagerValidUntil}    ${newManagerValidFrom}
    Given initialized criteria for bonus commercial
    And a branch B with branch manager M_OLD and employee E1
    And evaluation for E1 for period ${periodClosed} which is closed
    And evaluation for E1 for period ${periodOpenAndModified} which is open and modified
    When M_NEW becomes new manager of branch B
    And import service is called on ${importDay}
    Then the new branch manager of branch B is M_NEW valid from ${newManagerValidFrom}
    And branch manager M_OLD manages employee E until ${oldManagerValidUntil}
    And branch manager M_NEW manages employee E from ${newManagerValidFrom}
    And Evaluations for E1 still have the same content
    Given initialized criteria for bonus commercial
    But M_NEW becomes new manager of branch B
    But import service is called on ${importDay}
    And M_OLD becomes new manager of branch C

The BDD.robot resource file:

*** Settings ***
Documentation     Library de.codecentric.fourtexx.robot.ModelKeyword
#*** Test Cases ***
#Branch, Manager and Worker
#    Given a branch A with branch manager Boss and employee Worker
*** Keywords ***
the new branch manager of branch ${branch} is ${manager} valid from ${newManagerValidFrom}
    assert branch manager valid from    ${branch}    ${manager}    ${newManagerValidFrom}
initialized criteria for bonus commercial
    No Operation
a branch ${branch} with branch manager ${manager} and employee ${employee}
    No Operation
evaluation for ${employee} for period ${periodClosed} which is closed
    No Operation
evaluation for ${employee} for period ${periodOpenAndModified} which is open and modified
    No Operation
${manager} becomes new manager of branch ${branch}
    No Operation
import service is called on ${importDay}
    No Operation
branch manager ${manager} manages employee ${employee} until ${oldManagerValidUntil}
    No Operation
branch manager ${manager} manages employee ${employee} from ${newManagerValidFrom}
    No Operation
Evaluations for ${employee} still have the same content
    No Operation
assert branch manager valid from
    [Arguments]    ${arg1}    ${arg2}    ${arg3}
    Evaluate    True
0
votes
*** Test Cases ***
Scenario: eating cucumbers
    [Template]  Scenario Outline: eating cucumbers

    # Examples:
    # start  eat  left
    12       5    7
    20       5    15
    33       11   22
    35       15   20

*** Keywords ***
Scenario Outline: eating cucumbers
    [Arguments]  ${start}  ${eat}  ${left}
    Given there are ${start} cucumbers
    When I eat ${eat} cucumbers
    Then I should have ${left} cucumbers

font: https://gist.github.com/Tset-Noitamotua/8f06bd490918a56b0485630016aef60b