Skip to content

Commit 9b9ef98

Browse files
improve examples and notes in README
1 parent 862c114 commit 9b9ef98

1 file changed

Lines changed: 50 additions & 11 deletions

File tree

README.md

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,43 @@ Add the following dependency to your Maven project:
5050
</dependencies>
5151
```
5252

53-
When coverage agents are running in multi-user mode or tests execute in parallel, browser requests must include the current test's `Baggage` header so that coverage can be correctly associated with the executing test.
53+
When coverage agents are running in multi-user mode or tests execute in parallel, browser requests must include an additional HTTP `Baggage` header so that coverage can be correctly associated with the executing test. See [Browser Integrations](#browser-integrations) for more detail.
5454

55-
The following example retrieves the current `Baggage` header, creates a proxy that injects the header into browser requests, and configures the Chrome driver to use that proxy.
55+
The following example retrieves the current `Baggage` header and creates a proxy that injects the header into HTTP requests.
5656

5757
```java
5858
String baggageHeader = CoverageIntegration.getBaggageHeader();
5959
if (baggageHeader == null || baggageHeader.isBlank()) {
6060
return;
6161
}
6262

63-
ChromeOptions options = new ChromeOptions();
64-
ParasoftHeaderInjectingProxy coverageProxy =
65-
new ParasoftHeaderInjectingProxy(PROXY_BIND_HOST, 0, baggageHeader);
66-
SeleniumCoverageIntegration.configureChromeOptions(options, coverageProxy);
63+
try (ParasoftHeaderInjectingProxy coverageProxy =
64+
new ParasoftHeaderInjectingProxy(PROXY_BIND_HOST, 0, baggageHeader)) {
65+
String proxyHost = coverageProxy.getHost();
66+
int proxyPort = coverageProxy.getPort();
67+
// run test HTTP traffic through the coverage proxy
68+
} // implicitly close the proxy at the end of the try-with-resources block
6769
```
6870

6971
For rare standalone use cases, such as tests launched from a `main` method, use `CoverageApiClient` from the API module to start and stop sessions and tests directly.
7072

73+
```java
74+
CoverageApiClient client = CoverageApiClient.createFromSettings();
75+
String sessionId = client.startSession();
76+
CoverageTestContext context = client.startTest("ExampleTest", "runsFromMain");
77+
78+
try {
79+
// Execute the code under test here. Send context.getCurrentTestOperatorIdHeader()
80+
// as HTTP headers when calling an application under test.
81+
client.stopTest("ExampleTest", "runsFromMain", context, CoverageTestResult.PASS, null);
82+
} catch (RuntimeException e) {
83+
client.stopTest("ExampleTest", "runsFromMain", context, CoverageTestResult.FAIL, e.getMessage());
84+
throw e;
85+
} finally {
86+
client.stopSession();
87+
}
88+
```
89+
7190
## Coverage Configuration
7291

7392
Create a coverage-integration.properties file to configure communication with CTP during the testing workflow. This file also provides the information needed to publish test results and coverage after all tests have completed.
@@ -85,20 +104,22 @@ parasoft.coverage.integration.dtp.sessionTag=unit-testing-session
85104
# Authentication username for CTP
86105
parasoft.coverage.integration.ctp.auth.username=admin
87106

88-
# Password for CTP with support for variable resolution
89-
parasoft.coverage.integration.ctp.auth.password=${env_var:PASSWORD}
107+
# Password for CTP with support for variable resolution such as ${env_var:PASSWORD}
108+
# It is recommended that passwords be protected by a credentials manager.
109+
parasoft.coverage.integration.ctp.auth.password=password
90110

91111
# OAuth bearer token in the case where CTP is setup with OIDC authentication
92112
parasoft.coverage.integration.ctp.auth.token=<bearer token>
93113

94114
# Enables support for parallel test execution. When enabled, the
95115
# coverage-integration library isolates coverage data for each test.
116+
# Note: Requires Parasoft CTP version 2026.2 or later.
96117
parasoft.coverage.integration.parallel.test.enabled=true
97118

98119
# Identifies the user associated with the coverage session. When running
99-
# tests in parallel, this value is used to isolate coverage data between
100-
# concurrent test executions.
101-
parasoft.coverage.intergration.ctp.userId=tester
120+
# test sessions in parallel, this value is used to isolate coverage data between
121+
# concurrent test execution sessions.
122+
parasoft.coverage.integration.ctp.userId=tester
102123
```
103124
Place this file on your project's classpath, for example in src/test/resources.
104125

@@ -177,6 +198,13 @@ Enable JUnit extension auto-detection by setting the following system property w
177198

178199
-Djunit.jupiter.extensions.autodetection.enabled=true
179200

201+
Enable per-test coverage isolation for JUnit parallel test execution (-Djunit.jupiter.execution.parallel.enabled=true) by setting the following in the coverage-integration.properties file:
202+
203+
```properties
204+
# Note: Requires Parasoft CTP version 2026.2 or later.
205+
parasoft.coverage.integration.parallel.test.enabled=true
206+
```
207+
180208
### TestNG
181209

182210
Add the Maven dependency for the TestNG coverage integration:
@@ -220,6 +248,13 @@ Add both listeners to your `testng.xml` file as shown below:
220248
</suite>
221249
```
222250

251+
Enable per-test coverage isolation for TestNG parallel test execution (parallel="tests") by setting the following in the coverage-integration.properties file:
252+
253+
```properties
254+
# Note: Requires Parasoft CTP version 2026.2 or later.
255+
parasoft.coverage.integration.parallel.test.enabled=true
256+
```
257+
223258
### Cucumber
224259

225260
The `coverage-integration-cucumber` module automatically reports Cucumber 7.x scenario execution and coverage to CTP. It manages the coverage session for the duration of the Cucumber test run and reports each scenario as an individual test case.
@@ -404,6 +439,10 @@ To set explicit headers instead, use `configureCdpHeaders(driver, headers)`.
404439

405440
Call `configureCdpBaggageHeader` separately for each Chrome or Edge browser session used by parallel tests. The proxy-based approach works with all supported browsers. CDP is an alternative available only for Chrome and Edge.
406441

442+
> [!NOTE]
443+
> Cross-container Selenium Grid
444+
> Coverage isolation in multi-user or parallel testing with cross-container Selenium grid takes extra care to configure. The `SeleniumCoverageIntegration.configureCdpBaggageHeader(driver)` approach above is recommended for Google Chrome and Microsoft Edge. However, the Parasoft coverage proxy used with Firefox only binds to the loopback address `127.0.0.1` by default. Use the `ParasoftHeaderInjectingProxy` constructor from the API to bind the proxy to a different host.
445+
407446
## Logging
408447

409448
This project uses SLF4J and includes only the `slf4j-api` dependency. It does not provide or configure a logging backend, so debug logging is not shown by default. Applications that use this library control logging through their own SLF4J backend, such as Logback, Log4j 2, JUL, or `slf4j-simple`.

0 commit comments

Comments
 (0)