top of page

Use Allure in Cypress

  • doanhoavn
  • Jun 15, 2021
  • 1 min read

Updated: Jul 6, 2021

  • Step 1: Install @shelex/cypress-allure-plugin and allure-commandline


		npm i -D @shelex/cypress-allure-plugin

after you installed, it is inserted in package.json like this

"devDependencies": {

"@shelex/cypress-allure-plugin": "^2.7.0",

"allure-commandline": "^2.13.8"

}

  • Step 2: Connect plugin in cypress/plugins/index.js

const allureWriter = require('@shelex/cypress-allure-plugin/writer');

module.exports = (on, config) => {
    allureWriter(on, config);
    return config;
};
  • Step 3: Register commands in cypress/support/index.js file

//To use Allure report
import '@shelex/cypress-allure-plugin';
  • Step 4: for IntelliSense (autocompletion) support in your IDE add on top of your cypress/plugins/index.js file

/// <reference types="@shelex/cypress-allure-plugin" />
  • Step 5: Configuration

+ Via cypress.json

"env": {
        "allureResultsPath": "cypress/reports/allure-results",
        // tms prefix used without `*`, equivalent to `https://url-to-bug-tracking-system/task-*`"tmsPrefix": "https://url-to-bug-tracking-system/task-",
        "issuePrefix": "https://url-to-tms/tests/caseId-"// usage:  cy.allure().issue('blockerIssue', 'AST-111')// result: https://url-to-bug-tracking-system/task-AST-111
    }

That's all. Now we will run and view allure report.


Here is my package.json and cypress.json


package.json

{
  "name": "democypress",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "cy_run": "cypress run --spec ./cypress/integration/test/*.spec.js --browser chrome --env allure=true",
    "clean_reports": "(if exist cypress/reports/allure-results rmdir /q/s cypress/reports/allure-results) && if exist cypress/reports/allure-reports rmdir /q/s cypress/reports/allure-reports",
    "generate_report": "allure generate cypress/reports/allure-results --clean -o cypress/reports/allure-reports",
    "run_test": "npm run cy_run && npm run generate_report"
  },
  "author": "hoa doan",
  "license": "ISC",
  "devDependencies": {
    "cypress": "^7.2.0",
    "cypress-file-upload": "^5.0.7",
    "cypress-plugin-tab": "^1.0.5",
    "cypress-xpath": "^1.6.2",
    "moment": "^2.29.1",
    "@shelex/cypress-allure-plugin": "^2.7.0",
    "allure-commandline": "^2.13.8"
  }
}

cypress.json

{
  "baseUrl": "https://demoqa.com",
  "projectId": "wmbmub",
  "testFiles": "**/**.spec.js",
  "browser": "chrome",
  "watchForFileChanges": false,
  "chromeWebSecurity": false,
  "env": {
    "apiUrl": "https://demoqa.com",
    "allureResultsPath": "cypress/reports/allure-results"
  },
  "video": false,
  "screenshotOnRunFailure": true
}

1. First, I run script

npm run cy_run

--> report json with images is put in Cypress.env('allureResultsPath') - cypress/reports/allure-results


2. Generate report

npm run generate_report

--> now report is generated in cypress/reports/allure-reports


3. Open report by command line

allure open cypress/reports/allure-reports



References






Comments


Post: Blog2_Post
  • Facebook
  • Twitter
  • LinkedIn

©2020 by Bom's blogger. Proudly created with Wix.com

bottom of page