Gitlab CI/CD: TypeScript/Cypress
Last updated
Last updated
This guide demonstrates integrating automated testing into your GitLab CI/CD pipeline, specifically using Typescript/Cypress. However, the steps can be adapted for any test automation tool or framework to submit results to aqua.
a GitLab project with CI/CD enabled
an aqua account to submit test results
Updating aqua Test Case Execution based on Test Case run in GitLab
Generate new project in your workspace
Make sure that Node.js is installed
Install Cypress with TypeScript: “npm install --save-dev typescript” it will result in the following structure:
Write a test case in Cypress. For this demonstration example we will use a UI test which exercises the “https://example.cypress.io” website. The following e2e test is created under /Cypress/e2e/ project folder:
For automation purpose let's assume that the Test title is based on the actual aqua Test Case Id: e.g in the case above we updated aqua Test Case with Id=270.
Now we need to update aqua Test Case Execution based on the result of the Cypress Test run. To make it general and executable for all cases we will add “AfterEach” hook block in support file: …/cypress/support/e2e.ts:
For the above API request we need to know test case execution status from Cypress. This is being done by “cy.currentTest.state”.
To update aqua with Test Case Execution info we also need to provide aqua Test Case Id: in the above example test case id is extracted from “Number(this.currentTest.title)”.
Classes we use for API calls can be generated from JSON schema available here: https://app.aqua-cloud.io/aquaWebNG/swagger/v1/swagger.json
After successful JUnit test execution we should see corresponding single Test Case execution in aqua
To be able to run the above Cypress Project using GitLab CI/CD we need to create corresponding workflow file .gitlab-ci.yml. Simple Example of .gitlab-ci.yml script is shown below:
Once a GitLab test runner is configured and connected to your GitLab projects we can Run GitLab Pipeline using the above workflow:
Link to GitLab Repository - https://gitlab.com/aqua3191704/cypress-typescript-gitlab.git