web service testing_final.pptx

28
Manjyot Singh Ruchika Rawat API Testing Workshop

Upload: vodqancr

Post on 12-Apr-2017

116 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Web service testing_final.pptx

Manjyot SinghRuchika Rawat

API Testing Workshop

Page 2: Web service testing_final.pptx

Introduction[ { "speaker": { "id": "007", "name": "Manjyot Singh", "role": "QA" } }, { "speaker": { "id": "001", "name": "Ruchika Rawat", "role": "QA" } }]

Page 3: Web service testing_final.pptx

What is a web service – QA point of view?

A method of communication between two web applications

Page 4: Web service testing_final.pptx

Let’s play a video...

Page 5: Web service testing_final.pptx

Example

Page 6: Web service testing_final.pptx

Classifications

Page 7: Web service testing_final.pptx

REST Vs SOAP

Page 8: Web service testing_final.pptx

???

Page 9: Web service testing_final.pptx

SOAP

● Simple object access protocol.

● Used for exchange of information on distributed platform using XML.

● Works mainly with HTTP, HTTPS.

● HTTP makes SOAP go around firewalls.

● Slower when using large XML messages.

Page 10: Web service testing_final.pptx

???

Page 11: Web service testing_final.pptx

REST● Representational State Transfer.

● REST architectural style, data and functionality are considered resources and are accessed using Uniform Resource Identifiers (URIs).

● Resources are manipulated using a fixed set of four create, read, update, delete operations: PUT, GET, POST, and DELETE.

● Formats - XML, plain text, PDF and JSON.

Page 12: Web service testing_final.pptx

REST - ExampleResponseRequest

http://localhost:9000/users/1

Page 13: Web service testing_final.pptx

Let’s talk about...

Page 14: Web service testing_final.pptx

Why REST-assured ?

● Java Domain Specific Language (DSL) for testing web services

● Built on top of HTTPBuilder

● Supports response parsing

● Supports in-built assertions

● Supports BDD syntax

Page 15: Web service testing_final.pptx

Setup (Requirement)

● Install JDK

● IDE (Eclipse/Intellij)

● Build Tool (gradle) *optional

● Rest-assured jars

● Hamcrest-matchers jars

● Junit jars

Page 16: Web service testing_final.pptx

Understanding a Request

Page 17: Web service testing_final.pptx

Simple GET Request

given().contentType(“application/json”).

when().get("/users").then().assertThat().statusCode(HttpStatus.SC_OK);

Page 18: Web service testing_final.pptx

GET Request given().

contentType(“application/json”). when(). get("/users/1"). then(). assertThat(). body("userId", equalTo(1)). body("userName", equalTo("Robert")). body("employer", equalTo("facebook")). body("location.state", equalTo("California")). body("location.city", equalTo("San Jose"));

Page 19: Web service testing_final.pptx

POST Request

given(). contentType("application/json"). body("[{\"userName\":\"Jayant2\",\"employer\":\"Google\",\"location\":{\"state\":\"California\",\"city\":\"Mountain View\"}}]").

when(). post("/users").

then(). assertThat().body("userName", hasItems("Jayant2"));

Page 20: Web service testing_final.pptx

PUT Request int userId = 1;

given(). contentType("application/json"). when(). body("{\"userName\":\"Taylor\"}").

put("/users/" + userId). then(). statusCode(HttpStatus.SC_OK). body("userName", equalTo("Taylor"));

Page 21: Web service testing_final.pptx

DELETE Request int userId = 9;

given().

when(). delete("/users/" + userId).

then(). statusCode(HttpStatus.SC_OK);

Page 22: Web service testing_final.pptx

Response parsingResponse response = given().

contentType(ContentType.JSON).when(). get("/users/5"). then(). extract().response();

String userName = response.path("userName"); String userCity = response.path("location.city");

Assert.assertTrue(userName.equals("Steve")); Assert.assertTrue(userCity.equals("San

Francisco"));

Page 23: Web service testing_final.pptx

Json parsing

String jsonResponse = get("/users/5").asString();

JsonPath jsonPath = new JsonPath(json).setRoot("location");

String state = jsonPath.getString("state"); String city = jsonPath.getString("city");

Assert.assertTrue(state.equals("California")); Assert.assertTrue(city.equals("San Francisco"));

Page 24: Web service testing_final.pptx

AuthenticationString sessionToken = given(). body("{\"userName\" : \"ruchikar\",\"password\" : \"P@ssW0rd\"}").when(). with(). header("Content-Type", "application/json"). header("X-Forwarded-Proto", "https"). post("/sessionTokens").then(). statusCode(200). contentType(ContentType.JSON). extract(). response().path("response.sessionToken");

Page 25: Web service testing_final.pptx

given().

when().with().

header("X-Forwarded-Proto", "https"). header("Content-Type", "application/json"). header("X-Auth", sessionToken).

get(“/users”).then(). statusCode(HttpStatus.SC_OK). contentType(ContentType.JSON);

contd...

Page 26: Web service testing_final.pptx

Other available tools/api

Page 27: Web service testing_final.pptx

References

Rest-Assured: https://github.com/jayway/rest-assured

Github : https://github.com/jayway/rest-assured/wiki/Usage

Workshop Test framework: https://github.com/ruchikar/RestAssuredTest

Workshop WebService: https://github.com/syedatifakhtar/VodQABomb

Page 28: Web service testing_final.pptx

Questions