-
Notifications
You must be signed in to change notification settings - Fork 0
@JPostmanContext
@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.
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.
@JPostmanContext(namespace = "product")
private JPostman.Context ctx;@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();
}
}@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();
}
}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;@JPostmanContext can read configuration from jpostman.properties.
Example:
collection=classpath:DummyJSON.postman_collection.json
environment=classpath:DummyJSON.postman_environment.json
collection.product=classpath:DummyJSON.product_collection.json
environment.product=classpath:DummyJSON.product_environment.jsonThen the test can use:
@JPostmanContext(namespace = "product")
private JPostman.Context ctx;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;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
@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.