3

I'm a robot framework newbie. I'm trying everything I can possible think of but for some reason I'm still unable to get the correct result. I'm trying to use the combination of Rest and RestInstance library to create session for a website then log API's response.

When I use the following method, I got this error.

15:52:15.075 FAIL ValueError: need more than 1 value to unpack

Get User API Response
${auth}=    Create List    ${example_email}    ${pwd}
Create Session    a    website/api/sign_in    ${headers}    123    ${auth}

When I use this method I cannot successfully create an active session with account log-in thus return incorrect info.

${headers}=    Create Dictionary    csrf_token=123
Create Session    a    website/api/sign_in    ${headers}    123    ${auth}
Rest.Get    website/api/sign_in
Rest.Output    response

I'm not understanding what I did wrong. If anyone could point the right directions with be gratefully appreciated.

2 Answers 2

2

You can do the following You are trying to do the correct thing just assign Rest.Ouput to a variable and that way you can log it or verify the response

*** Keywords ***
Sample Rest
  ${Response_Body_Verify} =  set variable  Sample Data
  ${headers}=    Create Dictionary    csrf_token=123
  Create Session    a    website/api/sign_in    ${headers}    123    ${auth}
  Rest.Get    website/api/sign_in
  ${Response} =  Rest.Output    response body
  should be equal  ${Response}  ${Response_Body_Verify}
Sign up to request clarification or add additional context in comments.

1 Comment

Hi thanks for helping me out. I tried your way but same thing with result above. Instead of getting empty response I'm getting server error as API response output. Not sure what I'm doing wrong.
1

The problem looks like with the way you're calling the Create Session - what's the purpose of the "123" in the arguments?

Look at the library's documentation - the argument at that position is cookies, and it must be a dictionary.

So either create a dictionary and pass it there:

${cookies}=     Create Dictionary    var=123
Create Session    a    website/api/sign_in    ${headers}    ${cookies}    ${auth}

, or explicitly map the arguments you're passing to the keyword's paramters:

Create Session    a    website/api/sign_in    headers=${headers}    auth=${auth}

(I've dropped the "123" from the second example - I can't be sure what's its purpose, e.g. for which parameter is it)

2 Comments

Hi I tried both way but still unable to create a log in session which return correct API response. I have to set csrf_token equal to cookie that's this website's verify security measure. For my ${auth} i have ${auth}= Create Dictionary email=${example_email} password=${pwd} Did I do anything wrong with ${auth}?
@Todor Minakov - can we intercept the calls happening and take the responses to variables to variable instead of additional calls. So this doesnt require any headers authorization tokens also as the user is pre logged?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.