Append return values to list in Robot Framework

Viewed 16120

My test step creates 5 worker threads to upload a file to a server and returns the server HTTP response codes for each thread. I would like to append those to a list of response codes for each step.

TC001_Single_User_Upload
   [Documentation] Uploading single file by single user
   ${result}       single user test file upload    test_file.txt    test1   test
   Append To List  @{RESPONSE_LIST}    ${result}
   ${result}       single user test file upload    test_file.txt    test1   test
   Append To List  @{RESPONSE_LIST}    ${result}
   log variables
   log many     @{RESPONSE_LIST}

My current log files shows this :

20171127 13:59:01.911 - INFO - @{RESPONSE_LIST} = [ ]
20171127 13:59:01.911 - INFO - @{result} = [ <Response [201]> | <Response [201]> | <Response [201]> | <Response [201]> | <Response [201]> ]

Q: why is my @{RESPONSE_LIST} empty?

1 Answers

The first argument to Append to list needs to be a list object. When you use @, it's the same as if you took each element in the list and made it a new argument.

The solution is to change the @ to $:

Append To List  ${RESPONSE_LIST}    ${result}

From the robot framework user guide:

When a variable is used as a scalar like ${EXAMPLE}, its value will be used as-is. If a variable value is a list or list-like, it is also possible to use as a list variable like @{EXAMPLE}. In this case individual list items are passed in as arguments separately.

Related