-
Notifications
You must be signed in to change notification settings - Fork 0
@JPostmanExecutor
@JPostmanExecutor marks a method that executes the current JPostman request.
Executor methods return an ApiExecutor, such as a REST Assured executor, Java HttpClient executor, Playwright executor, or Unirest executor.
@JPostmanExecutor
public ApiExecutor defaultExecutor(TestNgContext context) {
return RestAssuredExecutor.apply(context.request());
}Use name when a response or runner should select a specific executor.
@JPostmanExecutor(name = "auth")
public ApiExecutor authExecutor(TestNgContext context) {
return RestAssuredExecutor.apply(context.request())
.auth()
.oauth2(context.cache("token"));
}Then use:
@JPostmanResponse(
request = "Get current auth user",
executor = "auth"
)
@Test
public void getCurrentAuthUser() {
}@JPostmanExecutor supports these signatures:
public ApiExecutor executor(TestNgContext context)public ApiExecutor executor(TestNgContext context, String methodName)public ApiExecutor executor(TestNgContext context, String methodName, String requestName)The same pattern works for JUnitContext.
The methodName parameter is the current test or dependency method name.
@JPostmanExecutor
public ApiExecutor myExecutor(TestNgContext context, String methodName) {
log.debug("Running method: {}", methodName);
return RestAssuredExecutor.apply(context.request());
}The requestName parameter is the current Postman request name.
This is especially useful with @JPostmanRunner, because one test method can run many requests.
@JPostmanExecutor
public ApiExecutor myExecutor(TestNgContext context, String methodName, String requestName) {
log.debug("=== {}::{} ==={}\n", methodName, requestName, context.log());
return RestAssuredExecutor.apply(context.request());
}For @JPostmanResponse, requestName is the value from:
@JPostmanResponse(request = "Get all products")For @JPostmanRunner, requestName is the current request being executed from the folder or root.
Executors can run dependencies before they execute.
@JPostmanExecutor(name = "auth", dependsOn = "getToken")
public ApiExecutor authExecutor(TestNgContext context) {
return RestAssuredExecutor.apply(context.request())
.auth()
.oauth2(context.cache("token"));
}Dependency method:
@JPostmanRequest(
request = "Login user and get tokens",
cache = "token"
)
public String getToken() {
return api.response(c -> RestAssuredExecutor.execute(c.request()))
.verify()
.path("accessToken");
}When no executor name is specified, JPostman looks for a default executor.
Good default executor:
@JPostmanExecutor
public ApiExecutor defaultExecutor(TestNgContext context) {
return RestAssuredExecutor.apply(context.request());
}If multiple executors exist, use a named executor in the response or runner:
@JPostmanResponse(
request = "Get all products",
executor = "rest"
)
@Test
public void getAllProducts() {
}@JPostmanExecutor(name = "rest")
public ApiExecutor restExecutor(TestNgContext context) {
return RestAssuredExecutor.apply(context.request());
}
@JPostmanExecutor(name = "auth", dependsOn = "getToken")
public ApiExecutor authExecutor(TestNgContext context) {
return RestAssuredExecutor.apply(context.request())
.auth()
.oauth2(context.cache("token"));
}@JPostmanExecutor controls how JPostman sends the prepared request. It supports named executors, dependencies, method-name access, request-name access, and multiple execution engines.