0.16.4 • Published 3 months ago

@mmisty/cypress-allure-adapter v0.16.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

cypress-allure-adapter

actions

This is allure adapter for Cypress providing realtime results. It is useful when using Allure TestOps - so you can watch tests execution. It adds tests, steps, suites and screenshots during tests execution.

In the same time you can generate Allure Report from these results, and it will have all necessary fields.

Some settings were taken from @shelex/cypress-allure-plugin, thank you!

Features:

  • automatically adds all cypress commands to report (this is configurable)
  • automatically adds hooks (before all, before each, after each, after all) to tests
  • if before all or before each hook fails cypress skips all tests in spec file. This plugin will create tests that were not run for allure report with unknown status - so total number of tests would be the same from run to run
  • has interface to add metadata like tags, links, owner, host and others.
  • has interface to add additional steps
  • Wraps custom commands into parent step, so report is cleaner
  • has interface to set status message for tests - cy.allure().testDetails({ message: "This test is skipped because needs to be reviewed" })
  • writes test files after each test - so you can watch execution in Allure TestOps
  • gherkin support

Example report is here - Allure Report example

Table of Contents

  1. Installation
  2. Environment variables
  3. To see allure report
  4. Allure Interface
  5. Advanced
  6. Examples
  7. Allure TestOps
  8. Troubleshooting
  9. See also:
  10. Credits
  11. Change log
  12. Support

Installation

Install adapter by npm i -D @mmisty/cypress-allure-adapter

1. Update support

Import @mmisty/cypress-allure-adapter/support into your support/index.ts file (or e2e.ts/ e2e.js file)

   // e2e.ts

   // import cypress-allure-adapter first to have all custom
   // commands being collapsed in report as parent command
   import '@mmisty/cypress-allure-adapter/support';
   // import other custom commands here

If you want all custom commands to be wrapped in report import adapter before adding(importing) any custom commands

Add allureAdapterSetup(); in your support/index.ts file (or e2e.ts file)

import { allureAdapterSetup } from '@mmisty/cypress-allure-adapter';

allureAdapterSetup();

If you want all custom commands to be correctly wrapped in report register adapter before adding custom commands:

  import { allureAdapterSetup } from '@mmisty/cypress-allure-adapter';
  
  allureAdapterSetup();
  // register custom commands here
// e2e.js

// import cypress-allure-adapter first to have all custom
// commands being collapsed in report as parent command
    import '@mmisty/cypress-allure-adapter/support';
   // import other custom commands here

2. Update plugins (setupNodeEvents)

Add configureAllureAdapterPlugins(on, config); into your plugins file:

// cypress.config.ts
import { configureAllureAdapterPlugins } from '@mmisty/cypress-allure-adapter/plugins';

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      configureAllureAdapterPlugins(on, config);
      
      return config;
    },
    // ...
  }
});
// cypress.config.js
const { configureAllureAdapterPlugins } = require("@mmisty/cypress-allure-adapter/plugins");

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      configureAllureAdapterPlugins(on, config);
      
      return config;
    },
    // ...
  }
});

3. Update environment variables

In cypress.config.ts or cypress.config.js or in your environment files set allure env var to true.

See other environment variables

4. Types

Typescript: No need to setup types - should be done automatically

That's it! :tada:

Environment variables

VariableDescription
alluretype: booleandefault: falseEnables reporting
allureResultstype: stringdefault: allure-resultsPath to allure results folder (where json files will be written)
allureResultsWatchPathtype: stringdefault: allure-resultsThis is needed when using Allure TestOps: path to folder where results will be moved after finishing. This path is what you need to watch when using Allure TestOps, but default this is not specified. When you use this path test results will start to appear in Allure TestOps, video will appear only after spec is finished. If do not use this with Allure TestOps some videos may not be uploaded - videos will be uploaded only for 1 test from spec file.
allureLogCyCommandstype: booleandefault: truelog cypress commands, by default will log allcy_steps
allureSkipCommandstype: stringex.: screenshot,waitCypress commands separated with comma. Will skip only cypress commands used by cy. (any child commands will persist)Will not log specified commands as steps in allure report, by default logs all commands. You can also use asterisk in command name - it will be assumed as any chars
allureSkipStepstype: stringex.: screenshot,wait ex.: "after each" hook*,"before each" hook*,"before all" hook*Any allure steps that were created separated with comma (ex. cy.allure().startStep('my-step') - my-step can be added into allureSkipSteps env var, if you put into allureSkipCommands this command will still persist). Will not log specified steps at all including child steps, by default logs all steps. To skip before each / before all / after each or after all hooks their names can be added here. You can also use asterisk in step name - it will be assumed as any chars
allureWrapCustomCommandstype: true/false/stringdefault: true ex: - allureWrapCustomCommands: 'true' - allureWrapCustomCommands:'qaId,login' - allureWrapCustomCommands:'!qaValue'will wrap custom commands, so custom command will have child steps in reportWhen value has string with commands split by comma will wrap only these commands. To exclude commands specify them starting with ! - all commands specified in this variable should have either ! or not have it For this to work you should register allure plugin in setup files before any new commands are added.wrap-cmd
allureCleanResultstype: booleandefault: falseWill remove allure results on cypress start (it will be done once, after plugins are loaded)
allureAttachRequeststype: booleandefault: falseAttach request/response body and status as files to request stepSeveral requests:requestsOne request: request
allureCompactAttachmentstype: booleandefault: trueStringify requests attachments with spaces or not
allureAddVideoOnPasstype: booleandefault: falseWhen true - will attach video for all tests (including passed), otherwise will attach videos only for failed, broken, unknown
tmsPrefix type: stringex: http://jira.com or http://jira.com/PROJECT-1/*/browseYou can specify prefix to tms using this. It will be concatenated with value when using cypress interface like cy.allure().tms('PROJ-01'). Also link can be specified with * - it will be replaced with id. Difference between tms and issue - will have different icons: links
issuePrefix type: stringex: http://jira.com or http://jira.com/PROJECT-1/*/browseThe same as tmsPrefix - for issue cy.allure().issue('PROJ-02')
allureShowDuplicateWarntype: booleandefault: falseShow console warnings about test duplicates.
allureShowTagsInTitletype: booleandefault: undefinedWhether to show tags in test title or not. When undefined will keep title as is
allureAddNonSpecialTagstype: booleandefault: trueWhether to add non-special tags to tests

tmsPrefix and issuePrefix

tmsPrefix and issuePrefix - you can specify prefix to tms using this. Also link can be specified with * - it will be replced with id.

   // cypress.config.ts 
   env: {
     tmsPrefix: 'http://jira.com' 
     issuePrefix: 'http://jira.com/PROJECT-1/*/browse' 
   }  
    // test.spec.ts
    cy.allure().tms('ABC-1'); // http://jira.com/ABC-1
    cy.allure().issue('ABC-2'); // http://jira.com/PROJECT-1/ABC-2/browse

To see report

In order to see Allure Report you need to install the CLI.

For nodejs you can use allure-commandline:

npm i -D allure-commandline

After installed allure command will be available. To see a report in browser, run in console

allure serve

If you want to generate html version, run in console

allure generate

Report example: Allure Report

Allure Interface

There is allure interface available to use from tests - cy.allure() and Cypress.Allure.

For details see interface

Advanced

after:spec event

This plugin uses after:spec plugins event to write videos and to write test results for Allure TestOps.

If you also use it in your cypress project cypress-allure-adapter after:spec would be rewritten.

To avoid that you can add await reporter.afterSpec({ results }); into your Cypress plugin action after:spec:

// cypress.config.ts
import { configureAllureAdapterPlugins } from '@mmisty/cypress-allure-adapter/plugins';

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      const reporter = configureAllureAdapterPlugins(on, config);
      
      on('after:spec', async (spec, results) => {
        // your code in after spec
        await reporter.afterSpec({ results });
      })
      
      return config;
    },
    // ...
  }
});

Before run

Some operations like writing environment information, execution info or categories definitions should be done once for a run.

To do that you need to modify your setupNodeEvents function:

  // cypress.config.ts
  import { configureAllureAdapterPlugins } from '@mmisty/cypress-allure-adapter/plugins';
  
  export default defineConfig({
    e2e: {
      setupNodeEvents(on, config) {
         const reporter = configureAllureAdapterPlugins(on, config);
         
         // after that you can use allure to make operations on cypress start,
         // or on before run start
         on('before:run', details => {
            reporter?.writeEnvironmentInfo({
               info: {
                  os: details.system.osName,
                  osVersion: details.system.osVersion,
               },
            });
         });
         
        return config;
      },
      // ...
    }
  });

Start/End test events

If you need to add labels, tags or other meta info for tests you can use the following additional events for Cypress.Allure interface:

  • test:started is fired after tests started but before all "before each" hooks
  • test:ended is fired after all "after each" hooks
Cypress.Allure.on('test:started', test => {
    Cypress.Allure.label('tag', 'started');
  });

And also if you need to do something with test before it ends:

Cypress.Allure.on('test:ended', test => {
    Cypress.Allure.label('tag', 'ended');
    Cypress.Allure.step('before end step');
  });

You can put this into your support/index.ts file.

Examples

Allure TestOps

Suites tree

To have correct suites tree you need to set up Allure TestOps: 1. Go to Administration section (for the whole application) -> Custom Fields section 2. Create 3 new fields if they not exist already: Parent Suite, Suite, Sub Suite 3. Go to Settings section for the project -> Custom Fields 4. Add mapping to newly added fields: - type key parentSuite and select from dropdown custom field Parent Suite - type key suite and select from dropdown custom field Suite - type key subSuite and select from dropdown custom field Sub Suite 5. Open Trees section from project settings 6. Add or modify Suites tree with the following chain: Parent Suite -> Suite -> Sub Suite

Troubleshooting

To see debug log run cypress with DEBUG env variable like: DEBUG=cypress-allure* npm run cy:open

No allure results folder

  • make sure you have enabled plugin by 'allure' env variable
  • to be continued

No results in allure folder

  • make sure you are not overriding confi in plugins (env variables, and events)
  • to be continued

Credits

Thanks to @shelex, without his plugin this plugin would have been harder to start.

Change log

see change log

Support

Mostly, I develop this plugin during my free time. However, I need your support to take it to the next level. Your donation will directly contribute to the further development of this plugin, allowing me to dedicate more time and resources to enhancing its features, improving user experience, and ensuring its compatibility with the latest versions. Help this plugin to grow by donating.

0.15.4-alpha.5

3 months ago

0.16.4

3 months ago

0.15.4-alpha.4

3 months ago

0.16.3

3 months ago

0.15.4-alpha.3

4 months ago

0.15.4-alpha.2

5 months ago

0.16.2

5 months ago

0.16.1

5 months ago

0.15.4-alpha.1

5 months ago

0.16.0

5 months ago

0.15.4-alpha.0

5 months ago

0.15.3

5 months ago

0.15.2

6 months ago

0.15.1-alpha.2

6 months ago

0.15.1-alpha.1

6 months ago

0.15.1

6 months ago

0.15.1-alpha.0

6 months ago

0.15.0

6 months ago

0.14.3

6 months ago

0.14.3-alpha.0

6 months ago

0.14.2

6 months ago

0.14.2-alpha.0

6 months ago

0.14.1

6 months ago

0.14.1-alpha.0

6 months ago

0.14.0

6 months ago

0.13.1-alpha.1

6 months ago

0.13.1-alpha.0

6 months ago

0.13.0

6 months ago

0.12.4-alpha.0

6 months ago

0.12.4

6 months ago

0.12.3

6 months ago

0.12.3-alpha.1

6 months ago

0.12.3-alpha.0

6 months ago

0.12.2

6 months ago

0.12.1

6 months ago

0.12.1-alpha-1

6 months ago

1.0.1

6 months ago

0.12.0

6 months ago

0.11.0

7 months ago

0.10.7

7 months ago

0.10.6

7 months ago

0.10.5

7 months ago

0.10.4

8 months ago

0.10.3

8 months ago

0.10.2

8 months ago

0.10.1

8 months ago

0.10.1-alpha.0

8 months ago

0.10.0

8 months ago

0.9.0

8 months ago

1.0.0

8 months ago

0.8.7

8 months ago

0.8.6

8 months ago

0.8.5

8 months ago

0.8.4

9 months ago

0.8.3

9 months ago

0.8.2

9 months ago

0.8.1

9 months ago

0.8.0

9 months ago

0.7.3

9 months ago

0.7.2

9 months ago

0.7.1

9 months ago

0.7.0

9 months ago

0.6.2

10 months ago

0.6.1

10 months ago

0.6.0

10 months ago

0.5.0

10 months ago

0.4.1

10 months ago

0.4.0

10 months ago

0.3.3

10 months ago

0.3.2

10 months ago

0.3.1

10 months ago

0.3.0

10 months ago

0.2.9

10 months ago

0.2.8

10 months ago

0.2.7

10 months ago

0.2.6

10 months ago

0.2.5

10 months ago

0.2.4

10 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.1.0

10 months ago

0.0.2-alpha-6

10 months ago

0.0.2-alpha-5

10 months ago

0.0.2-alpha-4

10 months ago

0.0.2-alpha-3

10 months ago

0.0.0

10 months ago

0.0.2-alpha-2

10 months ago

0.0.2-alpha-1

10 months ago

0.0.1

10 months ago

0.0.1-beta.13

10 months ago

0.0.1-beta.12

10 months ago

0.0.1-beta.11

10 months ago

0.0.1-beta.10

10 months ago

0.0.1-beta.9

10 months ago

0.0.1-beta.8

10 months ago

0.0.1-beta.7

10 months ago

0.0.1-beta.6

10 months ago

0.0.1-beta.5

10 months ago

0.0.1-beta.4

10 months ago

0.0.1-beta.3

10 months ago

0.0.1-beta.2

10 months ago

0.0.1-beta.1

10 months ago