2
votes

I am looking to make a new user per test suite to ensure state. I have setup keywords to achieve this as show below, the issue is getting the "USERNAME" accessible to the tests without making it a global (and thus preventing parallel running)

I currently receive a "Cannot Set Test variable when no test is started" error produced by robot.

MainTestSuite.robot

*** Settings ***
Resource           base.robot
Suite Setup        Suite Start Default
Suite Teardown     Suite teardown Default

*** Test Cases ***
Test One
    [Setup]        Login    ${USERNAME}
    Do testing
...

Base.robot

*** Keywords ***
Suite Start Default
    ${USERNAME}    Create User

Suite Teardown Default
    Delete User    ${USERNAME}

Possibly i have missed some variable definition, but happy to reformat to get the intended result

1

1 Answers

6
votes

To set a suite-level variable in the setup (ie: a variable accessible only to the tests in the suite), use Set Suite Variable

*** Keywords ***
Suite Start Default
    ${USERNAME}    Create User
    set suite variable   ${USERNAME}