├── README.md ├── api.robot └── requirements.txt /README.md: -------------------------------------------------------------------------------- 1 | # README # 2 | 3 | ![Robot framework](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Robot-framework-logo.png/250px-Robot-framework-logo.png) 4 | 5 | Robot Framework API automation example using [Mark Winteringham`s](https://twitter.com/2bittester) - [Restful-Booker](https://restful-booker.herokuapp.com/) 6 | 7 | By default this is using the live online version of RestfulBooker, but RestfulBooker can be ran locally, you can grab off git hub [here](https://github.com/mwinteringham/restful-booker) 8 | 9 | Documentation for the API can be found [here](https://restful-booker.herokuapp.com/apidoc/index.html) 10 | 11 | ### Who is this repository for? ### 12 | 13 | Newcomers to Robot Framework interested in automated API testing, looking for examples 14 | 15 | ### What is Robot Framework? ### 16 | 17 | Robot framework is a python based, open source test automation framework with great extensibility. Robot framework is cross platform and will run on Mac, Linux and Windows. 18 | 19 | See [here ](https://robotframework.org/)for Robot Framework home page 20 | 21 | 22 | ### What exactly is this? ### 23 | 24 | A basic Robot Framework API test suite with the following tests: 25 | 26 | * Obtaining Auth Token 27 | * Get All Bookings IDs 28 | * Add New Booking 29 | * Validate New Booking Details 30 | * Get New Booking ID By Name 31 | * Get New Booking ID By Date 32 | * Update New Booking 33 | * Partial Update New Booking 34 | * Delete All Bookings <- commented out by default 35 | 36 | The following supporting librarys are used in this suite alongside some of the built in librarys... 37 | 38 | [JSON Validator](https://github.com/peterservice-rnd/robotframework-jsonvalidator) 39 | 40 | [RequestsLibrary](https://github.com/bulkan/robotframework-requests) 41 | 42 | 43 | 44 | ### How do I get set up? ### 45 | 46 | * Install [Python 3](https://python.org/) 47 | * Clone or download this repository 48 | * Using the command line navigate in to the project folder and execute the command ```pip install -r requirements.txt``` this will install robot framework and the required supporting library's and their dependencies 49 | 50 | Once everything has been installed you can run the test suite from the command line in the projects folder with the command```robot .\api.robot``` 51 | 52 | By default it will run on the live site on the web, this can be changed at the command line to point to a local instance of restfulbooker by running ```robot -v BASE_URL:127.0.0.1:3001 .\api.robot``` or changing the ${BASEURL} variable in the api.robot file 53 | 54 | 55 | ### Who do I talk to? ### 56 | 57 | * Anthony O`Donnell - [LinkedIn](https://www.linkedin.com/in/anthonyodonnell) 58 | -------------------------------------------------------------------------------- /api.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Documentation API Test using RESTfulBooker application 3 | Test Timeout 1 minute 4 | Library RequestsLibrary 5 | Library Collections 6 | Library JsonValidator 7 | Library Process 8 | Library OperatingSystem 9 | Suite Setup Ping Server 10 | 11 | 12 | 13 | *** Variables *** 14 | #ENDPOINTS --- 15 | ${BASE_URL} https://restful-booker.herokuapp.com 16 | ${AUTH} /auth 17 | ${BOOKING} /booking 18 | #LOOP COUNTER --- 19 | ${COUNTER} ${1} 20 | #HEADERS --- 21 | ${CONTENT_TYPE} application/json 22 | #AUTH --- 23 | ${USERNAME} admin 24 | ${PASSWORD} password123 25 | #BOOKING DETAILS --- 26 | ${FIRSTNAME} Anthony 27 | ${LASTNAME} ODonnell 28 | ${TOTALPRICE} 500 29 | ${DEPOSITPAID} true 30 | ${CHECKIN} 2019-08-30 31 | ${CHECKOUT} 2019-09-10 32 | ${ADDITIONALNEEDS} Clearly Defined Requirements 33 | 34 | 35 | 36 | 37 | ***Test Cases*** 38 | Obtain Token 39 | [Tags] Auth 40 | Obtain Auth Token 41 | 42 | Get All Bookings IDs 43 | [Tags] Get 44 | Get All Booking IDs 45 | 46 | Add New Booking 47 | [Tags] Post 48 | Add Booking 49 | 50 | Validate New Booking Details 51 | [Tags] Get 52 | Check New Booking Details Are Correct 53 | 54 | Get New Booking ID By Name 55 | [Tags] Get 56 | Get New Booking ID By Name 57 | 58 | Get New Booking ID By Date 59 | [Tags] Get 60 | Get New Booking ID By Date 61 | 62 | Update New Booking 63 | [Tags] Put 64 | Update New Booking 65 | 66 | Partial Update New Booking 67 | [Tags] Patch 68 | Partial Update New Booking 69 | 70 | #Delete All Bookings 71 | # [Tags] Delete 72 | # Delete All Bookings 73 | 74 | ***Keywords*** 75 | Ping Server 76 | Create Session ping ${BASE_URL} verify=True 77 | ${response}= Get Request ping uri=/ping 78 | Should Be Equal As Strings ${response.status_code} 201 79 | 80 | Obtain Auth Token 81 | ${HEADERS}= Create Dictionary 82 | ... Content-Type=${CONTENT_TYPE} 83 | ... User-Agent=RobotFramework 84 | Create Session Obtain Token ${BASE_URL} verify=True 85 | ${response}= Post Request Obtain Token uri=${AUTH} data={"username":"${USERNAME}","password":"${PASSWORD}"} headers=${HEADERS} 86 | Should Be Equal As Strings ${response.status_code} 200 87 | Element should exist ${response.content} .token 88 | ${TOKEN}= Get From Dictionary ${response.json()} token 89 | Set Suite Variable ${TOKEN} ${TOKEN} 90 | 91 | 92 | Get All Booking IDs 93 | Create Session Get All ${BASE_URL} verify=True 94 | ${response}= Get Request Get All uri=${BOOKING} 95 | Should Be Equal As Strings ${response.status_code} 200 96 | @{BOOKINGIDS}= Create List 97 | FOR ${item} IN @{response.json()} 98 | Insert Into List ${BOOKINGIDS} ${COUNTER} ${item}[bookingid] 99 | ${COUNTER}= Set Variable ${COUNTER+1} 100 | END 101 | Set Suite Variable ${BOOKING_IDS} ${BOOKING_IDS} 102 | 103 | 104 | Add Booking 105 | ${bookingdates}= Create Dictionary 106 | ... checkin=${CHECKIN} 107 | ... checkout=${CHECKOUT} 108 | ${newbooking}= Create Dictionary 109 | ... firstname=${FIRSTNAME} 110 | ... lastname=${LASTNAME} 111 | ... totalprice=${TOTALPRICE} 112 | ... depositpaid=${DEPOSITPAID} 113 | ... additionalneeds=${ADDITIONALNEEDS} 114 | ... bookingdates=${bookingdates} 115 | ${HEADERS}= Create Dictionary 116 | ... Content-Type=${CONTENT_TYPE} 117 | ... User-Agent=RobotFramework 118 | Create Session Add Booking ${BASE_URL} verify=True 119 | ${response}= Post Request Add Booking uri=${BOOKING} data=${newbooking} headers=${HEADERS} 120 | Should Be Equal As Strings ${response.status_code} 200 121 | Element should exist ${response.content} .bookingid 122 | ${newid}= Select Elements ${response.content} .bookingid 123 | Set Suite Variable ${NEW_ID} ${newid}[0] 124 | 125 | 126 | Check New Booking Details Are Correct 127 | Create Session Get New ${BASE_URL} verify=True 128 | ${response}= Get Request Get New uri=${BOOKING}/${NEW_ID} 129 | Should Be Equal As Strings ${response.status_code} 200 130 | Element Should Exist ${response.content} .firstname:contains("${FIRSTNAME}") 131 | Element Should Exist ${response.content} .lastname:contains("${LASTNAME}") 132 | Element Should Exist ${response.content} .totalprice:(${TOTALPRICE}) 133 | Element Should Exist ${response.content} .depositpaid:(${DEPOSITPAID}) 134 | Element Should Exist ${response.content} .additionalneeds:contains("${ADDITIONALNEEDS}") 135 | ${BOOKING_DATES_STRING}= Json To String ${response.json()["bookingdates"]} 136 | Element Should Exist ${BOOKING_DATES_STRING} .checkin:(${CHECKIN}) 137 | Element Should Exist ${BOOKING_DATES_STRING} .checkin:(${CHECKOUT}) 138 | 139 | 140 | Get New Booking ID By Name 141 | Create Session Get ID By Name ${BASE_URL} verify=True 142 | ${response}= Get Request Get ID By Name uri=${BOOKING}/?firstname=${FIRSTNAME}&lastname=${LASTNAME} 143 | Should Be Equal As Strings ${response.status_code} 200 144 | Element Should Exist ${response.content} .bookingid:(${NEW_ID}) 145 | 146 | 147 | Get New Booking ID By Date 148 | Create Session Get ID By Date ${BASE_URL} verify=True 149 | ${response}= Get Request Get ID By Date uri=${BOOKING}/?checkin=2019-06-29&checkout=${CHECKOUT} 150 | Should Be Equal As Strings ${response.status_code} 200 151 | Element Should Exist ${response.content} .bookingid:(${NEW_ID}) 152 | 153 | 154 | Update New Booking 155 | ${bookingdates}= Create Dictionary 156 | ... checkin=${CHECKIN} 157 | ... checkout=${CHECKOUT} 158 | ${updatebooking}= Create Dictionary 159 | ... firstname=${FIRSTNAME} 160 | ... lastname=${LASTNAME} 161 | ... totalprice=0 162 | ... depositpaid=${DEPOSITPAID} 163 | ... additionalneeds=${ADDITIONALNEEDS} 164 | ... bookingdates=${bookingdates} 165 | ${HEADERS}= Create Dictionary 166 | ... Content-Type=${CONTENT_TYPE} 167 | ... Cookie=token=${TOKEN} 168 | Create Session Update Booking ${BASE_URL} verify=True 169 | ${response}= Put Request Update Booking uri=${BOOKING}/${NEWID} data=${updatebooking} headers=${HEADERS} 170 | Should Be Equal As Strings ${response.status_code} 200 171 | 172 | 173 | Partial Update New Booking 174 | ${partialupdatebooking}= Create Dictionary 175 | ... totalprice=1000 176 | ${HEADERS}= Create Dictionary 177 | ... Content-Type=${CONTENT_TYPE} 178 | ... Cookie=token=${TOKEN} 179 | Create Session Partial Update Booking ${BASE_URL} verify=True 180 | ${response}= Patch Request Partial Update Booking uri=${BOOKING}/${NEWID} data=${partialupdatebooking} headers=${HEADERS} 181 | Should Be Equal As Strings ${response.status_code} 200 182 | 183 | 184 | Delete All Bookings 185 | ${HEADERS}= Create Dictionary 186 | ... Content-Type=${CONTENT_TYPE} 187 | ... Cookie=token=${TOKEN} 188 | Create Session Delete Booking ${BASE_URL} verify=True 189 | ${COUNTER}= Get length ${BOOKING_IDS} 190 | FOR ${item} IN @{BOOKING_IDS} 191 | ${BOOKING_ID_TO_DELETE}= Set Variable /${item} 192 | ${response}= Delete Request Delete Booking uri=${BOOKING}${BOOKING_ID_TO_DELETE} headers=${HEADERS} 193 | #Bug in response code, should be 204 is 201, ignoring and expecting 201 for the pass ;) 194 | Should Be Equal As Strings ${response.status_code} 201 195 | END 196 | Get All Booking IDs 197 | ${CHECK}= Get length ${BOOKING_IDS} 198 | Should Be Equal As Integers ${CHECK} 0 -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | attrs==19.1.0 2 | certifi==2019.6.16 3 | chardet==3.0.4 4 | decorator==4.4.0 5 | idna==2.8 6 | jsonpath-rw==1.4.0 7 | jsonpath-rw-ext==1.2.2 8 | jsonschema==3.0.2 9 | objectpath==0.6.1 10 | pbr==5.4.2 11 | ply==3.11 12 | pyjsonselect==0.2.2 13 | pyrsistent==0.15.4 14 | requests==2.22.0 15 | robotframework==3.1.2 16 | robotframework-jsonvalidator==1.0.1 17 | robotframework-requests==0.5.0 18 | six==1.12.0 19 | urllib3==1.26.5 --------------------------------------------------------------------------------