1

What would be the simplest way to use Robot Framework for testing a CRUD (or resource oriented) Web Service using JSON media type?

Example Read interaction:

GET /user/666 HTTP/1.1
Host: example.com


HTTP/1.1 404 Not Found

Example Create interaction:

POST /user HTTP/1.1
Host: example.com
Content-Type: application/json

{
    "firstname":"Webber",
    "lastname":"Jim"
}


HTTP/1.1 201 OK
Content-Type: application/json

{
    "id": 9780596805821,
    "firstname":"Webber",
    "lastname":"Jim"
}

1 Answer 1

1

One could use standard libraries and robotframework-requests like so:

*** Settings ***
Library        Collections
Library        OperatingSystem
Library        RequestsLibrary

*** Test Cases ****
Create User
         Create Session      example    http://example.com
  ${file_data}= 
    ...  Get Binary File     ${RESOURCES}${/}normal_user.json
  ${headers}=
    ...  Create Dictionary   Content-Type    application/json
  ${resp}=
    ...  Post Request        example    /user    data=${file_data}    headers=${headers}
         Should Be Equal As Strings
           ...               ${resp.status_code}  201
         Dictionary Should Contain Key
           ...               ${resp.json()}       id
Sign up to request clarification or add additional context in comments.

Comments

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.