WebServiceAutomationBuild
Sample Framework
First We shall start automating using RestAssured
- RestAssured uses DSL (Domain Specific Language) for developing a test code.
- Key-words:
-
Given: Scenario Setup/Context builder :
- Example:
- Configuration
- Headers
- Parameters ,etc.,
- Example:
-
When: Do Some action:
- Example:
- GET an endpoint
- Post To an Endpoint
- ,etc.,
- Example:
-
Then: Validate the Response/ Assertions: - Example: - Check Response code - Check Response body - Extract data from Response and validate the fields,etc.,
-
BaseClass contains: -->Extends --> tests
- Base URI/PORT
- Default Headers
- Other Config
Request & Response Specifications:
-
Request Specification
- Actions to include in every HTTP Request
- Header, Cookies, Form Parameters, Base URL, BAse Port
-
Response Specifications
- Actions to be taken After every HTTP request
- Check Status code, Check Content-type, Response Time, Check Headers.
-You can use the builder to construct a request specification. The specification can be used as e.g.
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
RequestSpecification requestSpec = new RequestSpecBuilder().addParam("parameter1", "value1").build();
RequestSpecification requestSpec = new RequestSpecBuilder().addParameter("parameter1", "value1").build(); given(). spec(requestSpec). expect(). body("x.y.z", equalTo("something")). when(). get("/something");
Automating the application: https://github.com/james-willett/VideoGameDB
HTTP Verbs:
- GET --> Retrevie Data from an End point
- POST --> Send data to an end point
- PUT --> update a resource
- DELETE-> Delete a resource
- more information can be obtained from https://github.com/rest-assured/rest-assured/wiki/Usage
#Serialization: Get a Json Object -->Convert into Pojo -->Use pojo in restAssured code to create new game.
#XML Schema
- Get an XML Object --> Generate an XSD SChema -->Place the schema in our project-->Run a test that validates against the schema
#Json Schema
- Get a JSON Object -->Generate a JSON SChema--> place the schema in project--> Run Tests against it. http://jsonschema.net/
#JSON response to Pojo
- Genereated a POJO class for payload using for serialization using http://pojo.sodhanalibrary.com/
- Add a default constructor -->required by com.fasterxml.jackson.core
- response.getBody( ).as(ClassName.class); should parse the response to Pojo.
#Meassure Response Time
- Capture Response Time
- Asser on Response Time
- Add response time assertion to response specification.
##Payload management -JSON to Pojo ==>http://pojo.sodhanalibrary.com/ -XML to POJO ==?http://pojo.sodhanalibrary.com/
##Generate XSD from XML response
Generate JSON Schema from Json response
#Allure Reports:
- Report will be generated to target/site/allure-maven-plugin folder.
To open the report you can use the following command:
mvn io.qameta.allure:allure-maven:serve
- There is another way of generating the report. The generated report can be opened here "target/site/allure-maven-plugin/index.html".
The command to generate the report is the following:
mvn io.qameta.allure:allure-maven:report
@Epic @Features @Stories/@Story @Severity(SeverityLevel.BLOCKER) @Description("In this cool test we will check cool thing") @Step @Attachment @Link