|
| 1 | +*** Settings *** |
| 2 | +Library Collections |
| 3 | +Library String |
| 4 | +Library RequestsLibrary |
| 5 | +Library OperatingSystem |
| 6 | + |
| 7 | +Suite Teardown Delete All Sessions |
| 8 | + |
| 9 | +*** Test Cases *** |
| 10 | +Get Requests |
| 11 | + [Tags] get |
| 12 | + Create Session google http://www.google.com |
| 13 | + Create Session bing https://www.bing.com verify=True |
| 14 | + ${resp}= Get Request google / |
| 15 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 16 | + ${resp}= Get Request bing / |
| 17 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 18 | + |
| 19 | +Get Requests with Url Parameters |
| 20 | + [Tags] get |
| 21 | + Create Session httpbin http://httpbin.org |
| 22 | + &{params}= Create Dictionary key=value key2=value2 |
| 23 | + ${resp}= Get Request httpbin /get params=${params} |
| 24 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 25 | + ${jsondata}= To Json ${resp.content} |
| 26 | + Should Be Equal ${jsondata['args']} ${params} |
| 27 | + |
| 28 | +Get HTTPS & Verify Cert |
| 29 | + [Tags] get get-cert |
| 30 | + Create Session httpbin https://httpbin.org verify=True |
| 31 | + ${resp}= Get Request httpbin /get |
| 32 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 33 | + |
| 34 | +Post Request With URL Params |
| 35 | + [Tags] post |
| 36 | + Create Session httpbin http://httpbin.org |
| 37 | + &{params}= Create Dictionary key=value key2=value2 |
| 38 | + ${resp}= Post Request httpbin /post params=${params} |
| 39 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 40 | + |
| 41 | +Post Request With No Data |
| 42 | + [Tags] post |
| 43 | + Create Session httpbin http://httpbin.org |
| 44 | + ${resp}= Post Request httpbin /post |
| 45 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 46 | + |
| 47 | +Put Request With No Data |
| 48 | + [Tags] put |
| 49 | + Create Session httpbin http://httpbin.org |
| 50 | + ${resp}= Put Request httpbin /put |
| 51 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 52 | + |
| 53 | +Post Request With No Dictionary |
| 54 | + [Tags] post |
| 55 | + Create Session httpbin http://httpbin.org debug=3 |
| 56 | + Set Test Variable ${data} some content |
| 57 | + ${resp}= Post Request httpbin /post data=${data} |
| 58 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 59 | + Should Contain ${resp.text} ${data} |
| 60 | + |
| 61 | +Put Request With URL Params |
| 62 | + [Tags] put |
| 63 | + Create Session httpbin http://httpbin.org |
| 64 | + &{params}= Create Dictionary key=value key2=value2 |
| 65 | + ${resp}= Put Request httpbin /put params=${params} |
| 66 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 67 | + |
| 68 | +Put Request With No Dictionary |
| 69 | + [Tags] put |
| 70 | + Create Session httpbin http://httpbin.org |
| 71 | + Set Test Variable ${data} some content |
| 72 | + ${resp}= Put Request httpbin /put data=${data} |
| 73 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 74 | + Should Contain ${resp.text} ${data} |
| 75 | + |
| 76 | +Post Requests |
| 77 | + [Tags] post |
| 78 | + Create Session httpbin http://httpbin.org |
| 79 | + &{data}= Create Dictionary name=bulkan surname=evcimen |
| 80 | + &{headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded |
| 81 | + ${resp}= Post Request httpbin /post data=${data} headers=${headers} |
| 82 | + Dictionary Should Contain Value ${resp.json()['form']} bulkan |
| 83 | + Dictionary Should Contain Value ${resp.json()['form']} evcimen |
| 84 | + |
| 85 | +Post With Unicode Data |
| 86 | + [Tags] post |
| 87 | + Create Session httpbin http://httpbin.org debug=3 |
| 88 | + &{data}= Create Dictionary name=度假村 |
| 89 | + &{headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded |
| 90 | + ${resp}= Post Request httpbin /post data=${data} headers=${headers} |
| 91 | + Dictionary Should Contain Value ${resp.json()['form']} 度假村 |
| 92 | + |
| 93 | +Post Request With Unicode Data |
| 94 | + [Tags] post |
| 95 | + Create Session httpbin http://httpbin.org debug=3 |
| 96 | + &{data}= Create Dictionary name=度假村 |
| 97 | + &{headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded |
| 98 | + ${resp}= Post Request httpbin /post data=${data} headers=${headers} |
| 99 | + Dictionary Should Contain Value ${resp.json()['form']} 度假村 |
| 100 | + |
| 101 | +Post Request With Data and File |
| 102 | + [Tags] post |
| 103 | + Create Session httpbin http://httpbin.org |
| 104 | + &{data}= Create Dictionary name=mallikarjunarao surname=kosuri |
| 105 | + Create File foobar.txt content=foobar |
| 106 | + ${file_data}= Get File foobar.txt |
| 107 | + &{files}= Create Dictionary file=${file_data} |
| 108 | + ${resp}= Post Request httpbin /post files=${files} data=${data} |
| 109 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 110 | + |
| 111 | +Put Requests |
| 112 | + [Tags] put |
| 113 | + Create Session httpbin http://httpbin.org |
| 114 | + &{data}= Create Dictionary name=bulkan surname=evcimen |
| 115 | + &{headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded |
| 116 | + ${resp}= Put Request httpbin /put data=${data} headers=${headers} |
| 117 | + Dictionary Should Contain Value ${resp.json()['form']} bulkan |
| 118 | + Dictionary Should Contain Value ${resp.json()['form']} evcimen |
| 119 | + |
| 120 | +Head Request |
| 121 | + [Tags] head |
| 122 | + Create Session httpbin http://httpbin.org |
| 123 | + ${resp}= Head Request httpbin /headers |
| 124 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 125 | + |
| 126 | +Options Request |
| 127 | + [Tags] options |
| 128 | + Create Session httpbin http://httpbin.org |
| 129 | + ${resp}= Options Request httpbin /headers |
| 130 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 131 | + Dictionary Should Contain Key ${resp.headers} allow |
| 132 | + |
| 133 | +Delete Request With URL Params |
| 134 | + [Tags] delete |
| 135 | + Create Session httpbin http://httpbin.org |
| 136 | + &{params}= Create Dictionary key=value key2=value2 |
| 137 | + ${resp}= Delete Request httpbin /delete ${params} |
| 138 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 139 | + |
| 140 | +Delete Request With No Data |
| 141 | + [Tags] delete |
| 142 | + Create Session httpbin http://httpbin.org |
| 143 | + ${resp}= Delete Request httpbin /delete |
| 144 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 145 | + |
| 146 | +Delete Request With Data |
| 147 | + [Tags] delete |
| 148 | + Create Session httpbin http://httpbin.org debug=3 |
| 149 | + &{data}= Create Dictionary name=bulkan surname=evcimen |
| 150 | + ${resp}= Delete Request httpbin /delete data=${data} |
| 151 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 152 | + Log ${resp.content} |
| 153 | + Comment Dictionary Should Contain Value ${resp.json()['data']} bulkan |
| 154 | + Comment Dictionary Should Contain Value ${resp.json()['data']} evcimen |
| 155 | + |
| 156 | +Patch Requests |
| 157 | + [Tags] patch |
| 158 | + Create Session httpbin http://httpbin.org |
| 159 | + &{data}= Create Dictionary name=bulkan surname=evcimen |
| 160 | + &{headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded |
| 161 | + ${resp}= Patch Request httpbin /patch data=${data} headers=${headers} |
| 162 | + Dictionary Should Contain Value ${resp.json()['form']} bulkan |
| 163 | + Dictionary Should Contain Value ${resp.json()['form']} evcimen |
| 164 | + |
| 165 | +Get Request With Redirection |
| 166 | + [Tags] get |
| 167 | + Create Session httpbin http://httpbin.org debug=3 |
| 168 | + ${resp}= Get Request httpbin /redirect/1 |
| 169 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 170 | + ${resp}= Get Request httpbin /redirect/1 allow_redirects=${true} |
| 171 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 172 | + |
| 173 | +Get Request Without Redirection |
| 174 | + [Tags] get |
| 175 | + Create Session httpbin http://httpbin.org |
| 176 | + ${resp}= Get Request httpbin /redirect/1 allow_redirects=${false} |
| 177 | + ${status}= Convert To String ${resp.status_code} |
| 178 | + Should Start With ${status} 30 |
| 179 | + |
| 180 | +Options Request With Redirection |
| 181 | + [Tags] options |
| 182 | + Create Session httpbin http://httpbin.org |
| 183 | + ${resp}= Options Request httpbin /redirect/1 |
| 184 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 185 | + ${resp}= Options Request httpbin /redirect/1 allow_redirects=${true} |
| 186 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 187 | + |
| 188 | +Head Request With Redirection |
| 189 | + [Tags] head |
| 190 | + Create Session httpbin http://httpbin.org |
| 191 | + ${resp}= Head Request httpbin /redirect/1 allow_redirects=${true} |
| 192 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 193 | + |
| 194 | +Head Request Without Redirection |
| 195 | + [Tags] head |
| 196 | + Create Session httpbin http://httpbin.org |
| 197 | + ${resp}= Head Request httpbin /redirect/1 |
| 198 | + ${status}= Convert To String ${resp.status_code} |
| 199 | + Should Start With ${status} 30 |
| 200 | + ${resp}= Head Request httpbin /redirect/1 allow_redirects=${false} |
| 201 | + ${status}= Convert To String ${resp.status_code} |
| 202 | + Should Start With ${status} 30 |
| 203 | + |
| 204 | +Post Request With Redirection |
| 205 | + [Tags] post |
| 206 | + Create Session jigsaw http://jigsaw.w3.org |
| 207 | + ${resp}= Post Request jigsaw /HTTP/300/302.html |
| 208 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 209 | + ${resp}= Post Request jigsaw /HTTP/300/302.html allow_redirects=${true} |
| 210 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 211 | + |
| 212 | +Post Request Without Redirection |
| 213 | + [Tags] post |
| 214 | + Create Session jigsaw http://jigsaw.w3.org debug=3 |
| 215 | + ${resp}= Post Request jigsaw /HTTP/300/302.html allow_redirects=${false} |
| 216 | + ${status}= Convert To String ${resp.status_code} |
| 217 | + Should Start With ${status} 30 |
| 218 | + |
| 219 | +Put Request With Redirection |
| 220 | + [Tags] put |
| 221 | + Create Session jigsaw http://jigsaw.w3.org debug=3 |
| 222 | + ${resp}= Put Request jigsaw /HTTP/300/302.html |
| 223 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 224 | + ${resp}= Put Request jigsaw /HTTP/300/302.html allow_redirects=${true} |
| 225 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 226 | + |
| 227 | +Put Request Without Redirection |
| 228 | + [Tags] put |
| 229 | + Create Session jigsaw http://jigsaw.w3.org |
| 230 | + ${resp}= Put Request jigsaw /HTTP/300/302.html allow_redirects=${false} |
| 231 | + ${status}= Convert To String ${resp.status_code} |
| 232 | + Should Start With ${status} 30 |
| 233 | + |
| 234 | +Do Not Pretty Print a JSON object |
| 235 | + [Tags] json |
| 236 | + Comment Define json variable. |
| 237 | + &{var}= Create Dictionary key_one=true key_two=this is a test string |
| 238 | + ${resp}= Get Request httpbin /get params=${var} |
| 239 | + Set Suite Variable ${resp} |
| 240 | + Should Be Equal As Strings ${resp.status_code} 200 |
| 241 | + ${jsondata}= To Json ${resp.content} |
| 242 | + Dictionaries Should Be Equal ${jsondata['args']} ${var} |
| 243 | + |
| 244 | +Pretty Print a JSON object |
| 245 | + [Tags] json |
| 246 | + Comment Define json variable. |
| 247 | + Log ${resp} |
| 248 | + ${output}= To Json ${resp.content} pretty_print=True |
| 249 | + Log ${output} |
| 250 | + Should Contain ${output} "key_one": "true" |
| 251 | + Should Contain ${output} "key_two": "this is a test string" |
| 252 | + Should Not Contain ${output} {u'key_two': u'this is a test string', u'key_one': u'true'} |
| 253 | + |
| 254 | +Set Pretty Print to non-Boolean value |
| 255 | + [Tags] json |
| 256 | + Comment Define json variable. |
| 257 | + Log ${resp} |
| 258 | + ${output}= To Json ${resp.content} pretty_print="Hello" |
| 259 | + Log ${output} |
| 260 | + Should Contain ${output} "key_one": "true" |
| 261 | + Should Contain ${output} "key_two": "this is a test string" |
| 262 | + Should Not Contain ${output} {u'key_two': u'this is a test string', u'key_one': u'true'} |
0 commit comments