Skip to content

Automation with Cypress

Test reference in Squash TM

Info

In this version of Squash AUTOM, it is not possible to select a specific test in a .spec.js file containing several ones: all tests in the file are therefore executed together. The result of each executed Squash TM test case is calculated by taking into account the individual results of each test included in the bound file:

  • If at least one test has an Error status (in case of a technical issue), the status of the execution will be Blocked.

  • If at least one test fails functionally and none of the other has an Error status, the status of the execution will be Failed.

  • If all tests succeed, the status of the execution will be Success.

In order to bind a Squash TM test case to a Cypress automated test, the content of the Automated test reference field of the Automation block of a test case must have the following format:

[1] / [2]

With:

  • [1]: Name of the project on the source code repository.

  • [2]: Path and name of the Cypress test file, from the root of the project (with the .spec.js extension).

Nature of the exploitable Squash TM parameters

The exploitable Squash TM parameters in a Cypress script will differ depending on whether you're using the Community or Premium version of Squash DEVOPS.

Here is a table showing the exploitable parameters (these parameters are transmitted as test parameters, see below, Squash TM does not generate global parameters):

Nature Key Community Premium
Name of the dataset DSNAME βœ… βœ…
Dataset parameter DS_[name] βœ… βœ…
Test case reference TC_REFERENCE βœ… βœ…
Test case custom field TC_CUF_[code] βœ… βœ…
Iteration custom field IT_CUF_[code] ❌ βœ…
Campaign custom field CPG_CUF_[code] ❌ βœ…
Test suite custom field TS_CUF_[code] ❌ βœ…

Legend:

  • [code]: Value of the "Code" of a custom field
  • [name]: Parameter name as filled in Squash TM

As indicated, Squash TM adds a prefix to the code of the transmitted custom field. Make sure to take it into account.

Refer to the Squash TM documentation for more information about custom fields.

Parameters usage

It is possible, when running Cypress tests, to exploit parameters within it. A parameter can be a test parameter or a global parameter. Squash TM transmits only test parameters. Test parameters and global parameters can be used in Squash DevOps with the cypress/params action.

The parameters are available as CYPRESS_VAR environment variables and can be retrieved using the Cypress.env('VAR') syntax (see the Cypress documentation). If the same name is used both for a global parameter and a test parameter, the last one is used.

Example

Below is an example of a Cypress test file and the corresponding Squash TM test case automation:

Cypress example

Cypress example

Cypress example

Cypress example

Generation of Allure reports with the cypress/cypress action

When using the cypress/cypress action‑ (via the piloting with a PEaC), if you want the Cypress test results to appear in the Allure report generated for the PEaC, you need to:

1) configure (in the cypress.yaml configuration file of the cypress provider) a hook to capture the JUnit reports:

apiVersion: opentestfactory.org/v1alpha1
kind: ServiceConfig
current-context: allinone
contexts:
- context:
    port: 7789
    host: 127.0.0.1
    ssl_context: disabled
    trusted_authorities:
    - /etc/squashtf/squashtf.pub
    logfile: cypress.log
    enable_insecure_login: true
    eventbus:
        endpoint: http://127.0.0.1:38368
        token: reuse
  name: allinone
hooks:
- name: capture JUnit reports
  events:
  - categoryPrefix: cypress
    category: cypress
  after:
  - uses: actions/get-files
    with:
      pattern: test-output-*.xml

2) indicate in the PEaC to generate a JUnit report per test using the following reporter et reporter-options values:

{
  "apiVersion": "opentestfactory.org/v1alpha1",
  "kind": "Workflow",
  "metadata": {
    "name": "Cypress"
  },
  "jobs": {
    "execute": {
      "runs-on": "cypress",
      "steps": [
        {
          "uses": "actions/checkout@v2",
          "with": {
            "repository": "https://github.com/my-repo"
          }
        },
        {
          "uses": "cypress/cypress@v1",
          "with": {
            "reporter": "junit",
            "reporter-options": "mochaFile=test-output-[hash].xml,toConsole=true",
            "headless": "true"
          },
          "working-directory": "cypressDocCheck"
        }
      ]
    }
  }
}

‑ This is not necessary for Cypress tests launched from Squash TM or via Squash TM test execution plan retrieval with a PEaC.

Supported versions

Squash AUTOM and Squash DEVOPS have been validated with Cypress 8.5.0. Any recent version should work properly.

Back to top