asyrjasalo / RESTinstance

Robot Framework library for RESTful JSON APIs
https://pypi.org/project/RESTinstance
GNU Lesser General Public License v3.0
205 stars 84 forks source link

`String` keyword returns a list #49

Closed ec-wagner closed 5 years ago

ec-wagner commented 5 years ago

I was trying to store the result from the String keyword in a variable for further usage before I realized that it returns a list. I think it's not a real issue but it's not obvious that it returns a list without looking at the code of the keyword's implementation. Just want to share my experience in case somebody runs into it, too - and for my future me in case I run into it again :rofl:

Example:

REST.Post    /something    ${body}
Integer    response status    200
String     response body idToken
${token}=    String    response body idToken
Log To Console    ${token}
# console output
.['eyJhbGciOiJSUzI1NiIsImt ... ']

${token} contains some characters which I did not expected to be there: [' ... ']

Now that I know that String returns a list here is how the above should be done right

@{token}=    String    response body idToken
Log To Console    @{token}
Log To Console    @{token}[0]

Store the result in a list variable @{token} and access the value at index 0 --> @{token}[0] then I get what I actually wanted: eyJhbGciOiJSUzI1NiIsImt... - the token as a string.

Cheers

asyrjasalo commented 5 years ago

Use your own notes for this.

asyrjasalo commented 5 years ago

And yes, the keyword returns a list because JSONPath can match multiple. So one does not need check whether it is a single value or a a list, which would require too much keywords on the .robot side.

Please submit a Pull Request if one has a solution for this.