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:

Nature Key Community Premium
Name of the dataset DSNAME OK OK
Dataset parameter DS_[name] OK OK
Test case reference TC_REF OK OK
Test case custom field TC_CUF_[code] OK OK
Iteration custom field IT_CUF_[code] KO OK
Campaign custom field CPG_CUF_[code] KO OK
Test suite custom field TS_CUF_[code] KO OK

Legend:

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

Squash TM parameters usage

When executing a Squash TM automated test case with Cypress, it is possible to exploit the Squash TM parameters inside the test.

In order to achieve this, you'll have to follow these steps:

  • Create custom fields in Squash TM and bind them to the project bearing the test plan to execute.

  • Make sure that the code fields of the parameters correspond to the names of the existing environment variables present in the Cypress script.

Info

Squash TM adds a prefix to the code of the transmitted custom field. Make sure to take it into account.
Please refer to the Squash TM documentation for more information.

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

cypress-params-1

cypress-params-2

cypress-params-1

cypress-params-2

Generation of Allure reports with the cypress/cypress@v1 action

When using the cypress/cypress@v1 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