asyrjasalo / RESTinstance

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

facing problem to get response i.e. authentication key and get other response and store in a variable #38

Closed prajaktam closed 3 years ago

prajaktam commented 6 years ago

Hi Team, I am exploring RESTinstance, no prior experience in API test using Robot Framework so facing problem to get response i.e. authentication key and get other response and store in a variable.

Below is my dummy code .. it is not confidential:

*** Settings ***
Library         REST      https://xxxxxxxxxxxxxxx.in/
Suite Setup     Set Expectations

*** Keywords ***
Set Expectations
    Expect response     {"status":{"enum":[200, 201, 204, 401,405, 500]}}
    Expect response     {"seconds":{"maximum":1.5}}
*** Variables ***
${json}         { "email": "xxxxxxxx@xxxxx.com",   "password": "password" }

*** Test Cases ***
POST with valid params to create a user
    POST        /api-token-auth/          ${json}
    Integer     response status           200
    #[Teardown]  Output                    file_path=${OUTPUTDIR}/inst.json
    Output      response body   

Can you please help correct me, as I am not understanding how to implement.

and one more thing, I want to get a response from one request and from that response few information need to pass on to another request body. How can I do that?

cwienands commented 5 years ago

Unfortunately, I don't know if there is a more elegant way (no RF expert here), but this is how we access data from within the response: ${accessKey}= Set Variable ${response["body"]["accessKey"]}

Atihinen commented 3 years ago

Hi,

You can use Output keyword for this.

e.g. ${token}= Output response body accessKey