-
Notifications
You must be signed in to change notification settings - Fork 0
@JPostmanResponse
@JPostmanResponse prepares a Postman request, executes it through a JPostman executor, and verifies the response.
Use it for single-request tests where one test method represents one Postman request.
@JPostmanResponse(
folder = "Product",
request = "Get all products"
)
@Test
public void getAllProducts() {
}@JPostmanResponse(
namespace = "product",
folder = "Product",
request = "Add a new product",
verify = 201,
log = true
)
@Test
public void addNewProduct() {
}| Attribute | Meaning |
|---|---|
namespace |
Selects the configured JPostman context. Empty means default context. |
folder |
Optional Postman folder name. Empty means search by request name only. |
request |
Postman request name to execute. |
rule |
Optional secure rule section for masking/filtering. |
filter |
Optional response fields to keep before printing or verifying. |
dependsOn |
Dependency method names to run first. |
cache |
Optional cache key for storing dependency result. |
verify |
Expected HTTP status code. Default is 200. |
executor |
Named executor method. Empty means default executor. |
log |
Attach secure log details to assertion failures. |
soft |
Use soft assertion verification. |
Use executor to select a named executor method.
@JPostmanResponse(
request = "Get current auth user",
executor = "auth"
)
@Test
public void getCurrentAuthUser() {
}Executor:
@JPostmanExecutor(name = "auth", dependsOn = "getToken")
public ApiExecutor authExecutor(TestNgContext context) {
return RestAssuredExecutor.apply(context.request())
.auth()
.oauth2(context.cache("token"));
}dependsOn runs dependency methods before the response is executed.
@JPostmanResponse(
request = "Get current auth user",
executor = "auth",
dependsOn = "getToken"
)
@Test
public void getCurrentAuthUser() {
}Use rule to apply secure masking and filtering rules.
@JPostmanResponse(
namespace = "product",
folder = "Product",
request = "Get all products",
rule = "product",
log = true
)
@Test
public void getAllProducts() {
}Use filter to reduce response output.
@JPostmanResponse(
folder = "Product",
request = "Get all products",
filter = { "id", "title", "price" }
)
@Test
public void getFilteredProducts() {
}Use soft = true to collect multiple assertion failures.
@JPostmanResponse(
request = "Get all products",
verify = 200,
soft = true,
log = true
)
@Test
public void getAllProducts() {
}When @JPostmanAssert is present, JPostman skips the normal verify() value from @JPostmanResponse and uses assertion rules from the assertion file.
@JPostmanResponse(
namespace = "product",
folder = "Product",
request = "Add a new product",
log = true
)
@JPostmanAssert(sections = { "product" })
@Test
public void addNewProduct() {
}The status code can be defined in the assertion file:
[Add a new product]
extends=product
statusCode=201
pathNotNull=id@JPostmanTestNG
public class DemoTest {
@JPostmanTestContext(namespace = "product")
private TestNgContext product;
@JPostmanResponse(
namespace = "product",
folder = "Product",
request = "Get all products",
rule = "product",
log = true
)
@Test
public void getAllProducts() {
product.ctx().verify().print();
}
}@JPostmanResponse is the main annotation for running one Postman request as one test. It supports namespaces, folders, secure rules, filters, dependencies, custom executors, logging, soft assertions, and assertion-rule integration.