From Mobile QA Perspective: Oleg Nikiforov
From Mobile QA Perspective: Oleg Nikiforov
From Mobile QA Perspective: Oleg Nikiforov
API
Oleg Nikiforov
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Agenda
Rest Assured
Practice
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
What is a RESTful API
An API that:
● Uses HTTP/HTTPS connection and standard HTTP methods (e.g., GET, POST, PUT,
PATCH and DELETE);
● Has a base URI
● Utilizes a media type that defines state transition data elements
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Why does a mobile QA test APIs
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
What is
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Rest Assured drawbacks
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Syntax
Assuming URI is "https://api.untappd.com/v4/", simple Rest Assured request looks like
this:
given().param("key", "value").get("https://api.untappd.com/v4/path");
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Syntax
● For a GET request with Form URL-Encoded params:
given().formParam("key", "value").get("https://api.untappd.com/v4/path");
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Assertions
● In request code:
given().get("https://api.untappd.com/v4/path")
.then.statusCode(200).statusLine("HTTP/1.1 200 OK");
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Authentication
Oauth2: given().auth().oauth2(accessToken);
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Rest Assured Spec Builders
It’s a powerful tool that allows reduction of duplicated code and structuring of
request and response types.
For example we can create separate request specs for non authenticated and
authenticated users or for authenticated users with different roles (admin,
common user, etc.)
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
RequestSpecificationBuilder
Create a common request builder:
RequestSpecificationBuilder requestSpecBuilder = new RequestSpecificationBuilder();
requestSpecificationBuilder.setBaseUri("https://api.untappd.com/v4/");
requestSpecificationBuilder.setContentType("application/json");
RequestSpecification requestSpec = requestSpecBuilder.build();
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
ResponseSpecificationBuilder
Create a response spec for all responses that should have a “200 OK” status:
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Use specifications
● In request:
given().spec(authenticatedRequestSpec).get("/auth/")
● In response:
given().get("https://api.untappd.com/v4/path").then().spec(response200Spec)
● Both:
given().spec(authenticatedRequestSpec).get("/auth/")
.then().spec(response200Spec)
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Response validation (JSON)
Our tests should check that response structure is correct, via:
● JSON Schema:
given().get("https://api.untappd.com/v4/path").then().assertThat()
.body(matchesJsonSchemaInClasspath("Authenticate.json"));
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Debugging
● Proxy:
● RestAssured.proxy("localhost", 8200);
● requestSpecificationBuilder
.setProxy("localhost", 8200);
requestSpecificationBuilder.addFilter(new RequestLoggingFilter());
requestSpecificationBuilder.addFilter(new ResponseLoggingFilter());
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Allure reports
Allure - an open-source framework designed to create test execution reports that are clear
to everyone in the team.
Pros:
● Open sourced
● Easy to integrate with Rest Assured
● Supports attachments: screenshots, videos, logs, etc.
● A lot of customization: named steps, tests description, etc.
● Shows trends and history
● Marks flaky tests
● Works with all popular CI tools
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Default report
Default report
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Allure report
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Demo
1. Code walk through
2. Pre-recorded demo of tests execution and reporting using Rest Assured
and Allure
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Useful links
http://rest-assured.io
https://github.com/rest-assured/rest-assured
https://github.com/rest-assured/rest-assured/wiki/usage
https://github.com/allure-framework/allure-java
https://testautomationu.applitools.com/automating-your-api-tests-with-rest-assured/
https://issart.com/blog/practical-guide-for-making-tests-execution-result-reports-more-comprehensible
https://medium.com/gradeup/rest-api-testing-using-rest-assured-56a6cf772ca3
https://untappd.com/api/docs
https://jsonpath.com/
https://github.com/onikiforov/rest-assured-untappd
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019
Skype: navisnobilite
Twitter: ddr3ams
Github: onikiforov
Testing backend API from mobile QA perspective using Rest Assured @ddr3ams #NTD2019