Gathering detailed insights and metrics for @reportportal/agent-js-webdriverio
Gathering detailed insights and metrics for @reportportal/agent-js-webdriverio
Gathering detailed insights and metrics for @reportportal/agent-js-webdriverio
Gathering detailed insights and metrics for @reportportal/agent-js-webdriverio
@reportportal/client-javascript
ReportPortal client for Node.js
@reportportal/agent-js-playwright
Agent to integrate Playwright with ReportPortal.
wdio-reportportal-service
A WebdriverIO v5 service for wdio-reportportal-reporter.
@reportportal/agent-js-cypress
This agent helps Cypress to communicate with ReportPortal
Agent to integrate Webdriver.io with ReportPortal.
npm install @reportportal/agent-js-webdriverio
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
8 Stars
144 Commits
2 Forks
7 Watching
3 Branches
18 Contributors
Updated on 10 Oct 2024
TypeScript (98.59%)
JavaScript (1.41%)
Cumulative downloads
Total Downloads
Last day
-10.8%
378
Compared to previous day
Last week
-5.9%
1,957
Compared to previous week
Last month
16.7%
8,462
Compared to previous month
Last year
46.2%
121,314
Compared to previous year
19
Agent to integrate Webdriver.io with ReportPortal.
Install the agent in your project:
1npm install --save-dev @reportportal/agent-js-webdriverio
Create wdio.conf.js
Testrunner Configuration file:
1const { Reporter } = require('@reportportal/agent-js-webdriverio'); 2const config = { 3 apiKey: '<API_KEY>', 4 endpoint: 'https://your.reportportal.server/api/v1', 5 project: 'Your reportportal project name', 6 launch: 'Your launch name', 7 description: 'Your launch description', 8 attributes: [ 9 { 10 key: 'key', 11 value: 'value', 12 }, 13 { 14 value: 'value', 15 }, 16 ], 17}; 18 19exports.config = { 20 // ... 21 reporters: [[Reporter, config]], 22 // ... 23};
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/v2'. | |
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. |
launchId | Optional | Not set | The ID of an already existing launch. The launch must be in 'IN_PROGRESS' status while the tests are running. Please note that if this ID is provided, the launch will not be finished at the end of the run and must be finished separately. If this option used, launch related options (eg. description, attributes, rerun, rerunOf, mode) will not take any effect as they are used within launch start. |
restClientConfig | Optional | Not set | axios like http client config. May contain agent property for configure http(s) client, and other client options eg. 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 . |
isLaunchMergeRequired | Optional | false | Allows to merge several run's into one launch at the end of the run. Needs additional setup. See Manual merge launches. |
attachPicturesToLogs | Optional | false | Automatically attach screenshots taken during test execution. See Screenshots for more details. |
cucumberNestedSteps | Optional | false | Report Cucumber steps as logs. |
reportSeleniumCommands | Optional | false | Add selenium logs to each test case. |
seleniumCommandsLogLevel | Optional | 'info' | If set reportSeleniumCommands to true , you need to provide log level witch can be one of: 'trace', 'debug', 'info', 'warn', 'error', 'fatal'. |
token | Deprecated | Not set | Use apiKey instead. |
The following options can be overridden using ENVIRONMENT variables:
Option | ENV variable |
---|---|
launchId | RP_LAUNCH_ID |
After completing the above configuration, you will be able to see a basic report of test results in ReportPortal. To make the report more informative and utilize all features of ReportPortal, the agent provides additional features described below.
You can also refer the example-webdriverio example to see how to use the agent with WebdriverIO in action.
By default, this agent reports the following structure:
You may change this behavior to report steps to the log level by enabling scenario-based reporting:
To report scenarios as test cases and steps as logs, you need to pass an additional parameter to the agent config: cucumberNestedSteps: true
.
To attach screenshots to the test, the option attachPicturesToLogs
need to be enabled in the agent config.
Then, in case the screenshot is taken within the test execution, it will be attached to the test result in ReportPortal automatically.
Examples:
1describe('suite name', () => { 2 it('Test should be FAILED', async () => { 3 await browser.url('https://webdriver.io'); 4 const title = await browser.getTitle(); 5 await browser.saveScreenshot('./screenshots/screenshot.png'); 6 7 expect(title).toBe('WebdriverIO'); 8 }); 9});
1Given('I do something awesome', async () => { 2 await browser.takeScreenshot(); 3 assert.strictEqual(this.value, expectedValue); 4});
It is also may be useful to take the screenshot on test failure in the afterStep
function for Cucumber in wdio.conf.js
file:
1afterStep: async function(step, scenario, { error, result, duration, passed }, context) { 2 if (!passed) { 3 await browser.takeScreenshot(); 4 } 5}
Another way to add any files to the test (not only screenshots) is to use the ReportingAPI.log() method.
This reporter provides Reporting API to use it directly in tests to send some additional data to the report.
To start using the ReportingApi
in tests, just import it from '@reportportal/agent-js-webdriverio'
:
1const { ReportingApi } = require('@reportportal/agent-js-webdriverio');
ReportingApi.addAttributes(attributes: Array<Attribute>, suite?: string);
required: attributes
1interface Attribute { 2 key?: string; 3 value: string; 4}
Examples:
1// Jasmine/Mocha 2describe('suite name', () => { 3 ReportingApi.addAttributes([ 4 { 5 key: 'suiteKey', 6 value: 'suiteValue', 7 }, 8 { 9 value: 'suiteValue_2', 10 }, 11 ], 'suite name'); // the second parameter must match the name of the suite 12 it('test with attributes', () => { 13 ReportingApi.addAttributes([ 14 { 15 key: 'testKey', 16 value: 'testValue', 17 }, 18 { 19 value: 'testValue_2', 20 }, 21 ]); 22 23 expect(true).eql(true); 24 }) 25});
Note: Pay attention if you want to provide attributes to the
suite
you should pass describe name as a second parameter.
1// Cucumber - adding attributes to the `suite` 2@testKey:testValue @testValueTwo 3Feature: Test WDIO with cucumber 4//...
1// Cucumber - adding attributes to the `step` 2Given('I do something awesome', () => { 3 ReportingApi.addAttributes([ 4 { 5 key: 'stepKey', 6 value: 'stepValue', 7 }, 8 { 9 value: 'stepValue_2', 10 }, 11 ]); 12 //... 13});
Note: The agent does not support adding attributes to the
scenario
.
ReportingApi.setDescription(description: string, suite?: string);
required: description
Examples:
1// Jasmine/Mocha 2describe('suite name', () => { 3 ReportingApi.setDescription('suite description', 'suite name'); // the second parameter must match the name of the suite 4 it('test with attributes', () => { 5 ReportingApi.setDescription('step description'); 6 expect(true).eql(true); 7 }) 8});
Note: Pay attention if you want to provide description to the
suite
you should pass describe name as a second parameter.
1// Cucumber 2Feature: Test WDIO with cucumber 3 This description will be added to the suite 4//...
1// Cucumber 2Given('I do something awesome', () => { 3 ReportingApi.setDescription('step description'); 4 //... 5});
Note: Agent is not supported adding description to the
scenario
.
ReportingApi.setTestCaseId(testCaseId: string, suite?: string);
required: testCaseId
Examples:
1// Jasmine/Mocha 2describe('suite name', () => { 3 ReportingApi.setTestCaseId('suiteTestCaseId', 'suite name'); // the second parameter must match the name of the suite 4 it('some test', () => { 5 ReportingApi.setTestCaseId('testCaseId'); 6 // ... 7 }) 8});
Note: Pay attention if you want to provide testCaseId to the
suite
you should pass describe name as a parameter.
1// Cucumber 2Given('I do something awesome', () => { 3 ReportingApi.setTestCaseId('testCaseId'); 4 //... 5});
Assign corresponding status to the current test item or suite.
ReportingApi.setStatus(status: string, suite?: string);
required: status
where status
must be one of the following: passed, failed, stopped, skipped, interrupted, cancelled, info, warn
Examples:
1// Jasmine/Mocha 2describe('should have status FAILED', () => { 3 ReportingApi.setStatus('failed', 'should have status FAILED'); // the second parameter must match the name of the suite 4 it('test with INFO status', () => { 5 ReportingApi.setStatus('info'); 6 // ... 7 }) 8});
Note: Pay attention if you want to provide custom status to the
suite
you should pass describe name as a parameter.
1// Cucumber 2Given('I do something awesome', () => { 3 ReportingApi.setStatus('info'); 4 //... 5});
Assign corresponding status to the current test item or suite.
ReportingApi.setStatusFailed(suite?: string);
ReportingApi.setStatusPassed(suite?: string);
ReportingApi.setStatusSkipped(suite?: string);
ReportingApi.setStatusStopped(suite?: string);
ReportingApi.setStatusInterrupted(suite?: string);
ReportingApi.setStatusCancelled(suite?: string);
ReportingApi.setStatusInfo(suite?: string);
ReportingApi.setStatusWarn(suite?: string);
Examples:
1// Jasmine/Mocha 2describe('manual statuses assigning', () => { 3 ReportingApi.setStatusInfo('manual statuses assigning'); // string must match the name of the suite 4 it('should call ReportingApi to set statuses', () => { 5 ReportingApi.setStatusInfo(); 6 }); 7 // ... 8});
Note: Pay attention if you want to provide custom status to the
suite
you should pass describe name as a parameter.
1// Cucumber 2Given('I do something awesome', () => { 3 ReportingApi.setStatusInfo(); 4 //... 5});
Assign corresponding status to the current launch.
ReportingApi.setLaunchStatus(status: string);
required: status
where status
must be one of the following: passed, failed, stopped, skipped, interrupted, cancelled, info, warn
Examples:
1// Jasmine/Mocha 2it('launch should have status FAILED', () => { 3 ReportingApi.setLaunchStatus('failed'); 4 // ... 5});
1// Cucumber 2Given('I do something awesome', () => { 3 ReportingApi.setLaunchStatus('failed'); 4 //... 5});
Assign corresponding status to the current launch.
ReportingApi.setLaunchStatusFailed();
ReportingApi.setLaunchStatusPassed();
ReportingApi.setLaunchStatusSkipped();
ReportingApi.setLaunchStatusStopped();
ReportingApi.setLaunchStatusInterrupted();
ReportingApi.setLaunchStatusCancelled();
ReportingApi.setLaunchStatusInfo();
ReportingApi.setLaunchStatusWarn();
Examples:
1// Jasmine/Mocha 2it('should call ReportingApi to set launch statuses', () => { 3 ReportingApi.setLaunchStatusInfo(); 4});
1// Cucumber 2Given('I do something awesome', () => { 3 ReportingApi.setLaunchStatusInfo(); 4 //... 5});
Send logs to the ReportPortal for the current test.
ReportingApi.log(level: LOG_LEVELS, message: string, file?: Attachmentm, suite?: string);
required: level
, message
where level
can be one of the following: TRACE, DEBUG, WARN, INFO, ERROR, FATAL
Examples:
1// Jasmine/Mocha 2it('should contain logs with attachments', () => { 3 const fileName = 'test.jpg'; 4 const fileContent = fs.readFileSync(path.resolve(__dirname, './attachments', fileName)); 5 const attachment = { 6 name: fileName, 7 type: 'image/jpg', 8 content: fileContent.toString('base64'), 9 }; 10 ReportingApi.log('INFO', 'info log with attachment', attachment); 11 // ... 12});
1// Cucumber 2Given('I do something awesome', () => { 3 const fileName = 'test.jpg'; 4 const fileContent = fs.readFileSync(path.resolve(__dirname, './attachments', fileName)); 5 const attachment = { 6 name: fileName, 7 type: 'image/jpg', 8 content: fileContent.toString('base64'), 9 }; 10 ReportingApi.log('INFO', 'info log with attachment', attachment); 11 //... 12});
Send logs with corresponding level to the ReportPortal for the current suite/test. Should be called inside corresponding suite/test.
ReportingApi.info(message: string, file?: Attachment, suite?: string);
ReportingApi.debug(message: string, file?: Attachment, suite?: string);
ReportingApi.warn(message: string, file?: Attachment, suite?: string);
ReportingApi.error(message: string, file?: Attachment, suite?: string);
ReportingApi.trace(message: string, file?: Attachment, suite?: string);
ReportingApi.fatal(message: string, file?: Attachment, suite?: string);
required: message
Examples:
1// Jasmine/Mocha 2describe('should containe suite log', () => { 3 ReportingApi.info('Log message', null, 'should containe suite log'); // last parameter must match the name of the suite 4 it('should contain logs with different levels', () => { 5 ReportingApi.info('Log message'); 6 ReportingApi.debug('Log message'); 7 ReportingApi.warn('Log message'); 8 ReportingApi.error('Log message'); 9 ReportingApi.trace('Log message'); 10 ReportingApi.fatal('Log message'); 11 // .. 12 }); 13});
Note: Pay attention if you want to provide log to the
suite
you should pass describe name as a last parameter.
1// Cucumber 2Given('I do something awesome', () => { 3 ReportingApi.info('Log message'); 4 ReportingApi.debug('Log message'); 5 ReportingApi.warn('Log message'); 6 ReportingApi.error('Log message'); 7 ReportingApi.trace('Log message'); 8 ReportingApi.fatal('Log message'); 9 //... 10});
Send logs to the ReportPortal for the current launch. Should be called inside the any test.
ReportingApi.launchLog(level: LOG_LEVELS, message: string, file?: Attachment);
required: level
, message
where level
can be one of the following: TRACE, DEBUG, WARN, INFO, ERROR, FATAL
Examples:
1// Jasmine/Mocha 2it('should send log with attachment to launch', async (page) => { 3 const fileName = 'test.jpg'; 4 const fileContent = fs.readFileSync(path.resolve(__dirname, './attachments', fileName)); 5 const attachment = { 6 name: fileName, 7 type: 'image/jpg', 8 content: fileContent.toString('base64'), 9 }; 10 ReportingApi.launchLog('INFO', 'info log with attachment', attachment); // attaching log to the launch 11 // ... 12});
1// Cucumber 2Given('I do something awesome', () => { 3 const fileName = 'test.jpg'; 4 const fileContent = fs.readFileSync(path.resolve(__dirname, './attachments', fileName)); 5 const attachment = { 6 name: fileName, 7 type: 'image/jpg', 8 content: fileContent.toString('base64'), 9 }; 10 ReportingApi.launchLog('INFO', 'info log with attachment', attachment); // attaching log to the launch 11 //... 12});
Send logs with corresponding level to the ReportPortal for the current launch. Should be called inside the any test.
ReportingApi.launchInfo(message: string, file?: Attachment);
ReportingApi.launchDebug(message: string, file?: Attachment);
ReportingApi.launchWarn(message: string, file?: Attachment);
ReportingApi.launchError(message: string, file?: Attachment);
ReportingApi.launchTrace(message: string, file?: Attachment);
ReportingApi.launchFatal(message: string, file?: Attachment);
required: message
Examples:
1// Jasmine/Mocha 2it('launch should contain logs with with different levels', () => { 3 ReportingApi.launchInfo('Log message'); 4 ReportingApi.launchDebug('Log message'); 5 ReportingApi.launchWarn('Log message'); 6 ReportingApi.launchError('Log message'); 7 ReportingApi.launchTrace('Log message'); 8 ReportingApi.launchFatal('Log message'); 9 // ... 10});
Note: Pay attention if you want to provide log to the
launch
you should call ReportingApi methods inside test/it blocks.
1// Cucumber 2Given('I do something awesome', () => { 3 ReportingApi.launchInfo('Log message'); 4 ReportingApi.launchDebug('Log message'); 5 ReportingApi.launchWarn('Log message'); 6 ReportingApi.launchError('Log message'); 7 ReportingApi.launchTrace('Log message'); 8 ReportingApi.launchFatal('Log message'); 9 //... 10});
To integrate with Sauce Labs just add attributes for the test case:
1[{ 2 "key": "SLID", 3 "value": "# of the job in Sauce Labs" 4}, { 5 "key": "SLDC", 6 "value": "EU (your job region in Sauce Labs)" 7}]
For example, this configuration specs: [‘./tests/**/*.spec.js’]
is used to execute each spec in a separate worker process).
There may also be a situation where tests are executed in parallel on different machines.
For the current agent implementation, this will result in multiple launches in ReportPortal.
If a single launch is required for such cases - there are several options for combining them within a single launch.
The reporter config supports the launchId
parameter to specify the id of the already started launch.
This way, you can start the launch manually using @reportportal/client-javascript
before the test run and then specify its id in the config or via environment variable.
This option may also be useful when running several test suites in parallel on different machines.
onPrepare
hook while running on a single machine:1const { Reporter } = require('@reportportal/agent-js-webdriverio'); 2const RPClient = require('@reportportal/client-javascript'); 3 4const rpConfig = { 5 // ... 6}; 7 8exports.config = { 9 // ... 10 reporters: [[Reporter, rpConfig]], 11 // ... 12 onPrepare: async function (exitCode, config, capabilities, results) { 13 async function startLaunch() { 14 const client = new RPClient(rpConfig); 15 const response = await client.startLaunch({ 16 name: rpConfig.launch, 17 attributes: rpConfig.attributes, 18 // etc 19 }).promise; 20 21 return response.id; 22 } 23 24 const launchId = await startLaunch(); 25 // The Launch ID can be set to the environment variable right here 26 process.env.RP_LAUNCH_ID = response.id; 27 }, 28}
Note: If the Launch ID is already known (e.g., created in a separate CI pipeline step before running tests), it can be set directly via the RP_LAUNCH_ID
environment variable or in the agent configuration:
1const { Reporter } = require('@reportportal/agent-js-webdriverio'); 2const RPClient = require('@reportportal/client-javascript'); 3 4const rpConfig = { 5 // ... 6 launchId: 'Id of an already started launch', // or set it via environment variable RP_LAUNCH_ID 7 // ... 8}; 9 10exports.config = { 11 // ... 12 reporters: [[Reporter, rpConfig]], 13 // ... 14}
onComplete
hook while running on a single machine:1const { Reporter } = require('@reportportal/agent-js-webdriverio'); 2const RPClient = require('@reportportal/client-javascript'); 3 4const rpConfig = { 5 // ... 6}; 7 8exports.config = { 9 // ... 10 reporters: [[Reporter, rpConfig]], 11 // ... 12 onComplete: async function (exitCode, config, capabilities, results) { 13 const finishLaunch = async () => { 14 const client = new RPClient(rpConfig); 15 const launchTempId = client.startLaunch({ id: process.env.RP_LAUNCH_ID }).tempId; 16 await client.finishLaunch(launchTempId, {}).promise; 17 }; 18 19 await finishLaunch(); 20 }, 21}
Note: In case of running specs in parallel on several machines, it is recommended to finish the launch after the test execution in a separate step within your CI pipeline.
Using this option a separate launch still will be created for each spec file, but at the end of the entire execution they will be merged into a single launch.
1const rpConfig = { 2 // ... 3 isLaunchMergeRequired: true, 4};
onComplete
hook:1const fs = require('fs'); 2const glob = require('glob'); 3const { Reporter } = require('@reportportal/agent-js-webdriverio'); 4const RPClient = require('@reportportal/client-javascript'); 5 6const rpConfig = { 7 // ... 8 isLaunchMergeRequired: true, 9}; 10 11exports.config = { 12 // ... 13 reporters: [[Reporter, rpConfig]], 14 // ... 15 onComplete: async function (exitCode, config, capabilities, results) { 16 if (rpConfig.isLaunchMergeRequired) { 17 try { 18 const client = new RPClient(rpConfig); 19 await client.mergeLaunches(); 20 console.log('Launches successfully merged!'); 21 } catch (error) { 22 console.error(error); 23 } finally { 24 const files = glob.sync('rplaunch-*.tmp'); 25 const deleteTempFile = (filename) => { 26 fs.unlinkSync(filename); 27 }; 28 files.forEach(deleteTempFile); 29 } 30 } 31 }, 32}
Please check the options described in Getting a single launch section.
Licensed under the Apache 2.0 license (see the LICENSE file).
No vulnerabilities found.
No security vulnerabilities found.