https://github.com/mehdi-reza/api-automation
A utility for api automation
https://github.com/mehdi-reza/api-automation
api-automation automation integration-tests junit maven qa restassured swagger
Last synced: 7 months ago
JSON representation
A utility for api automation
- Host: GitHub
- URL: https://github.com/mehdi-reza/api-automation
- Owner: mehdi-reza
- Created: 2020-02-11T14:15:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-05T22:25:22.000Z (almost 2 years ago)
- Last Synced: 2025-01-22T08:11:27.295Z (9 months ago)
- Topics: api-automation, automation, integration-tests, junit, maven, qa, restassured, swagger
- Language: Java
- Size: 51.8 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# api-automation
[](https://circleci.com/gh/mehdi-reza/api-automation) [](https://coveralls.io/github/mehdi-reza/api-automation)
It uses swagger.json to find out all available operations and required parameters.
See sample/src/test/java/tez/TestScenario1.java. The test data is defined in src/test/resources/scenario.1.res and annotated in test class.
A JUnit test is defined as following:
```
@Scenario(resource = "scenario.1.res")
@TestMethodOrder(OrderAnnotation.class)
public class TestScenario1 extends ScenarioRunner {private Logger logger = LoggerFactory.getLogger(TestScenario1.class);
@Test
@Order(1)
public void testGetByPetId() {
logger.info("testGetByPetId");
// returns as restassured Response
Response response = callApi("get:/pet/{petId}");
// get a validatable response and assert
response.then().body("name", is("Trump"));
// save for later use in other test method
push("name", response.getBody().as(JsonObject.class, ObjectMapperType.GSON).get("name").getAsString());
logger.debug(response.asString());
}
@Test
@Order(2)
public void testFindByStatus() {
logger.info("testFindByStatus");
logger.info("peek(\"name\") returns {}", peek("name"));
String response = callApi("get:/pet/findByStatus").asString();
logger.debug(response);
}
}
```
Read further on assertions https://github.com/rest-assured/rest-assured/wiki/usage## Test data
```
[
"post:/pet/{petId}/uploadImage",
{
"consumes": "application/json",
"produces": "application/json",
"headers": {},
"data": {
"petId": 1,
"name": "Pet name"
}
},
"get:/pet/{petId}",
{
"consumes": "application/json",
"produces": "application/json",
"headers": {},
"data": {
"petId": 509194403
}
},
"get:/pet/findByStatus",
{
"consumes": "application/json",
"produces": "application/json",
"headers": {},
"data": {
"status": "sold"
}
},
"post:/pet/{petId}",
{
"consumes": "application/json",
"produces": "application/json",
"headers": {},
"data": {
"petId": 509194403,
"name": "Trump",
"status":"available"
}
},
"delete:/pet/{petId}",
{
"consumes": "application/json",
"produces": "application/json",
"headers": {
"api_key":"blah blah"
},
"data": {
"petId": 1964
}
},
"post:/pet",
{
"consumes": "application/json",
"produces": "application/json",
"headers": {},
"data": {
"body": {
"type": "dog",
"name": "doggie",
"photoUrls": ["http://bit.li/1","http://bit.li/2"],
"status":"sold"
}
}
}
]
```## Run tests
It reads the host from swagger.json, but you can override it with system property.
### Using swagger file
```mvn clean -Dswagger-file=/Users/vd-mehdi/TEMP/swagger.json -Dhost=https://petstore.swagger.io test```### Using swagger url
```mvn clean -Dswagger-url=https://petstore.swagger.io/v2/swagger.json -Dhost=https://petstore.swagger.io test```