Skip to main content

Restful Booker

Technology: Restful API, Web Service

Download the example from here.

*** Settings ***
Library RequestsLibrary
Library Collections
Suite Setup Authenticate as Admin

*** Test Cases ***
Get Bookings from Restful Booker
${body} Create Dictionary firstname=John
${response} GET ${body}
Status Should Be 200
Log List ${response.json()}
FOR ${booking} IN @{response.json()}
${response} GET${booking}[bookingid]
Log ${response.json()}
Log Cannot retrieve JSON due to invalid data

Create a Booking at Restful Booker
${booking_dates} Create Dictionary checkin=2022-12-31 checkout=2023-01-01
${body} Create Dictionary firstname=Hans lastname=Gruber totalprice=200 depositpaid=false bookingdates=${booking_dates}
${response} POST url= json=${body}
${id} Set Variable ${response.json()}[bookingid]
Set Suite Variable ${id}
${response} GET${id}
Log ${response.json()}
Should Be Equal ${response.json()}[lastname] Gruber
Should Be Equal ${response.json()}[firstname] Hans
Should Be Equal As Numbers ${response.json()}[totalprice] 200
Dictionary Should Contain Value ${response.json()} Gruber

Delete Booking
${header} Create Dictionary Cookie=token\=${token}
${response} DELETE url=${id} headers=${header}
Status Should Be 201 ${response}

*** Keywords ***
Authenticate as Admin
${body} Create Dictionary username=admin password=password123
${response} POST url= json=${body}
Log ${response.json()}
${token} Set Variable ${response.json()}[token]
Log ${token}
Set Suite Variable ${token}