kishore
kishore

Reputation: 1

`Test Case Timeout in robot framework with test case variable instead of variable defined in *** Variables *** section`

*** Settings ***
Library         Collections
Documentation    Suite description
Test Timeout    60 minutes

*** Test Cases ***
Test title
${TEST_TIMEOUT1}  set variable  120   
log to console  ${TEST_TIMEOUT1}
[Timeout]  ${TEST_TIMEOUT1} minutes

I am trying to update the default Test Timeout of 60 minutes with Test case time [TIMEOUT] with variable ${TEST_TIMEOUT1}. I want to use a variable instead of hard-coded value. with hard-coded value [TIMEOUT] is working fine.But facing below error if i use test case variable substitution

Setting test timeout failed: Variable '${TEST_TIMEOUT1}' not found. Can you help how to fix this issue.

Upvotes: 0

Views: 2065

Answers (1)

pavelsaman
pavelsaman

Reputation: 8352

The problem is that

*** Test Cases ***
Test title
    ${TEST_TIMEOUT1}  set variable  120   
    log to console  ${TEST_TIMEOUT1}
    [Timeout]  ${TEST_TIMEOUT1} minutes

is not executed in this order. [Timeout] belongs to the test case setting, so it's executed before those first two lines. It's setting after all, so it makes sense to execute it first and then run the actual test steps.

Solution is easy, define ${TEST_TIMEOUT1} outside the test case, for example:

*** Settings ***
Test Timeout    60 minutes

*** Variables ***
${TEST_TIMEOUT1}=    120 minutes

*** Test Cases ***
Test title
    [Timeout]  ${TEST_TIMEOUT1}

Then the default timeout will be 60 minutes, but in Test title it will be overriden and value of 120 minutes will be used.

Further readings:

Upvotes: 3

Related Questions