Cypress Component
This component runs Cypress browser tests in a pinned container image. It can verify a review environment or an application supplied as a GitLab CI service.
Usage
Add the component to .gitlab-ci.yml and point path at the directory that contains cypress.config.* and the Cypress tests:
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/cypress@stable
inputs:
path: tests/e2e
browser: firefox
review-domain: $CI_ENVIRONMENT_SLUG.review.example.com
The test directory is mounted at /e2e. Its npm dependencies are installed before Cypress starts. Use needs when the tests require artifacts or a job that prepares their target.
Test a public URL
Set review-domain to the public host and read CI_ENVIRONMENT_URL in the Cypress configuration. The following example checks the public GitLab project API.
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/cypress@stable
inputs:
path: tests/e2e
browser: electron
environment: gitlab-com
review-domain: gitlab.com
export default {
e2e: {
baseUrl: process.env.CI_ENVIRONMENT_URL,
supportFile: false,
},
video: false,
};
describe('GitLab.com', () => {
it('serves the GitLab project', () => {
cy.request('/api/v4/projects/278964').then((response) => {
expect(response.status).to.equal(200);
expect(response.body.path_with_namespace).to.equal('gitlab-org/gitlab');
});
});
});
Add a minimal package.json in tests/e2e so the component can run npm install before Cypress starts:
{
"name": "gitlab-cypress-smoke-test",
"private": true
}
The job succeeds after Cypress receives the public GitLab project metadata.
Service under test
Use services to run an application beside Cypress. The Cypress browser runs in a nested container, so configure its base URL with host.containers.internal and the port exposed by the service. GitLab services in the Kubernetes executor share the job pod network.
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/cypress@stable
inputs:
path: tests/e2e
browser: electron
services:
- name: $CI_REGISTRY_IMAGE/test-server:$CI_COMMIT_SHA
alias: test-server
needs:
- job: build:test-server
artifacts: false
export default {
e2e: {
baseUrl: 'http://host.containers.internal',
},
};
Use proxy and no-proxy when the test environment requires an HTTP proxy. Set record-key to enable Cypress Cloud recording, and use options for additional cypress run arguments.
Registry authentication
For private job images and OCI client credentials, follow the central registry authentication guide.
Inputs
| Name | Description | Default | Type |
| --- | --- | --- | --- |
| browser | firefox | string | |
| environment | int | string | |
| environment-identifier | Environment identifier, typically in the format /review-$CI_PIPELINE_IID-$CI_COMMIT_SHORT_SHA | string | |
| image | Cypress image to use for running the Cypress tests. | registry.gitlab.com/xrow-public/library/cypress/included:15.21.1 | string |
| name | review:cypress | string | |
| needs | Jobs that the start job depends on. | [] | array |
| no-proxy | Comma-separated list of hosts to exclude from proxying. | string | |
| options | --headless | string | |
| path | Path in the repository to the Cypress tests. | tests/e2e | string |
| proxy | Proxy to use for the tests. | string | |
| record-key | string | ||
| review-domain | Domain to be tested (create it with the review component). | $CI_ENVIRONMENT_SLUG.review.xrow.net | string |
| rules | The rules to determine when to run the job. | [{"if":"$CI_PIPELINE_SOURCE == \"schedule\"","when":"never"},{"if":"$CI_COMMIT_TAG =~ $CI_PATTERN_SEMVER","when":"never"},{"if":"$CI_PIPELINE_SOURCE == \"merge_request_event\"","when":"on_success"},{"if":"$CI_COMMIT_REF_SLUG =~ $CI_DEFAULT_BRANCH","when":"on_success"},{"when":"never"}] | array |
| services | Additional services to run alongside the tests. Like a proxy. | [] | array |
| stage | test | string | |
| tag | string | ||
| test-context | string |