ReportPortal js client
This Client is to communicate with the ReportPortal on Node.js.
Library is used only for implementors of custom listeners for ReportPortal.
Already implemented listeners:
Examples for test framework integrations from the list above described in examples repository.
Installation
The latest version is available on npm:
npm install @reportportal/client-javascript
Usage example
const RPClient = require('@reportportal/client-javascript');
const rpClient = new RPClient({
apiKey: 'reportportalApiKey',
endpoint: 'http://your-instance.com:8080/api/v1',
launch: 'LAUNCH_NAME',
project: 'PROJECT_NAME'
});
rpClient.checkConnect().then(() => {
console.log('You have successfully connected to the server.');
}, (error) => {
console.log('Error connection to server');
console.dir(error);
});
TypeScript
Starting from version 5.6.0, the client has been migrated to TypeScript and ships with bundled type definitions. It works with both CommonJS and ES module projects:
import RPClient from '@reportportal/client-javascript';
const rpClient = new RPClient({
apiKey: 'reportportalApiKey',
endpoint: 'https://your-instance.com:8080/api/v1',
launch: 'LAUNCH_NAME',
project: 'PROJECT_NAME',
});
Constants, models and helpers are available via subpath imports:
import { RP_STATUSES } from '@reportportal/client-javascript/constants';
import PublicReportingAPI from '@reportportal/client-javascript/publicReportingAPI';
Configuration
When creating a client instance, you need to specify the following options.
Authentication options
The client supports two authentication methods:
- API Key Authentication (default)
- OAuth 2.0 Password Grant (recommended for enhanced security)
Note:
If both authentication methods are provided, OAuth 2.0 will be used.
Either API key or complete OAuth 2.0 configuration is required to connect to ReportPortal.
| Option |
Necessity |
Default |
Description |
| apiKey |
Conditional |
|
User's ReportPortal API key from which you want to send requests. It can be found on the profile page of this user. *Required only if OAuth is not configured. |
| oauth |
Conditional |
|
OAuth 2.0 configuration object. When provided, OAuth authentication will be used instead of API key. See OAuth Configuration below. |
OAuth configuration
The oauth object supports the following properties:
| Property |
Necessity |
Default |
Description |
| tokenEndpoint |
Required |
|
OAuth 2.0 token endpoint URL for password grant flow. |
| username |
Required |
|
Username for OAuth 2.0 password grant. |
| password |
Required |
|
Password for OAuth 2.0 password grant. |
| clientId |
Required |
|
OAuth 2.0 client ID. |
| clientSecret |
Optional |
|
OAuth 2.0 client secret (optional, depending on your OAuth server configuration). |
| scope |
Optional |
|
OAuth 2.0 scope (optional, space-separated list of scopes). |
Note: The OAuth interceptor automatically handles token refresh when the token is about to expire (1 minute before expiration).
OAuth 2.0 configuration example
const RPClient = require('@reportportal/client-javascript');
const rpClient = new RPClient({
endpoint: 'http://your-instance.com:8080/api/v1',
launch: 'LAUNCH_NAME',
project: 'PROJECT_NAME',
oauth: {
tokenEndpoint: 'https://your-oauth-server.com/oauth/token',
username: 'your-username',
password: 'your-password',
clientId: 'your-client-id',
clientSecret: 'your-client-secret', // optional
scope: 'reportportal', // optional
}
});
rpClient.checkConnect().then(() => {
console.log('You have successfully connected to the server.');
}, (error) => {
console.log('Error connection to server');
console.dir(error);
});
General options
| Option |
Necessity |
Default |
Description |
| endpoint |
Required |
|
URL of your server. For example, if you visit the page at 'https://server:8080/ui', then endpoint will be equal to 'https://server:8080/api/v1'. |
| launch |
Required |
|
Name of the launch at creation. |
| project |
Required |
|
The name of the project in which the launches will be created. |
| headers |
Optional |
{} |
The object with custom headers for internal http client. |
| debug |
Optional |
false |
This flag allows seeing the logs of the client. Useful for debugging. |
| isLaunchMergeRequired |
Optional |
false |
Allows client to merge launches into one at the end of the run via saving their UUIDs to the temp files at filesystem. At the end of the run launches can be merged using mergeLaunches method. Temp file format: rplaunch-${launch_uuid}.tmp. |
| restClientConfig |
Optional |
Not set |
Check the details in the HTTP client config. |
| launchUuidPrint |
Optional |
false |
Whether to print the current launch UUID. |
| launchUuidPrintOutput |
Optional |
'STDOUT' |
Launch UUID printing output. Possible values: 'STDOUT', 'STDERR', 'FILE', 'ENVIRONMENT'. Works only if launchUuidPrint set to true. File format: rp-launch-uuid-${launch_uuid}.tmp. Env variable: RP_LAUNCH_UUID. |
| skippedIsNotIssue |
Optional |
False |
ReportPortal provides feature to mark skipped tests as not 'To Investigate'. Option could be equal boolean values: true - skipped tests will not be marked as 'To Investigate' on application. false - skipped tests considered as issues and will be marked as 'To Investigate' on application. |
HTTP client options
axios like http client config.
Timeout (30000ms) on axios requests
There is a timeout on axios requests. If for instance the server your making a request to is taking too long to load, then axios timeout will work and you will see the error 'Error: timeout of 30000ms exceeded'.
You can simply change this timeout by adding a timeout property to restClientConfig with your desired numeric value (in ms) or 0 to disable it.
Debug
Use debug: true for debugging.
Agent
Use agent property to provide http(s) agent options.
Use this property in case the direct httpAgent/httpsAgent instance property cannot be used due to config serializations.
Retry configuration
The client retries failed HTTP calls up to 6 times with an exponential backoff (starting at 200 ms and capping at 5 s) and resets the axios timeout before each retry. Provide a retry option in restClientConfig to change that behaviour. The value can be either a number (overriding just the retry count) or a full axios-retry configuration object:
const axiosRetry = require('axios-retry').default;
const client = new RPClient({
// ... other options
restClientConfig: {
retry: {
retries: 5,
retryDelay: axiosRetry.exponentialDelay,
},
},
});
Setting retry: 0 disables automatic retries.
Proxy configuration
The client supports comprehensive proxy configuration for both HTTP and HTTPS requests, including ReportPortal API calls and OAuth token requests. Proxy settings can be configured via restClientConfig or environment variables.
Basic proxy configuration
Via configuration object
const RPClient = require('@reportportal/client-javascript');
const rpClient = new RPClient({
apiKey: 'your_api_key',
endpoint: 'http://your-instance.com:8080/api/v1',
launch: 'LAUNCH_NAME',
project: 'PROJECT_NAME',
restClientConfig: {
proxy: {
protocol: 'https', // 'http' or 'https'
host: '127.0.0.1',
port: 8080,
// Optional authentication
auth: {
username: 'proxy-user',
password: 'proxy-password'
}
}
}
});
Via proxy URL string