Skip to content

@JPostmanContext

David Gofman edited this page Jun 22, 2026 · 3 revisions

@JPostmanContext

Overview

@JPostmanContext injects the loaded core JPostman.Context into an annotation-based test class.

Use this annotation when you need direct access to the loaded Postman collection or environment, for example to inspect folders, print collection details, or read environment values before a test runs.

When to Use

Use @JPostmanContext when you want access to the raw loaded JPostman context:

  • ctx.getCollection()
  • ctx.getEnvironment()
  • collection folders and requests
  • environment values

Use @JPostmanTestContext when you want the framework test context such as JUnitContext or TestNgContext.

Basic Example

@JPostmanContext(namespace = "product")
private JPostman.Context ctx;

Full TestNG Example

@JPostmanTestNG
public class DemoTest {

    @JPostmanContext(namespace = "product")
    private JPostman.Context ctx;

    @JPostmanTestContext(namespace = "product")
    private TestNgContext product;

    @BeforeClass
    public void beforeClass() {
        ctx.getCollection().print();
        ctx.getCollection().getFolder("Product").print();
        ctx.getEnvironment().print();
    }
}

Full JUnit Example

@JPostmanJUnit(printFailures = true)
public class DemoJUnitTest {

    @JPostmanContext(namespace = "product")
    private JPostman.Context ctx;

    @JPostmanTestContext(namespace = "product")
    private JUnitContext product;

    @BeforeAll
    public void beforeAll() {
        ctx.getCollection().print();
        ctx.getCollection().getFolder("Product").print();
        ctx.getEnvironment().print();
    }
}

Namespace

The namespace connects this loaded context to the same namespace used by @JPostmanTestContext, @JPostmanRequest, @JPostmanResponse, and @JPostmanRunner.

@JPostmanContext(namespace = "product")
private JPostman.Context ctx;

If namespace is empty, the default context is used:

@JPostmanContext
private JPostman.Context ctx;

Configuration

@JPostmanContext can read configuration from jpostman.properties.

Example:

collection.product=classpath:DummyJSON.postman_collection.json
environment.product=classpath:DummyJSON.postman_environment.json

Then the test can use:

@JPostmanContext(namespace = "product")
private JPostman.Context ctx;

Direct Configuration

You can also define the collection and environment directly on the annotation:

@JPostmanContext(
    namespace = "product",
    collection = "classpath:DummyJSON.postman_collection.json",
    environment = "classpath:DummyJSON.postman_environment.json"
)
private JPostman.Context ctx;

Common Use Case

Use this annotation when you want to verify which requests are loaded:

@BeforeClass
public void beforeClass() {
    ctx.getCollection().print();
    ctx.getCollection().getFolder("Product").print();
}

Example output:

=== Collection: DummyJSON (0 requests) ===
  (1 folder)
  Product

=== Folder: Product (11 requests) ===
    [GET   ] Get all products
    [POST  ] Add a new product
    [PUT   ] Update a product
    [DELETE] Delete a product

Summary

@JPostmanContext gives direct access to the loaded Postman collection and environment. It is useful for setup, debugging, printing collection details, and working with raw JPostman context data.

Clone this wiki locally