Giter Site home page Giter Site logo

api-automation's Introduction

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);
  }
  
}

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.