简体   繁体   中英

`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.

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM