Variable '${response}' not found

I’ve created an GET request keyword to get status of one device but I cannot use the function “List Should Contain Value” to validate the value of the key I have like " REACHABLE" or “NOT_REACHEABLE”.

 *** Test Cases *** 

    GET request to "${endpoint}"
        [Documentation]    1. Get Request for a given endpoint
        Log    URL:= ${endpoint}
        ${headers_dict}=    Create Dictionary    content-type=application/json
        ${base_url}=    get_base_url    ${endpoint}
        ${path}=    get_url_path    ${endpoint}
        Create Session    my-session    ${base_url}
        ${response}=    GET On Session    my-session    ${path}    headers=${headers_dict}
        ${json_data}=    Get Value From Json    ${response.json()}    $..value
        Log To console    ${json_data}
        List Should Contain Value    ${json_data}    NOT_REACHEABLE

    *** Test Cases ***

    GET TEST ENDPOINT                                                       
           GET request to "${endpoint}"

when I run the robot test case I have an error:

==============================================================================
Test1
==============================================================================
The following environment is under test :
.

GET TEST ENDPOINT                                                       
['NOT_REACHEABLE', '0', '4', '0', '1', '3', '100', '3', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0']
GET TEST ENDPOINT                                                       | FAIL |
Variable '${response}' not found.
------------------------------------------------------------------------------
Test 1                                                       | FAIL |
1 test, 0 passed, 1 failed
==============================================================================
Output:  /home/user/output.xml
Log:     /home/user/log.html
Report:  /home/user/report.html

Hard to say. ${response} has nothing to do with the List should contain value. The error is like raised when the value is retrieved from the json.

The test case looks good, though. As this is not the original code that raises the error, maybe there is a typo in ${response}= in the original code. That is usually the case when I get the error of a non existing variable I am sure is there.

2 Likes

i got it, i deleted a empty space. thanks