Skip to content

@JPostmanResponse

David Gofman edited this page Jun 22, 2026 · 1 revision

Overview

@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.

Basic Example

@JPostmanResponse(
    folder = "Product",
    request = "Get all products"
)
@Test
public void getAllProducts() {
}

Namespace and Folder Example

@JPostmanResponse(
    namespace = "product",
    folder = "Product",
    request = "Add a new product",
    verify = 201,
    log = true
)
@Test
public void addNewProduct() {
}

Main Attributes

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.

Custom Executor

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

Depends On

dependsOn runs dependency methods before the response is executed.

@JPostmanResponse(
    request = "Get current auth user",
    executor = "auth",
    dependsOn = "getToken"
)
@Test
public void getCurrentAuthUser() {
}

Secure Rule Section

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() {
}

Filter

Use filter to reduce response output.

@JPostmanResponse(
    folder = "Product",
    request = "Get all products",
    filter = { "id", "title", "price" }
)
@Test
public void getFilteredProducts() {
}

Soft Assertions

Use soft = true to collect multiple assertion failures.

@JPostmanResponse(
    request = "Get all products",
    verify = 200,
    soft = true,
    log = true
)
@Test
public void getAllProducts() {
}

With @JPostmanAssert

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

Full Example

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

Summary

@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.

Clone this wiki locally