Agent to integrate Mocha with ReportPortal.
It was designed to work with mocha programmatically, in order to be able to parametrize each test run.
npm install --save-dev @reportportal/agent-js-mocha
Fill in the reporterOptions
in Mocha configuration.
const Mocha = require("mocha");
const mochaMain = new Mocha({
reporter: '@reportportal/agent-js-mocha',
reporterOptions: {
"apiKey": "reportportalApiKey",
"endpoint": "https://your.reportportal.server/api/v1",
"project": "YourReportPortalProjectName",
"launch": "YourLauncherName",
"attributes": [
{
"key": "YourKey",
"value": "YourValue"
},
{
"value": "YourValue"
},
]
}
});
Using .mocharc.js
:
module.exports = {
'extension': ['js', 'cjs', 'mjs'],
'package': './package.json',
reporter: '@reportportal/agent-js-mocha',
'reporter-option':[
'endpoint=https://your.reportportal.server/api/v1',
'apiKey=reportportalApiKey',
'launch=YourLauncherName',
'project=YourReportPortalProjectName',
'attributes=YourKey:YourValue;YourValue',
],
'file': [
'spec/someTest.spec.js',
]
}
The full list of available options presented below.
Option | Necessity | Default | Description |
---|---|---|---|
apiKey | Required | User's reportportal token from which you want to send requests. It can be found on the profile page of this user. | |
endpoint | Required | URL of your server. For example 'https://server:8080/api/v1'. | |
launch | Required | Name of launch at creation. | |
project | Required | The name of the project in which the launches will be created. | |
attributes | Optional | [] | Launch attributes. |
description | Optional | '' | Launch description. |
rerun | Optional | false | Enable rerun |
rerunOf | Optional | Not set | UUID of launch you want to rerun. If not specified, reportportal will update the latest launch with the same name |
mode | Optional | 'DEFAULT' | Results will be submitted to Launches page 'DEBUG' - Results will be submitted to Debug page (values must be upper case). |
debug | Optional | false | This flag allows seeing the logs of the client-javascript. Useful for debugging. |
restClientConfig | Optional | Not set | axios like http client config. May contain agent property for configure http(s) client, and other client options e.g. proxy , timeout . For debugging and displaying logs the debug: true option can be used. Visit client-javascript for more details. |
headers | Optional | {} | The object with custom headers for internal http client. |
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 , note that the env variable is only available in the reporter process (it cannot be obtained from tests). |
skippedIssue | Optional | true | reportportal provides feature to mark skipped tests as not 'To Investigate'. Option could be equal boolean values: true - skipped tests considered as issues and will be marked as 'To Investigate' on reportportal. false - skipped tests will not be marked as 'To Investigate' on application. |
reportHooks | Optional | false | Determines report before and after hooks or not. |
token | Deprecated | Not set | Use apiKey instead. |
The agent-js-mocha
usage example can be found here.
This reporter provides Reporting API to use it directly in tests to send some additional data to the report.
Import the PublicReportingAPI
as shown below to use additional reporting features.
const PublicReportingAPI = require('@reportportal/agent-js-mocha/lib/publicReportingAPI');
PublicReportingAPI
provides the following methods for reporting logs into the current test/step.
{
name: "filename",
type: "image/png", // media type
content: data, // file content represented as 64base string
}
PublicReportingAPI provides the corresponding methods for reporting logs into the launch.
Example:
const PublicReportingAPI = require('@reportportal/agent-js-mocha/lib/publicReportingAPI');
...
describe('suite',()=>{
it('test', () => {
const attachment = {
name: 'attachment.png',
type: 'image/png',
content: data.toString('base64'),
}
PublicReportingAPI.log('INFO', 'Info log message for test "test" with attachment', attachment);
PublicReportingAPI.launchLog('ERROR', 'Error log message for current launch with attachment', attachment);
PublicReportingAPI.trace('Trace log message for test "test"', attachment);
PublicReportingAPI.debug('Debug log message for test "test"');
PublicReportingAPI.info('Info log message for test "test" with attachment');
PublicReportingAPI.warn('Warning for test "test"');
PublicReportingAPI.error('Error log message for test "test"');
PublicReportingAPI.fatal('Fatal log message for test "test"');
});
});
addAttributes (attributes). Add attributes(tags) to the current test/suite. Should be called inside of corresponding test or suite. attributes is array of pairs of key and value:
[{
key: "attributeKey1",
value: "attributeValue2",
}]
Key is optional field.
Mocha doesn't allow functional calls directly into describe section. You can call addAttributes inside of before/after hooks to add attributes to the corresponding suite.
Example:
const PublicReportingAPI = require('@reportportal/agent-js-mocha/lib/publicReportingAPI');
...
describe('suite',()=>{
before(function (){
PublicReportingAPI.addAttributes([{ key: 'suiteAttr1Key', value: 'suiteAttr1Value' }, { value: 'suiteAttr2' }]);
});
it('test', () => {
PublicReportingAPI.addAttributes([{ key: 'testAttr1Key', value: 'testAttr1Value' }]);
PublicReportingAPI.addAttributes([{ value: 'testAttr2' }]);
});
});
To integrate with Sauce Labs just add attributes:
[{
"key": "SLID",
"value": "# of the job in Sauce Labs"
}, {
"key": "SLDC",
"value": "EU (EU or US)"
}]
setDescription (description). Set text description to the current test/suite. Should be called inside of corresponding test or suite.
Mocha doesn't allow functional calls directly into describe section. You can call setDescription inside of before/after hooks to set description to the corresponding suite.
Example:
const PublicReportingAPI = require('@reportportal/agent-js-mocha/lib/publicReportingAPI');
...
describe('suite',()=>{
before(function (){
PublicReportingAPI.setDescription('suite description');
});
it('test', () => {
PublicReportingAPI.setDescription('test description');
});
});
setTestCaseId (testCaseId). Set test case id to the current test/suite. Should be called inside of corresponding test or suite.
Mocha doesn't allow functional calls directly into describe section. You can call setTestCaseId inside of before/after hooks to set test case id to the corresponding suite.
Example:
const PublicReportingAPI = require('@reportportal/agent-js-mocha/lib/publicReportingAPI');
...
describe('suite',()=>{
before(function (){
PublicReportingAPI.setTestCaseId('TestCaseIdForTheSuite');
});
it('test', () => {
PublicReportingAPI.setTestCaseId('TestCaseIdForTheTest');
});
});
PublicReportingAPI provides the following methods for setting status to the current suite/spec.
You can use the shorthand forms of the setStatus method:
There are also the corresponding methods for setting status into the launch:
Example:
const PublicReportingAPI = require('@reportportal/agent-js-mocha/lib/publicReportingAPI');
...
describe('suite',()=>{
it('test info', function() {
PublicReportingAPI.setStatusFailed();
expect(true).to.be.equal(true);
});
});
Licensed under the Apache License v2.0