Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@reportportal/agent-js-cypress
Advanced tools
This agent helps Cypress to communicate with Report Portal
Agent to integrate Cypress with ReportPortal.
$ npm install --save-dev @reportportal/agent-js-cypress
There is a configuration guide for Cypress version 10 and above.
Add the following options to cypress.config.js.
const { defineConfig } = require('cypress');
const registerReportPortalPlugin = require('@reportportal/agent-js-cypress/lib/plugin');
module.exports = defineConfig({
reporter: '@reportportal/agent-js-cypress',
reporterOptions: {
endpoint: 'http://your-instance.com:8080/api/v1',
apiKey: 'reportportalApiKey',
launch: 'LAUNCH_NAME',
project: 'PROJECT_NAME',
description: 'LAUNCH_DESCRIPTION',
attributes: [
{
key: 'attributeKey',
value: 'attributeValue',
},
{
value: 'anotherAttributeValue',
},
],
},
e2e: {
setupNodeEvents(on, config) {
return registerReportPortalPlugin(on, config);
},
},
});
To see more options refer Options.
Add the following to your custom commands file (cypress/support/commands.js):
require('@reportportal/agent-js-cypress/lib/commands/reportPortalCommands');
See examples of usage here.
There is a configuration guide for Cypress version 9 and below.
Add the following options to cypress.json
{
"reporter": "@reportportal/agent-js-cypress",
"reporterOptions": {
"endpoint": "http://your-instance.com:8080/api/v1",
"apiKey": "reportportalApiKey",
"launch": "LAUNCH_NAME",
"project": "PROJECT_NAME",
"description": "LAUNCH_DESCRIPTION",
"attributes": [
{
"key": "attributeKey",
"value": "attributeValue"
},
{
"value": "anotherAttributeValue"
}
]
}
}
To see more options refer Options.
const registerReportPortalPlugin = require('@reportportal/agent-js-cypress/lib/plugin');
module.exports = (on, config) => registerReportPortalPlugin(on, config);
Add the following to your custom commands file (cypress/support/commands.js):
require('@reportportal/agent-js-cypress/lib/commands/reportPortalCommands');
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. |
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. |
launchUuidPrint | Optional | false | Whether to print the current launch UUID. |
launchUuidPrintOutput | Optional | 'STDOUT' | Launch UUID printing output. Possible values: 'STDOUT', 'STDERR'. Works only if launchUuidPrint set to true . |
restClientConfig | Optional | Not set | The object with agent property for configure http(s) client, may contain other client options eg. timeout . Visit client-javascript for more details. |
autoMerge | Optional | false | Enable automatic report test items of all runned spec into one launch. You should install plugin or setup additional settings in reporterOptions. See Automatically merge launch. |
reportHooks | Optional | false | Determines report before and after hooks or not. |
isLaunchMergeRequired | Optional | false | Allows to merge Cypress run's into one launch at the end of the run. Needs additional setup. See Manual merge launches. |
parallel | Optional | false | Indicates to the reporter that spec files will be executed in parallel. Parameter could be equal boolean values. See Parallel execution. |
token | Deprecated | Not set | Use apiKey instead. |
If you run Cypress tests programmatically or use cypress.config.js
, you can simply overwrite them:
const updatedConfig = {
...config,
reporterOptions: {
...config.reporterOptions,
apiKey: process.env.RP_API_KEY,
},
};
For security reasons, you can also set token as a part of Environment Variables, instead of sharing it in the config file:
Option | ENV variable | Note |
---|---|---|
apiKey | RP_API_KEY | |
token | RP_TOKEN | deprecated Use RP_API_KEY instead. |
ReportPortal provides the following custom commands for reporting logs into the current test.
cy.log(log)
. Reports message as an info log of the current test.You can use the following methods to report logs and attachments with different log levels:
file should be an object:
{
name: "filename",
type: "image/png", // media type
content: data, // file content represented as 64base string
}
Note: The cy.debug
RP command has been changed to cy.logDebug
due to the command with the same name in Cypress 9.*.
addTestAttributes (attributes). Add attributes(tags) to the current test. Should be called inside of corresponding test.
attributes is array of pairs of key and value:
[{
key: "attributeKey1",
value: "attributeValue2",
}]
Key is optional field.
To integrate with Sauce Labs just add attributes:
[{
"key": "SLID",
"value": "# of the job in Sauce Labs"
}, {
"key": "SLDC",
"value": "EU (EU or US)"
}]
setTestDescription (description). Set text description to the current test. Should be called inside of corresponding test.
setTestCaseId (id, suite). Set test case id to the current test or suite. Should be called inside of corresponding test/suite.
id is a string test case Id.
suite (optional) is the title of the suite to which the specified test case id belongs. Should be provided just in case of reporting test case id for specified suite instead of current test.
ReportPortal provides the following custom commands for setting status to the current suite/spec.
You can use the shorthand forms of the cy.setStatus method:
ReportPortal also provides the corresponding methods for setting status into the launch:
To use custom filename in cy.screenshot function you should setup ReportRortal custom commands. Default usage of Cypress screenshot function is supported without additional setup.
By default Cypress create a separate run for each test file. This section describe how to report test items of different specs into the single launch. This feature needs information about Cypress configuration. To provide it to the reporter you need to install reportPortal plugin (see how to in this section).
Enable auto-merge in reporterOptions as shown below:
{
...
"reporterOptions": {
...
"autoMerge": true
}
}
There is a possibility to merge all launches into a single launch in the end of the run. We advise using autoMerge option to merge results in one launch, but you can use this alternative option in case of you need to perform some additional actions before merge.
Edit cypress.config.js (or cypress.json for versions <=9) file. Set isLaunchMergeRequired option to true as shown below:
{
...
reporterOptions: {
...
isLaunchMergeRequired: true
}
}
Create folder "scripts" on project folder. Copy the following script into "cypress.js" file and put it to "scripts" folder.
const cypress = require('cypress');
const fs = require('fs');
const glob = require('glob');
const { mergeLaunches } = require('@reportportal/agent-js-cypress/lib/mergeLaunches');
// const { config } = require('../cypress.config.js'); // for Cypress >= 10
const cypressConfigFile = 'cypress.json'; // for cypress <= 9
const getLaunchTempFiles = () => {
return glob.sync('rplaunch-*.tmp');
};
const deleteTempFile = (filename) => {
fs.unlinkSync(filename);
};
cypress.run().then(
() => {
fs.readFile(cypressConfigFile, 'utf8', (err, data) => {
if (err) {
throw err;
}
const config = JSON.parse(data);
if (config.reporterOptions.isLaunchMergeRequired) {
mergeLaunches(config.reporterOptions)
.then(() => {
const files = getLaunchTempFiles();
files.forEach(deleteTempFile);
console.log('Launches successfully merged!');
process.exit(0);
})
.catch((err) => {
console.error(error);
process.exit(1);
});
} else {
process.exit(0);
}
});
},
(error) => {
console.error(error);
const files = getLaunchTempFiles();
files.forEach(deleteTempFile);
process.exit(1);
},
);
"scripts": {
...
"cypress": "node scripts/cypress.js",
...
},
Cypress can run recorded tests in parallel across multiple machines since version 3.1.0 (Cypress docs).
By default Cypress create a separate run for each test file. To merge all runs into one launch in Report Portal you need to provide autoMerge option together with parallel flag.
Since Cypress does not provide the ci_build_id to the reporter, you need to provide it manually using the CI_BUILD_ID environment variable (see Cypress docs for details).
Enable parallel in reporterOptions as shown below:
{
...
reporterOptions: {
...
parallel: true
}
}
Here's an example of setting up parallel Cypress execution using GitHub Actions:
name: CI-pipeline
on:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
container: cypress/browsers:node12.18.3-chrome87-ff82
strategy:
fail-fast: false
matrix:
containers: [1, 2, 3]
env:
CI_BUILD_ID: ${{ github.sha }}-${{ github.workflow }}-${{ github.event_name }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: 'UI Tests - Chrome'
uses: cypress-io/github-action@v2
with:
config-file: cypress.json
group: 'UI Tests - Chrome'
spec: cypress/integration/*
record: true
parallel: true
env:
CYPRESS_RECORD_KEY: ${{ secrets.RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ACTIONS_RUNNER_DEBUG: true
Note: The example provided for Cypress version <= 9. For Cypress version >= 10 usage of cypress-io/github-action
may be changed.
Specify the options in the cypress.config.js:
const { defineConfig } = require('cypress');
const createBundler = require('@bahmutov/cypress-esbuild-preprocessor');
const preprocessor = require('@badeball/cypress-cucumber-preprocessor');
const createEsbuildPlugin = require('@badeball/cypress-cucumber-preprocessor/esbuild').default;
const registerReportPortalPlugin = require('@reportportal/agent-js-cypress/lib/plugin');
module.exports = defineConfig({
reporter: '@reportportal/agent-js-cypress',
reporterOptions: {
endpoint: 'http://your-instance.com:8080/api/v1',
apiKey: 'reportportalApiKey',
launch: 'LAUNCH_NAME',
project: 'PROJECT_NAME',
description: 'LAUNCH_DESCRIPTION',
},
e2e: {
async setupNodeEvents(on, config) {
await preprocessor.addCucumberPreprocessorPlugin(on, config);
on(
'file:preprocessor',
createBundler({
plugins: [createEsbuildPlugin(config)],
}),
);
registerReportPortalPlugin(on, config);
return config;
},
specPattern: 'cypress/e2e/**/*.feature',
supportFile: 'cypress/support/e2e.js',
},
});
At the moment it is not possible to subscribe to start and end of scenario steps events. To solve the problem with displaying steps in the ReportPortal, the agent provides special commands: cucumberStepStart
, cucumberStepEnd
.
To work correctly, these commands must be called in the BeforeStep
/AfterStep
hooks.
import { BeforeStep, AfterStep } from '@badeball/cypress-cucumber-preprocessor';
BeforeStep((step) => {
cy.cucumberStepStart(step);
});
AfterStep((step) => {
cy.cucumberStepEnd(step);
});
You can avoid duplicating this logic in each step definitions. Instead, add it to the cypress/support/step_definitions.js
file and include the path to this file in the stepDefinitions array (if necessary) within cucumber-preprocessor config. These hooks will be used for all step definitions.
Licensed under the Apache License v2.0
[5.3.0] - 2024-05-07
cucumberStepStart
and cucumberStepEnd
commands for reporting cypress-cucumber-preprocessor
scenario steps as nested steps in RP.FAQs
This agent helps Cypress to communicate with ReportPortal
The npm package @reportportal/agent-js-cypress receives a total of 20,935 weekly downloads. As such, @reportportal/agent-js-cypress popularity was classified as popular.
We found that @reportportal/agent-js-cypress 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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.