increase automation to rest
TRANSCRIPT
![Page 1: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/1.jpg)
Increase Automation to REST
Understanding Web Services and how to test them
Shiva and Fiona
![Page 2: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/2.jpg)
Key Take Aways:
❏ What Web Services are and why we use them
❏ How to test a Web Service in multiple ways
❏ Increased familiarity with test automation
![Page 3: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/3.jpg)
Web Services
● Interface to provide access to functionality
● Uses HTTP/HTTPS/SMTP for communication
● Communicates using JSON/XML/CSV/Plain Text etc.
![Page 4: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/4.jpg)
When and Why
Same functionality multiple UIs:● Customise cross platform● Multiple apps● Different vendors
Being able to implement one service and use that functionality across all these different displays
![Page 5: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/5.jpg)
Let see an example!...things get clearer when you can see them :)
![Page 6: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/6.jpg)
An Example
Website serving request:Weather Underground
Underlying HTTP request:curl -X GET http://api.wunderground.com/api/e896598d74613088/conditions/q/zmw:00000.1.43128.json
![Page 7: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/7.jpg)
Another Example
Booking a ticket with Orange Bus via different agencies
RedBus UI TravelYari UI Orange Bus UI
Book a seat
Book a seat
Get bus details
Orange Bus Web Service
![Page 8: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/8.jpg)
REpresentational State Transfer (REST)
● Uses HTTP(S) for CRUD operations
● Uniform Resource Identifiers (URIs)
● New alternative to SOAP
![Page 9: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/9.jpg)
Statelessness
Client
Load Balancer
Node 1 Node 2
![Page 10: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/10.jpg)
What about APIs?
● Part of the web service which receives requests/sends responses
● Has one or more endpoints
● Documented contract
![Page 11: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/11.jpg)
Requests and Responses...lets see some examples...
![Page 12: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/12.jpg)
Request
Request:
URI Method Headers DATA
![Page 13: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/13.jpg)
Response
Response
HeadersResponse Code Data
![Page 14: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/14.jpg)
Requests
Common request types:
● GET ● POST● PUT● DELETE
![Page 15: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/15.jpg)
Response Codes
Outcome of a request:
● 1xx - Informational● 2xx - Success● 3xx - Redirection● 4xx - Client Error● 5xx - Server Error
![Page 16: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/16.jpg)
![Page 17: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/17.jpg)
![Page 18: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/18.jpg)
![Page 19: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/19.jpg)
![Page 20: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/20.jpg)
![Page 21: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/21.jpg)
![Page 22: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/22.jpg)
QAs and Web Services...based on our experiences testing web services out in the wild...
![Page 23: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/23.jpg)
How testing helps
● Business issues first then the presentation issues
● Early feedback● Debug in different layers● Save time retesting● More confident app works● Release more frequently● Lots more….
![Page 24: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/24.jpg)
The role of QAs
![Page 25: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/25.jpg)
Demo - try it yourself!
![Page 26: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/26.jpg)
Manual in browser test
https://petal-spirit.hyperdev.space/
![Page 27: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/27.jpg)
Postman
Sample Postman Request:
![Page 28: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/28.jpg)
curl
Sample Curl Request:
curl -X GET https://petal-spirit.hyperdev.space/dreams -H "Content-Type: application/json" -i
> curl _
![Page 29: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/29.jpg)
Alternatives?
Cocoa Rest Client IntelliJ REST Plugin
![Page 30: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/30.jpg)
Let’s automate it! - Java
Use Library: UniRest (Java)
Sample Test Scenario
public class TestDreams {@Testpublic void testGetDreams() throws UnirestException { System.out.println("Testing Get Dreams.....");
String url = "https://petal-spirit.hyperdev.space/dreams";HttpResponse<JsonNode> jsonResponse = Unirest.get(url)
.header("Content-Type", "application/json").asJson();Assert.assertEquals(200, jsonResponse.getStatus());Assert.assertNotNull(jsonResponse.getBody());
}}
![Page 31: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/31.jpg)
Let’s automate it! - Python
Use Package: Requests (Python)
Sample Test Scenario
import unittestimport requests
class TestDreams(unittest.TestCase):def setUp(self):
self.url = 'http://petal-spirit.hyperdev.space/dreams'
def test_should_verify_get_dreams(self): print("Verifying Get Dreams....") headers = {"Content-Type": "application/json"} res = requests.get(url=self.url, headers=headers, verify=False) self.assertEqual(200, res.status_code, "Response code doesn't match") self.assertTrue(res.json())
![Page 32: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/32.jpg)
Closing notes...time flies when you’re automating tests...
![Page 33: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/33.jpg)
Suggestions
● Test as you go● Cross role pairing● Integrate with build pipeline● If the service is broken no need
to test UI● Spread the word! :)
![Page 34: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/34.jpg)
Key Take Aways:
❏ What Web Services are and why we use them
❏ How to test a Web Service in multiple ways
❏ Increased familiarity with test automation
![Page 35: Increase automation to rest](https://reader031.vdocuments.mx/reader031/viewer/2022030223/5883569d1a28ab42678b5747/html5/thumbnails/35.jpg)
Questions
?