Top Banner
Increase Automation to REST Understanding Web Services and how to test them Shiva and Fiona
35

Increase automation to rest

Apr 14, 2017

Download

Technology

vodQA
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Increase automation to rest

Increase Automation to REST

Understanding Web Services and how to test

them

Shiva and Fiona

Page 2: Increase automation to rest

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

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

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

Let see an example!...things get clearer when you can see them :)

Page 6: Increase automation to rest

An 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 7: Increase automation to rest

Another 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 8: Increase automation to rest

REpresentational State Transfer (REST)

● Uses HTTP(S) for CRUD operations

● Uniform Resource Identifiers (URIs)

● New alternative to SOAP

Page 9: Increase automation to rest

Statelessness

Client

Load Balancer

Node 1 Node 2

Page 10: Increase automation to rest

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

Requests and Responses...lets see some examples...

Page 12: Increase automation to rest

RequestRequest:

URI Method Headers DATA

Page 13: Increase automation to rest

ResponseResponse

HeadersResponse Code Data

Page 14: Increase automation to rest

Requests

Common request types:

● GET ● POST● PUT● DELETE

Page 15: Increase automation to rest

Response Codes

Outcome of a request:

● 1xx - Informational● 2xx - Success● 3xx - Redirection● 4xx - Client Error● 5xx - Server Error

Page 16: Increase automation to rest
Page 17: Increase automation to rest
Page 18: Increase automation to rest
Page 19: Increase automation to rest
Page 20: Increase automation to rest
Page 21: Increase automation to rest
Page 22: Increase automation to rest

QAs and Web Services...based on our experiences testing web services out in the wild...

Page 23: Increase automation to rest

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

The role of QAs

Page 25: Increase automation to rest

Demo - try it yourself!

Page 26: Increase automation to rest

Manual in browser test

https://petal-spirit.hyperdev.space/

Page 27: Increase automation to rest

Postman

Sample Postman Request:

Page 28: Increase automation to rest

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

Alternatives?

Cocoa Rest ClientIntelliJ REST Plugin

Page 30: Increase automation to rest

Let’s automate it! - JavaUse 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

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

Closing notes...time flies when you’re automating tests...

Page 33: Increase automation to rest

Suggestions

● Automate 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

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

Questions

?