
Research
/Security News
Popular Tinycolor npm Package Compromised in Supply Chain Attack Affecting 40+ Packages
Malicious update to @ctrl/tinycolor on npm is part of a supply-chain attack hitting 40+ packages across maintainers
@reportportal/agent-js-jasmine
Advanced tools
Agent to integrate Jasmine with ReportPortal.
Install the agent in your project:
npm install --save-dev @reportportal/agent-js-jasmine
1. Create the reportportalConf.js
file with ReportPortal configuration:
module.exports = {
apiKey: "<API_KEY>",
endpoint: "http://your.reportportal.server/api/v1",
project: 'Your reportportal project name',
launch: 'Your launch name',
attributes: [
{
"key": "YourKey",
"value": "YourValue"
},
{
"value": "YourValue"
},
],
description: 'Your launch description',
};
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. |
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. |
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). |
attachPicturesToLogs | Optional | false | If set to 'true' then attempts will be made to attach screenshots to the logs. |
reportHooks | Optional | false | Determines report before and after hooks or not. |
token | Deprecated | Not set | Use apiKey instead. |
2. Create the agent and add the reporter it to the Jasmine:
const ReportportalAgent = require('@reportportal/agent-js-jasmine');
const reportportalConfig = require('./reportportalConf');
const agent = new ReportportalAgent(reportportalConfig);
jasmine.addReporter(agent.getJasmineReporter());
3. After the Jasmine completes its work, wait for the agent to finish:
agent.getExitPromise().then(() => {
console.log('finish work');
})
The agent provides an API to extend the functionality of Jasmine.
Add PublicReportingAPI
into your test file to use additional reporting features.
const PublicReportingAPI = require('@reportportal/agent-js-jasmine/lib/publicReportingAPI');
Inside your suite or spec call PublicReportingAPI.setDescription()
, PublicReportingAPI.addAttributes()
setDescription method inside your suite
Parameter | Required | Description | Examples |
---|---|---|---|
description | true | "string" - text description for your suite | "Your description" |
suite | true | "string" - description of your suite (all suite descriptions must be unique) | "Suite" |
addAttributes method inside your suite
Parameter | Required | Description | Examples |
---|---|---|---|
attributes | true | attributes, pairs of key and value | [{ "key": "YourKey", "value": "YourValue" }] |
suite | true | "string" - description of your suite (all suite descriptions must be unique) | "Suite" |
setDescription method inside your spec
Parameter | Required | Description | Examples |
---|---|---|---|
description | true | "string" - text description for your suite | "Your description" |
addAttributes method inside your spec
Parameter | Required | Description | Examples |
---|---|---|---|
attributes | true | attributes, pairs of key and value | [{ "key": "YourKey", "value": "YourValue" }] |
To integrate report with Sauce Labs just add attributes:
[{
"key": "SLID",
"value": "# of the job in Sauce Labs"
}, {
"key": "SLDC",
"value": "EU (EU or US)"
}]
PublicReportingAPI
provides the following methods for reporting logs into the current suite/spec.
level should be equal to one of the following values: TRACE, DEBUG, INFO, WARN, ERROR, FATAL.
suite it's description of your suite (all suite descriptions must be unique) REQUIRED INSIDE OF YOUR SUITE, OPTIONAL FOR SPEC
file should be an object (REQUIRED INSIDE YOUR SUITE, if there is no file object, set NULL) :
{
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.
PublicReportingAPI
provides the following methods for setting status into the current suite/spec.
status should be equal to one of the following values: passed, failed, stopped, skipped, interrupted, cancelled, info, warn.
suite it's description of your suite (all suite descriptions must be unique) REQUIRED INSIDE OF YOUR SUITE, OPTIONAL FOR SPEC
PublicReportingAPI
provides the corresponding methods for setting status into the launch.
setLaunchStatus(status). Assign status to the launch.
status should be equal to one of the following values: passed, failed, stopped, skipped, interrupted, cancelled, info, warn.
setLaunchStatusPassed(). Assign passed status to the launch.
setLaunchStatusFailed(). Assign failed status to the launch.
setLaunchStatusSkipped(). Assign skipped status to the launch.
setLaunchStatusStopped(). Assign stopped status to the launch.
setLaunchStatusInterrupted(). Assign interrupted status to the launch.
setLaunchStatusCancelled(). Assign cancelled status to the launch.
setLaunchStatusInfo(). Assign info status to the launch.
setLaunchStatusWarn(). Assign warn status to the launch.
setTestCaseId(testCaseId, suite). Set test case id to the current suite/spec. Should be called inside of corresponding suite or spec.
suite it's description of your suite (all suite descriptions must be unique) REQUIRED INSIDE OF YOUR SUITE, OPTIONAL FOR SPEC
Example:
const PublicReportingAPI = require('@reportportal/agent-js-jasmine/lib/publicReportingAPI');
describe('A suite', function() {
const suiteAttachment = {
name: 'attachment.png',
type: 'image/png',
content: data.toString('base64'),
}
PublicReportingAPI.addAttributes([{
key: 'suiteKey',
value: 'suiteValue',
}], 'A suite');
PublicReportingAPI.setDescription('Suite description', 'A suite');
PublicReportingAPI.debug('Debug log message for suite "suite"', null, 'A suite');
PublicReportingAPI.info('Info log message for suite "suite"', suiteAttachment, 'A suite');
PublicReportingAPI.warn('Warning for suite "suite"', null, 'A suite');
PublicReportingAPI.error('Error log message for suite "suite"', null, 'A suite');
PublicReportingAPI.fatal('Fatal log message for suite "suite"', suiteAttachment, 'A suite');
PublicReportingAPI.setLaunchStatusPassed();
PublicReportingAPI.setStatusPassed('A suite');
PublicReportingAPI.setTestCaseId('TestCaseIdForSuite', 'A suite');
it('spec', function() {
const specAttachment = {
name: 'attachment.png',
type: 'image/png',
content: data.toString('base64'),
}
PublicReportingAPI.addAttributes([{
key: 'specKey',
value: 'specValue'
}]);
PublicReportingAPI.setDescription('Spec description');
PublicReportingAPI.log('INFO', 'Info log message for spec "spec" with attachment', specAttachment);
PublicReportingAPI.launchLog('ERROR', 'Error log message for current launch with attachment', specAttachment);
PublicReportingAPI.trace('Trace log message for spec "spec"', specAttachment);
PublicReportingAPI.debug('Debug log message for spec "spec"');
PublicReportingAPI.info('Info log message for spec "spec" with attachment');
PublicReportingAPI.warn('Warning for spec "spec"');
PublicReportingAPI.error('Error log message for spec "spec"');
PublicReportingAPI.fatal('Fatal log message for spec "spec"');
PublicReportingAPI.setStatusPassed();
PublicReportingAPI.setTestCaseId('TestCaseIdForSpec');
expect(true).toBe(true);
});
});
If you launch protractor in single tread mode, just add agent initialization to the onPrepare
function.
Add agent.getJasmineReporter
to the jasmine.getEnv().addReporter()
as an argument. You can see this in the example bellow.
Update your configuration file as follows:
const ReportportalAgent = require('@reportportal/agent-js-jasmine');
...
const agent = new ReportportalAgent({
token: "00000000-0000-0000-0000-000000000000",
endpoint: "http://your.reportportal.server/api/v1",
launch: "LAUNCH_NAME",
project: "PROJECT_NAME",
attachPicturesToLogs: false,
attributes: [
{
"key": "YourKey",
"value": "YourValue"
},
{
"value": "YourValue"
},
]
});
exports.config = {
...
onPrepare: ()=> {
...
jasmine.getEnv().addReporter(agent.getJasmineReporter());
},
afterLaunch:() => {
return agent.getExitPromise();
}
};
For launching agents in multi thread mode firstly parent launch must be created and it ID must be sent to the child launches , so they would send data to the right place, and wouldn't create new launch instances at the Report Portal.
The main problem is that node.js is a single threaded platform. And for providing multi treading launch with browsers protractor generate new processes of node, which can't interact with each other, so Singelton objects or functions can't be created for synchronizing it work. Only primitive types could be sent as args to the new processes before launch. The way of resolving this problem is to create launch file that would generate a Parent Launch and send launch's ID to protractor as argument. Then protractor would launch jasmine-agents with parent ID. Look through example of the Launch File with protractor-flake module at the 'Settings fot the multi threaded launch' section or at the examples folder. Any node runner could be used!
npm install protractor-flake --save-dev
reportportalConf.js
module.exports = {
token: "00000000-0000-0000-0000-000000000000",
endpoint: "http://your.reportportal.server/api/v1",
launch: "LAUNCH_NAME",
project: "PROJECT_NAME",
attachPicturesToLogs: false,
attributes: [
{
"key": "YourKey",
"value": "YourValue"
},
{
"value": "YourValue"
},
]
}
protractorLaunchFile.js
const protractorFlake = require('protractor-flake');
const AgentJasmine = require('@reportportal/agent-js-jasmine');
const reportportalConfig = require('./reportportalConf');
const agent = new AgentJasmine(reportportalConfig);
agent.getLaunchStartPromise().then((launchData) =>{
protractorFlake({
maxAttempts: 1,
protractorArgs: [
'./multiThreadConf.js',
'--params.id',
launchData.id
]
}, (status) => {
agent.getExitPromise().then(() =>{
process.exit(status);
});
});
});
multiThreadConf.js
file
const ReportportalAgent = require('@reportportal/agent-js-jasmine');
const reportportalConfig = require('./reportportalConf');
exports.config = {
multiCapabilities: [
{
name: 'normal',
browserName: 'chrome',
maxInstances: 2,
shardTestFiles: true,
chromeOptions: {
args: ['--window-size=1024,768', '--disable-infobars']
}
}
],
specs: ['testAngularPage.spec.js', 'testGithubPage.spec.js'],
onPrepare() {
const config = Object.assign({
id: browser.params.id
}, reportportalConfig);
const agent = new ReportportalAgent(config);
/*Its a hack. There is an issue since 2015. That Jasmine doesn't wait for report's async functions.
links to the issues https://github.com/jasmine/jasmine/issues/842
https://github.com/angular/protractor/issues/1938
So it needed to wait until requests would be sent to the Report Portal.
*/
afterAll((done) => agent.getPromiseFinishAllItems(agent.tempLaunchId).then(()=> done()));
jasmine.getEnv().addReporter(agent.getJasmineReporter());
}
};
package.json
:"scripts": {
"protractor-multi": "node protractorLaunchFile.js"
}
npm run protractor-multi
See the detailed example with tests in examples.
Link to the jasmine issue, that it doesn't work well with async functions jasmine issue, protractor's community
Licensed under the Apache 2.0 license (see the LICENSE.txt file).
[5.2.0] - 2024-10-03
@reportportal/client-javascript
bumped to version 5.3.0
.FAQs
Agent for integration Jasmine with ReportPortal.
We found that @reportportal/agent-js-jasmine demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Malicious update to @ctrl/tinycolor on npm is part of a supply-chain attack hitting 40+ packages across maintainers
Security News
pnpm's new minimumReleaseAge setting delays package updates to prevent supply chain attacks, with other tools like Taze and NCU following suit.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.