Scripting without Authorization:
Swagger: https://www.videogamedb.uk/
Required Imports
import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;
import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.http.HttpDsl.*;
import static io.gatling.javaapi.http.HttpDsl.http;
/*
1.Http configuration
2.Scenerio Definition
3.Load Simulation
*/
private HttpProtocolBuilder httpProtocol= http
.baseUrl("https://www.videogamedb.uk/api")
.acceptHeader("application/json");
private ScenarioBuilder scn=scenario("My First Gatling Script")
.exec(
http("List all video games")
.get("/videogame")
);{
setUp(scn.injectOpen(atOnceUsers(1)))
.protocols(httpProtocol);
}Pause:
- We can use Pause command in between exec methods
Way 1:
.pause(5)
Way 2:
.pause(1,10)
Way 3:
import java.time.Duration;
.pause(Duration.ofMillis(5000));
How to check Response Status?
Way 1:
.check(status().is(200))Way 2:
.check(status().in(200,201,202)))Way 3:
.check(status().not(404),status().not(500)))
How to extract response and Assert using jsonpath?https://goessner.net/articles/JsonPath/
https://gatling.io/docs/gatling/reference/current/core/check/#jsonpath
For Example: .check(jsonPath("$[?(@.id==1)].name").is("Resident Evil 4")))How to extract response and Assert using jmespath?
Example:if it is number.check(jmesPath("[? id ==`1`].category").ofList().is(List.of("Shooter")))if it string.check(jmesPath("[? category== 'Shooter'].name").ofList().is(List.of("Resident Evil 4","Doom")))
No comments:
Post a Comment