-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapi.robot
198 lines (165 loc) · 8.09 KB
/
api.robot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
*** Settings ***
Documentation API Test using RESTfulBooker application
Test Timeout 1 minute
Library RequestsLibrary
Library Collections
Library JsonValidator
Library Process
Library OperatingSystem
Suite Setup Ping Server
*** Variables ***
#ENDPOINTS ---
${BASE_URL} https://restful-booker.herokuapp.com
${AUTH} /auth
${BOOKING} /booking
#LOOP COUNTER ---
${COUNTER} ${1}
#HEADERS ---
${CONTENT_TYPE} application/json
#AUTH ---
${USERNAME} admin
${PASSWORD} password123
#BOOKING DETAILS ---
${FIRSTNAME} Anthony
${LASTNAME} ODonnell
${TOTALPRICE} 500
${DEPOSITPAID} true
${CHECKIN} 2019-08-30
${CHECKOUT} 2019-09-10
${ADDITIONALNEEDS} Clearly Defined Requirements
***Test Cases***
Obtain Token
[Tags] Auth
Obtain Auth Token
Get All Bookings IDs
[Tags] Get
Get All Booking IDs
Add New Booking
[Tags] Post
Add Booking
Validate New Booking Details
[Tags] Get
Check New Booking Details Are Correct
Get New Booking ID By Name
[Tags] Get
Get New Booking ID By Name
Get New Booking ID By Date
[Tags] Get
Get New Booking ID By Date
Update New Booking
[Tags] Put
Update New Booking
Partial Update New Booking
[Tags] Patch
Partial Update New Booking
#Delete All Bookings
# [Tags] Delete
# Delete All Bookings
***Keywords***
Ping Server
Create Session ping ${BASE_URL} verify=True
${response}= Get Request ping uri=/ping
Should Be Equal As Strings ${response.status_code} 201
Obtain Auth Token
${HEADERS}= Create Dictionary
... Content-Type=${CONTENT_TYPE}
... User-Agent=RobotFramework
Create Session Obtain Token ${BASE_URL} verify=True
${response}= Post Request Obtain Token uri=${AUTH} data={"username":"${USERNAME}","password":"${PASSWORD}"} headers=${HEADERS}
Should Be Equal As Strings ${response.status_code} 200
Element should exist ${response.content} .token
${TOKEN}= Get From Dictionary ${response.json()} token
Set Suite Variable ${TOKEN} ${TOKEN}
Get All Booking IDs
Create Session Get All ${BASE_URL} verify=True
${response}= Get Request Get All uri=${BOOKING}
Should Be Equal As Strings ${response.status_code} 200
@{BOOKINGIDS}= Create List
FOR ${item} IN @{response.json()}
Insert Into List ${BOOKINGIDS} ${COUNTER} ${item}[bookingid]
${COUNTER}= Set Variable ${COUNTER+1}
END
Set Suite Variable ${BOOKING_IDS} ${BOOKING_IDS}
Add Booking
${bookingdates}= Create Dictionary
... checkin=${CHECKIN}
... checkout=${CHECKOUT}
${newbooking}= Create Dictionary
... firstname=${FIRSTNAME}
... lastname=${LASTNAME}
... totalprice=${TOTALPRICE}
... depositpaid=${DEPOSITPAID}
... additionalneeds=${ADDITIONALNEEDS}
... bookingdates=${bookingdates}
${HEADERS}= Create Dictionary
... Content-Type=${CONTENT_TYPE}
... User-Agent=RobotFramework
Create Session Add Booking ${BASE_URL} verify=True
${response}= Post Request Add Booking uri=${BOOKING} data=${newbooking} headers=${HEADERS}
Should Be Equal As Strings ${response.status_code} 200
Element should exist ${response.content} .bookingid
${newid}= Select Elements ${response.content} .bookingid
Set Suite Variable ${NEW_ID} ${newid}[0]
Check New Booking Details Are Correct
Create Session Get New ${BASE_URL} verify=True
${response}= Get Request Get New uri=${BOOKING}/${NEW_ID}
Should Be Equal As Strings ${response.status_code} 200
Element Should Exist ${response.content} .firstname:contains("${FIRSTNAME}")
Element Should Exist ${response.content} .lastname:contains("${LASTNAME}")
Element Should Exist ${response.content} .totalprice:(${TOTALPRICE})
Element Should Exist ${response.content} .depositpaid:(${DEPOSITPAID})
Element Should Exist ${response.content} .additionalneeds:contains("${ADDITIONALNEEDS}")
${BOOKING_DATES_STRING}= Json To String ${response.json()["bookingdates"]}
Element Should Exist ${BOOKING_DATES_STRING} .checkin:(${CHECKIN})
Element Should Exist ${BOOKING_DATES_STRING} .checkin:(${CHECKOUT})
Get New Booking ID By Name
Create Session Get ID By Name ${BASE_URL} verify=True
${response}= Get Request Get ID By Name uri=${BOOKING}/?firstname=${FIRSTNAME}&lastname=${LASTNAME}
Should Be Equal As Strings ${response.status_code} 200
Element Should Exist ${response.content} .bookingid:(${NEW_ID})
Get New Booking ID By Date
Create Session Get ID By Date ${BASE_URL} verify=True
${response}= Get Request Get ID By Date uri=${BOOKING}/?checkin=2019-06-29&checkout=${CHECKOUT}
Should Be Equal As Strings ${response.status_code} 200
Element Should Exist ${response.content} .bookingid:(${NEW_ID})
Update New Booking
${bookingdates}= Create Dictionary
... checkin=${CHECKIN}
... checkout=${CHECKOUT}
${updatebooking}= Create Dictionary
... firstname=${FIRSTNAME}
... lastname=${LASTNAME}
... totalprice=0
... depositpaid=${DEPOSITPAID}
... additionalneeds=${ADDITIONALNEEDS}
... bookingdates=${bookingdates}
${HEADERS}= Create Dictionary
... Content-Type=${CONTENT_TYPE}
... Cookie=token=${TOKEN}
Create Session Update Booking ${BASE_URL} verify=True
${response}= Put Request Update Booking uri=${BOOKING}/${NEWID} data=${updatebooking} headers=${HEADERS}
Should Be Equal As Strings ${response.status_code} 200
Partial Update New Booking
${partialupdatebooking}= Create Dictionary
... totalprice=1000
${HEADERS}= Create Dictionary
... Content-Type=${CONTENT_TYPE}
... Cookie=token=${TOKEN}
Create Session Partial Update Booking ${BASE_URL} verify=True
${response}= Patch Request Partial Update Booking uri=${BOOKING}/${NEWID} data=${partialupdatebooking} headers=${HEADERS}
Should Be Equal As Strings ${response.status_code} 200
Delete All Bookings
${HEADERS}= Create Dictionary
... Content-Type=${CONTENT_TYPE}
... Cookie=token=${TOKEN}
Create Session Delete Booking ${BASE_URL} verify=True
${COUNTER}= Get length ${BOOKING_IDS}
FOR ${item} IN @{BOOKING_IDS}
${BOOKING_ID_TO_DELETE}= Set Variable /${item}
${response}= Delete Request Delete Booking uri=${BOOKING}${BOOKING_ID_TO_DELETE} headers=${HEADERS}
#Bug in response code, should be 204 is 201, ignoring and expecting 201 for the pass ;)
Should Be Equal As Strings ${response.status_code} 201
END
Get All Booking IDs
${CHECK}= Get length ${BOOKING_IDS}
Should Be Equal As Integers ${CHECK} 0