简体   繁体   中英

Robot framework expected error failed: IndexError: list index out of range

I have a problem with Robot Framework.

Currently I do negative testing. I have a JSON response with length of an array 5 data (counting from 0). I want to check if the 6 th exists or not. If the 6 th data does not exist, the test is passed.

Here's my code:

${msg}    Run Keyword And Expect Error    Resolving variable '${json_response['data'][5]}' failed: IndexError: list index out of range    *    Log To Console    ${json_response['data'][5]}
Should Contain    ${msg}    failed: IndexError: list index out of range

The code gives failing results.

How can I solve this problem?

Better one would be to verify if list length is expecte one:

    ${json_length}    Get Length    ${json_response['data']}
    Should Be Equal As Integers    ${json_length}    6

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