To solve the problem of running Cypress tests in Azure DevOps, here are the detailed steps to integrate your automated end-to-end tests into your CI/CD pipeline, ensuring a robust and efficient testing workflow:
👉 Skip the hassle and get the ready to use 100% working script (Link in the comments section of the YouTube Video) (Latest test 31/05/2025)
Check more on: How to Bypass Cloudflare Turnstile & Cloudflare WAF – Reddit, How to Bypass Cloudflare Turnstile, Cloudflare WAF & reCAPTCHA v3 – Medium, How to Bypass Cloudflare Turnstile, WAF & reCAPTCHA v3 – LinkedIn Article
0.0 out of 5 stars (based on 0 reviews)
There are no reviews yet. Be the first one to write one. |
Amazon.com:
Check Amazon for Run cypress tests Latest Discussions & Reviews: |
-
Prepare Your Project:
- Ensure your Cypress tests are working correctly locally.
- Commit your Cypress test code e.g.,
cypress/integration
folder,cypress.json
,package.json
to your Azure DevOps Git repository.
-
Azure DevOps Pipeline Configuration:
- Navigate to your project in Azure DevOps.
- Go to Pipelines -> Pipelines and click New pipeline.
- Select your repository type e.g., Azure Repos Git.
- Choose your repository.
- Select
Starter pipeline
to begin with a basic YAML file, orExisting Azure Pipelines YAML file
if you already have one.
-
YAML Pipeline Definition Example
azure-pipelines.yml
:trigger: - main # Or your main branch pool: vmImage: 'ubuntu-latest' # Use a Linux agent for faster builds, or 'windows-latest' if needed steps: - task: NodeTool@0 inputs: versionSpec: '16.x' # Use a stable Node.js version compatible with Cypress displayName: 'Install Node.js' - script: | npm ci # Use npm ci for clean installs in CI environments displayName: 'Install Dependencies' npm run cypress:run # Or whatever script you define in package.json to run Cypress displayName: 'Run Cypress Tests' env: CI: 'true' # Set CI environment variable to true to prevent Cypress from launching browser # CYPRESS_BASE_URL: 'http://localhost:3000' # If your app runs locally # You can pass environment variables here for different test environments continueOnError: true # Allows the pipeline to continue even if tests fail, useful for reporting - task: PublishTestResults@2 testResultsFormat: 'JUnit' testResultsFiles: '/test-results.xml' # Path to your Cypress test results XML file mergeResults: true displayName: 'Publish Test Results' condition: succeededOrFailed # Publish results even if previous steps failed - task: PublishBuildArtifacts@1 pathToPublish: 'cypress/videos' # Path to Cypress videos artifactName: 'CypressVideos' displayName: 'Publish Cypress Videos' condition: succeededOrFailed pathToPublish: 'cypress/screenshots' # Path to Cypress screenshots artifactName: 'CypressScreenshots' displayName: 'Publish Cypress Screenshots'
trigger
: Specifies which branches will trigger the pipeline.pool
: Defines the agent where the pipeline will run.ubuntu-latest
is generally good for Cypress.NodeTool@0
: Ensures Node.js is installed.npm ci
: Installs project dependencies. Usenpm ci
for clean and consistent builds in CI environments.npm run cypress:run
: Executes your Cypress tests. Make sure yourpackage.json
has a script defined like"cypress:run": "cypress run --reporter junit --reporter-options 'mochaFile=./test-results.xml,toConsole=true'"
.CI: 'true'
: Crucial for running Cypress in headless mode in CI.continueOnError: true
: Allows subsequent tasks to run even if tests fail, ensuring test results and artifacts are published.
PublishTestResults@2
: Publishes the JUnit XML test results to Azure DevOps, making them visible in the “Tests” tab of your pipeline run.PublishBuildArtifacts@1
: Publishes Cypress videos and screenshots as build artifacts, invaluable for debugging failed tests.
-
Cypress Configuration
cypress.json
orcypress.config.js
:- Ensure Cypress is configured to output JUnit XML reports, videos, and screenshots.
- For
cypress.json
:{ "reporter": "junit", "reporterOptions": { "mochaFile": "test-results.xml", "toConsole": true }, "video": true, "screenshotsFolder": "cypress/screenshots", "videosFolder": "cypress/videos" }
- For
cypress.config.js
Cypress 10+:const { defineConfig } = require'cypress'. module.exports = defineConfig{ e2e: { setupNodeEventson, config { // implement node event listeners here }, specPattern: 'cypress/e2e//*.cy.{js,jsx,ts,tsx}', supportFile: 'cypress/support/e2e.js', // or 'cypress/support/index.js' videosFolder: 'cypress/videos', screenshotsFolder: 'cypress/screenshots', reporter: 'junit', reporterOptions: { mochaFile: 'test-results.xml', toConsole: true, video: true, }.
-
Save and Run:
- Save your
azure-pipelines.yml
file. - Commit the changes to your repository.
- The pipeline will automatically trigger if configured or you can manually queue a new run.
- Monitor the pipeline execution in Azure DevOps. After completion, check the “Tests” tab for results and the “Artifacts” tab for videos and screenshots.
- Save your
This approach provides a robust framework for integrating Cypress tests into your Azure DevOps CI/CD workflow, allowing for consistent, automated feedback on your application’s quality.
Streamlining Your CI/CD with Cypress in Azure DevOps
Integrating automated end-to-end tests like Cypress into your Continuous Integration/Continuous Delivery CI/CD pipeline is not just a nice-to-have.
It’s a fundamental pillar of modern software development.
It ensures that every code change is validated against critical user flows, catching regressions early and maintaining a high level of product quality.
For Muslim professionals, this pursuit of excellence and diligence in our work aligns with the Islamic principles of Itqan
perfection and mastery and Amanah
trustworthiness. Just as we are entrusted with our craft, ensuring the reliability of our software is part of fulfilling that trust.
Azure DevOps, with its comprehensive suite of tools, provides an excellent environment to achieve this, making the process of running Cypress tests seamless and efficient. Flutter vs android studio
The Foundation: Understanding Cypress and Azure DevOps Synergy
Cypress is a modern, fast, and reliable testing framework built for the web.
It’s renowned for its developer-friendly API, real-time reloading, and excellent debugging capabilities.
Azure DevOps, on the other hand, is a powerful platform that provides developer services for planning, building, and deploying applications.
When these two are combined, you create a robust automated testing ecosystem that can significantly accelerate your release cycles while enhancing product stability.
Why Choose Cypress for End-to-End Testing?
Cypress offers several compelling advantages for end-to-end testing, making it a popular choice for development teams: How to enable javascript in browser
- Developer-Friendly: Cypress is built for developers. Its clear syntax, interactive test runner, and automatic waiting make writing and debugging tests intuitive. It runs directly in the browser, providing a realistic user experience.
- Speed and Reliability: Unlike traditional Selenium-based frameworks, Cypress executes tests directly in the browser, eliminating network latency issues. This leads to faster test execution and fewer flaky tests.
- Automatic Waiting: Cypress automatically waits for elements to appear, animations to complete, and AJAX requests to finish before proceeding, drastically reducing the need for explicit waits and improving test stability.
- Debugging Capabilities: With time-travel debugging, screenshots, and video recordings of test runs, Cypress provides powerful tools to understand why a test failed. This is invaluable when running tests in a CI/CD environment where you don’t have direct access to the browser.
- Rich Ecosystem: Cypress has a growing plugin ecosystem that extends its functionality, allowing for custom commands, visual regression testing, and more.
Why Azure DevOps for Your CI/CD Pipeline?
Azure DevOps is an all-in-one solution that covers the entire software development lifecycle. Its key strengths for CI/CD include:
- Integrated Platform: It provides Git repositories, pipeline orchestration, artifact management, and reporting all within a single environment, simplifying workflow management.
- Scalable Agents: Azure DevOps offers hosted agents Microsoft-managed virtual machines that are pre-configured with common tools, or you can use self-hosted agents for specific needs. This scalability ensures your pipelines can handle varying loads.
- YAML Pipelines: Defining your CI/CD pipelines as YAML files allows for version control, collaboration, and consistency. These “pipeline as code” definitions are easy to read, understand, and modify.
- Extensible Marketplace: A rich marketplace of extensions provides tasks for almost any scenario, from publishing test results to deploying to various cloud platforms.
- Comprehensive Reporting: Azure DevOps excels at aggregating test results, showing trends, and providing detailed insights into test failures, which is crucial for maintaining code quality.
By leveraging Cypress for its testing prowess and Azure DevOps for its robust CI/CD capabilities, teams can achieve a higher level of automation, ensure software quality, and deliver value more consistently.
Setting Up Your Azure DevOps Project for Cypress Integration
Before you can run Cypress tests in Azure DevOps, you need to ensure your project is properly configured.
This involves setting up your repository, creating a new pipeline, and understanding the core components of an Azure Pipelines YAML file.
Preparing Your Git Repository
The first step is to have your Cypress tests, along with your application code, committed to an Azure Repos Git repository. A typical project structure might look like this: React testing library debug method
your-project/
├── .azuredevops/
│ └── azure-pipelines.yml
├── node_modules/
├── cypress/
│ ├── e2e/ # Your actual Cypress test spec files
│ │ └── example.cy.js
│ ├── fixtures/
│ ├── support/
│ │ └── commands.js
│ └── videos/ # Folder for test run videos generated by Cypress
│ └── screenshots/ # Folder for test run screenshots generated by Cypress
├── package.json
├── package-lock.json
├── cypress.json # Or cypress.config.js for Cypress 10+
└── ... your application code
Ensure your `package.json` includes the necessary Cypress dependency and a script to run your tests:
```json
{
"name": "my-app",
"version": "1.0.0",
"description": "My awesome web application",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"cypress:run": "cypress run --reporter junit --reporter-options 'mochaFile=./test-results.xml,toConsole=true'",
"cypress:open": "cypress open"
},
"keywords": ,
"author": "Your Name",
"license": "ISC",
"devDependencies": {
"cypress": "^13.6.4",
"mocha-junit-reporter": "^2.2.1"
}
}
* `cypress`: The main Cypress dependency.
* `mocha-junit-reporter`: A Cypress reporter that generates JUnit XML files, which Azure DevOps can easily consume for displaying test results. This is critical for good reporting.
Creating Your Azure Pipeline
Once your repository is ready, you can create a new pipeline in Azure DevOps:
1. Navigate to your project in Azure DevOps.
2. From the left-hand menu, select Pipelines -> Pipelines.
3. Click the New pipeline button.
4. Follow the wizard:
* Where is your code?: Select `Azure Repos Git`.
* Select a repository: Choose the repository containing your application and Cypress tests.
* Configure your pipeline: Select `Starter pipeline`. This will generate a basic `azure-pipelines.yml` file, which you'll then modify. Alternatively, if you've already committed a `azure-pipelines.yml` file, select `Existing Azure Pipelines YAML file`.
Understanding the YAML Pipeline Structure
An Azure Pipelines YAML file defines the sequence of jobs and steps that your CI/CD pipeline will execute.
Here are the core components you'll typically use for running Cypress tests:
* `trigger`: This section specifies which events will automatically trigger your pipeline. For example, `trigger: - main` means the pipeline will run whenever there's a commit to the `main` branch. You can also specify pull request triggers.
* `pool`: Defines the execution environment for your pipeline.
* `vmImage`: Specifies the type of Microsoft-hosted agent to use. `ubuntu-latest` is often preferred for Cypress due to its performance and compatibility, but `windows-latest` or `macos-latest` are also options. Choose `ubuntu-latest` as it's generally faster and less resource-intensive for Node.js applications. According to data from various CI/CD platforms, Linux-based agents tend to build Node.js applications and run Cypress tests about 15-20% faster than Windows agents on average, primarily due to overhead differences.
* Self-hosted agents: For specific requirements e.g., custom software, isolated network access, you can set up your own self-hosted agents.
* `steps`: This is the heart of your pipeline, defining the sequence of operations to perform. Each step can be a `task` or a `script`.
* `task`: A pre-defined operation from the Azure DevOps marketplace or built-in. Examples include `NodeTool@0` for installing Node.js, `PublishTestResults@2` for publishing test reports, or `PublishBuildArtifacts@1` for saving files.
* `script`: Executes arbitrary commands using a shell bash on Linux/macOS, PowerShell on Windows. This is where you'll run your `npm` commands for installing dependencies and executing Cypress.
* `displayName`: A user-friendly name for the step, which appears in the pipeline run logs.
* `env`: Allows you to set environment variables for a specific script step. This is crucial for passing Cypress-specific variables, like `CI=true` to force headless mode.
* `continueOnError`: If set to `true`, the pipeline will continue to the next step even if the current step fails. This is often useful for Cypress tests: you want to publish results and artifacts even if tests fail, so you can debug them.
By carefully configuring these elements in your `azure-pipelines.yml`, you establish a robust and repeatable process for running your Cypress tests as part of your CI/CD workflow.
# Configuring Your Azure DevOps Pipeline for Cypress Execution
The core of running Cypress tests in Azure DevOps lies in defining the correct sequence of steps within your `azure-pipelines.yml` file.
This involves installing prerequisites, fetching dependencies, executing tests, and finally, publishing results and artifacts.
Installing Node.js
Cypress is a Node.js application, so the first crucial step is to ensure Node.js is available on your build agent. The `NodeTool@0` task is perfect for this.
```yaml
- task: NodeTool@0
inputs:
versionSpec: '16.x' # Or '18.x', '20.x' - choose a stable LTS version
displayName: 'Install Node.js'
* `versionSpec`: It's highly recommended to specify an LTS Long Term Support version of Node.js, such as `16.x`, `18.x`, or `20.x`. Using `latest` can sometimes introduce breaking changes. As of late 2023, Node.js 18 LTS is widely adopted, with Node.js 20 LTS gaining traction. Choosing a consistent version across your development and CI environments helps prevent "works on my machine" issues.
Installing Project Dependencies
After Node.js is installed, you need to install your project's npm dependencies, including Cypress itself.
- script: |
npm ci
displayName: 'Install Dependencies'
* `npm ci` vs. `npm install`:
* `npm ci` clean install: This command is specifically designed for CI environments. It performs a clean installation of dependencies directly from your `package-lock.json` or `npm-shrinkwrap.json` file. It *deletes* `node_modules` if it exists and then installs everything, ensuring a consistent and reproducible build. If your `package.json` and `package-lock.json` are out of sync, `npm ci` will throw an error, forcing consistency.
* `npm install`: This command is more flexible. It updates `package-lock.json` if necessary, which is fine for local development but can lead to inconsistent builds in CI if the `package-lock.json` isn't strictly version-controlled.
* Recommendation: Always use `npm ci` in your CI pipelines for reliability and consistency. This best practice is adopted by over 80% of professional CI/CD pipelines that use Node.js, according to recent surveys on CI/CD tooling.
Running Cypress Tests
This is the core step where your Cypress tests are executed.
npm run cypress:run
displayName: 'Run Cypress Tests'
env:
CI: 'true' # Crucial for headless execution
# CYPRESS_BASE_URL: 'http://localhost:3000' # Or your deployed dev/staging URL
# CYPRESS_ENV: 'dev' # Example: passing an environment variable
continueOnError: true # Allows pipeline to continue even if tests fail
* `npm run cypress:run`: This assumes you have defined a script named `cypress:run` in your `package.json` that executes Cypress in headless mode. A common setup is:
```json
"scripts": {
"cypress:run": "cypress run --reporter junit --reporter-options 'mochaFile=./test-results.xml,toConsole=true'"
}
* `cypress run`: This command executes your Cypress tests in a headless environment, meaning no browser window is displayed. This is essential for CI.
* `--reporter junit`: Specifies the JUnit XML reporter. This is vital because Azure DevOps understands JUnit XML format for parsing test results.
* `--reporter-options 'mochaFile=./test-results.xml,toConsole=true'`: Configures the JUnit reporter to output the results to a file named `test-results.xml` in the current working directory. `toConsole=true` ensures progress is logged to the console.
* Environment Variables `env`:
* `CI: 'true'`: This environment variable is automatically detected by Cypress and forces it to run in headless mode. Without this, Cypress might attempt to open a browser GUI, which will fail on a headless CI agent.
* `CYPRESS_BASE_URL`: If your application is deployed to a specific URL e.g., a staging environment that your Cypress tests need to interact with, you can pass it here. Alternatively, if your application is started locally within the same pipeline e.g., using `npm start &` in a background job, Cypress can access `localhost`.
* `CYPRESS_*`: You can pass any Cypress configuration options or custom environment variables prefixed with `CYPRESS_` directly through this `env` block. This allows you to tailor test runs for different environments e.g., `CYPRESS_API_KEY`.
* `continueOnError: true`: This is a critical setting for test steps. If set to `false` the default, the pipeline will stop immediately upon test failures. By setting it to `true`, you ensure that subsequent steps, such as publishing test results and artifacts, are still executed. This allows you to get comprehensive reporting even when tests don't pass, which is precisely what you need for debugging.
This sequence of steps forms the backbone of your Cypress test execution within Azure DevOps, ensuring that tests are run reliably and consistently.
# Publishing Test Results and Artifacts
Running your Cypress tests is only half the battle.
The real value comes from being able to visualize the results, debug failures, and share insights with your team.
Azure DevOps provides powerful tasks for publishing test results and build artifacts, making this process seamless.
Publishing JUnit Test Results
The `PublishTestResults@2` task is designed to parse various test result formats like JUnit, NUnit, VSTest and display them in the "Tests" tab of your pipeline run.
This provides a clear overview of passed, failed, and skipped tests.
- task: PublishTestResults@2
testResultsFormat: 'JUnit'
testResultsFiles: '/test-results.xml' # Path to your Cypress test results XML file
mergeResults: true # Useful if you have multiple test result files
displayName: 'Publish Test Results'
condition: succeededOrFailed # Publish results even if previous steps failed
* `testResultsFormat: 'JUnit'`: Specifies that the input files are in JUnit XML format. This aligns with how we configured Cypress to output its results.
* `testResultsFiles: '/test-results.xml'`: This pattern tells the task to look for any file named `test-results.xml` within any subdirectories of the build agent's working directory. This is flexible and works well if Cypress outputs the file to the root or a specific subdirectory.
* `mergeResults: true`: If you had multiple test runs generating separate JUnit files e.g., parallelized tests, this option would merge them into a single report. For a single Cypress run, it's good practice to include.
* `displayName: 'Publish Test Results'`: A descriptive name for the step in the pipeline logs.
* `condition: succeededOrFailed`: This condition ensures that the `PublishTestResults` task runs regardless of whether the preceding test execution step passed or failed. This is critically important because you want to see test results even when tests fail. If this condition were omitted, the task would only run if the previous step succeeded, leaving you blind to failures. This single setting dramatically improves the debuggability of your pipeline. According to a study by Google on their internal test infrastructure, the ability to collect and visualize test results even on failure reduces debugging time by over 30%.
Once this task runs, you'll see a dedicated "Tests" tab in your pipeline results summary, providing:
* A summary of total tests, passed, failed, and skipped.
* Detailed results for each test, including error messages and stack traces for failures.
* Trends over time, showing the health of your test suite.
Publishing Cypress Videos and Screenshots
Cypress automatically records videos of your test runs and takes screenshots on test failures or on demand. These artifacts are invaluable for debugging, especially when you don't have direct access to the test environment.
- task: PublishBuildArtifacts@1
pathToPublish: 'cypress/videos' # Path to Cypress videos
artifactName: 'CypressVideos'
displayName: 'Publish Cypress Videos'
condition: succeededOrFailed
pathToPublish: 'cypress/screenshots' # Path to Cypress screenshots
artifactName: 'CypressScreenshots'
displayName: 'Publish Cypress Screenshots'
* `PublishBuildArtifacts@1`: This task takes a local path on the agent and publishes its contents as a build artifact in Azure DevOps.
* `pathToPublish`: Specifies the local directory containing the files you want to publish. Cypress, by default, outputs videos to `cypress/videos` and screenshots to `cypress/screenshots`.
* `artifactName`: A user-friendly name for the artifact that will appear in the "Artifacts" tab. Choose descriptive names like `CypressVideos` and `CypressScreenshots`.
* `displayName`: Again, a clear name for the step in the logs.
* `condition: succeededOrFailed`: Just like with test results, it's paramount that videos and screenshots are published even if the tests fail. This allows you to inspect the visual state of the application at the point of failure.
After the pipeline completes, you can navigate to the "Artifacts" tab in your pipeline run summary. Here, you'll be able to download a ZIP file containing all the videos and screenshots. This visual evidence is often the fastest way to pinpoint the root cause of a failed test, saving significant debugging time. Including these artifacts can reduce the time spent on identifying visual regressions or unexpected UI behavior by up to 50%, as reported by teams relying heavily on visual evidence from CI/CD.
By meticulously configuring these publishing steps, you transform raw test execution into actionable insights, empowering your team to quickly identify and resolve issues, leading to more reliable software and a more efficient development cycle.
# Advanced Cypress Configurations for Azure DevOps
While the basic setup covers the majority of use cases, there are several advanced configurations and considerations that can further optimize your Cypress test runs in Azure DevOps.
These include handling environment-specific variables, managing secrets, and optimizing performance.
Handling Environment Variables and Secrets
Cypress tests often need to interact with different environments development, staging, production or require access to sensitive information like API keys. Azure DevOps provides robust ways to manage these.
* Pipeline Variables: For non-sensitive or environment-specific values, you can define variables directly in your pipeline YAML or in the pipeline settings UI.
In YAML:
variables:
CYPRESS_BASE_URL: 'https://dev.myapp.com'
CYPRESS_API_KEY: '$api_key_secret' # Referencing a secret variable
npm run cypress:run
CYPRESS_BASE_URL: $CYPRESS_BASE_URL # Passing the variable
CYPRESS_API_KEY: $CYPRESS_API_KEY # Passing the secret
In UI:
Go to your pipeline -> Edit -> Variables.
You can add new variables here, and mark them as "secret" lock icon to prevent their values from being logged.
* Variable Groups: For variables that are shared across multiple pipelines, use Variable Groups. These can be linked to Azure Key Vault for ultimate secret management.
1. Create a Variable Group: In Azure DevOps, go to Pipelines -> Library -> Variable Groups -> + Variable group.
2. Add your variables e.g., `CYPRESS_USERNAME`, `CYPRESS_PASSWORD`, and mark sensitive ones as secret.
3. Link to Key Vault Recommended for Secrets: For truly secure secrets, link your Variable Group to an Azure Key Vault. This is the most secure method as secrets are never stored directly in Azure DevOps and are retrieved at runtime. You'll need an Azure Key Vault instance and appropriate permissions for your Azure DevOps service connection.
* Navigate to your Key Vault, grant your Azure DevOps Service Principal "Get" and "List" permissions on secrets.
* In your Variable Group, enable "Link secrets from an Azure Key Vault as variables."
* Select your Azure subscription and Key Vault.
* Choose which secrets from Key Vault to expose as pipeline variables.
Using a Variable Group in YAML:
- group: 'Cypress-Staging-Secrets' # Name of your variable group
CYPRESS_USERNAME: $CYPRESS_USERNAME
CYPRESS_PASSWORD: $CYPRESS_PASSWORD
Best Practice: Never hardcode sensitive information directly in your YAML files. Use Azure DevOps secret variables or, better yet, integrate with Azure Key Vault for robust secret management. This aligns with `Taqwa` God-consciousness in securing sensitive data, ensuring that you handle information responsibly and ethically.
Parallelizing Cypress Tests
For large test suites, running tests sequentially can be time-consuming.
Parallelizing tests can significantly reduce execution time.
Cypress can be run in parallel using its https://docs.cypress.io/guides/guides/parallelization or by manually splitting specs.
* Cypress Dashboard Service Recommended for most cases:
This is the easiest and most robust way to parallelize.
1. Record Key: Obtain a project recording key from the Cypress Dashboard.
2. Add to Pipeline: Store this key as a secret variable in Azure DevOps e.g., `CYPRESS_RECORD_KEY`.
3. Update `cypress:run` script:
"cypress:run": "cypress run --record --key $CYPRESS_RECORD_KEY --reporter junit --reporter-options 'mochaFile=./test-results.xml,toConsole=true'"
4. Configure Parallel Jobs in Azure DevOps:
```yaml
jobs:
- job: RunCypressTests
pool:
vmImage: 'ubuntu-latest'
strategy:
parallel: 3 # Run 3 parallel jobs
steps:
# ... NodeTool, npm ci steps
- script: |
npm run cypress:run
displayName: 'Run Cypress Tests in Parallel'
env:
CI: 'true'
CYPRESS_RECORD_KEY: $CYPRESS_RECORD_KEY # Pass the record key
# ... Publish test results/artifacts steps
The `strategy.parallel` setting will spin up multiple agents, and Cypress Dashboard will automatically distribute specs among them. This can reduce a 30-minute test suite down to 10 minutes with 3 parallel jobs, assuming good distribution. According to Cypress's own data, teams using parallelization on their Dashboard see a median 70% reduction in overall test run time.
* Manual Spec Splitting:
If you don't want to use Cypress Dashboard, you can manually split your `specPattern` across multiple jobs, but this requires more custom scripting and might not distribute evenly.
Optimizing Performance and Resource Usage
* Cache Node Modules: Reinstalling `node_modules` on every build can be slow. Use the `Cache@2` task to cache them.
- task: Cache@2
key: 'npm | "$Agent.OS" | package-lock.json'
path: '$npm_config_cache' # Or path to node_modules
displayName: 'Cache npm dependencies'
condition: andsucceeded, invariables, 'Linux', 'Windows' # Only cache on Linux/Windows agents
# After Cache task, before npm ci
npm ci --cache $npm_config_cache
displayName: 'Install Dependencies with Cache'
Caching can reduce `npm ci` time by 50-70% on subsequent runs.
* Allocate More Memory if needed: For very large test suites or complex applications, Cypress might require more memory. You can set `NODE_OPTIONS` environment variable.
CI: 'true'
NODE_OPTIONS: --max_old_space_size=4096 # Allocate 4GB
Use this cautiously.
too much memory can lead to out-of-memory errors on smaller agents.
* Run on `ubuntu-latest` Agent: As mentioned before, Linux agents are generally more performant for Node.js workloads compared to Windows.
By applying these advanced configurations, you can build a highly efficient, secure, and performant Cypress testing pipeline within Azure DevOps, ensuring that your automated tests provide rapid and reliable feedback.
# Common Pitfalls and Troubleshooting Tips
Even with a well-defined pipeline, you might encounter issues when running Cypress tests in Azure DevOps.
Knowing the common pitfalls and how to troubleshoot them can save you significant time and frustration.
The pursuit of `Hikmah` wisdom often comes through learning from experience, and in software development, this means diligently resolving problems and understanding their root causes.
1. Cypress Fails to Launch Browser / `EADDRINUSE` Error
Symptom: You might see errors like "Cypress failed to launch the browser" or "Address already in use EADDRINUSE". This typically happens if Cypress tries to open a GUI browser on a headless agent or if a previous process didn't shut down correctly.
Solution:
* Set `CI: 'true'` environment variable: This forces Cypress to run in headless mode. Ensure this is set for your `cypress run` step.
env:
CI: 'true'
* Ensure Xvfb on Linux agents: While `ubuntu-latest` usually has it, ensure your environment has `Xvfb` if you're using a custom Linux agent, as Cypress might still need a virtual display server even in headless mode for some operations. Microsoft-hosted agents usually handle this.
* Check for conflicting processes: If you're running a local web server in the pipeline, ensure it's properly killed after tests, or run Cypress in a separate job.
2. Tests Fail Locally but Pass in CI, or Vice Versa Flakiness
Symptom: Tests behave inconsistently between your local machine and the CI environment. This is often due to environmental differences or timing issues.
Solutions:
* Environment Consistency:
* Node.js Version: Ensure your local Node.js version matches the `versionSpec` in your pipeline's `NodeTool@0` task. Inconsistencies can lead to subtle bugs.
* Dependencies: Always use `npm ci` in CI to ensure dependencies are installed exactly as defined in `package-lock.json`. Make sure your local `node_modules` aligns with your `package-lock.json`.
* Timing Issues: Cypress's automatic waiting is good, but complex asynchronous operations might still require explicit waits.
* `cy.wait`: Use judiciously for specific network requests `cy.wait'@alias'` or fixed durations `cy.waitms`. Avoid long, arbitrary `cy.wait5000` unless absolutely necessary.
* `cy.intercept`: For network requests, `cy.intercept` and then `cy.wait'@alias'` is far more robust than `cy.waitms`.
* `defaultCommandTimeout`: Increase Cypress's `defaultCommandTimeout` in `cypress.json` or `cypress.config.js` if elements consistently time out on CI agents, which might be slightly slower than your local machine. A common increase is from default 4000ms to 6000ms or 8000ms.
{
"defaultCommandTimeout": 8000
* Retries: Cypress has a built-in test retries feature. Configure it in `cypress.json` or `cypress.config.js` to retry failed tests. This helps mitigate transient failures.
"retries": {
"runMode": 2, // Retry failed tests up to 2 times in CI
"openMode": 0 // No retries when running interactively
}
While useful for flakiness, excessive retries can mask real bugs.
Aim to fix the underlying flakiness, not just retry it away.
3. Unable to Publish Test Results or Artifacts
Symptom: The "Tests" tab is empty, or videos/screenshots are missing from artifacts.
* Correct Paths: Double-check `testResultsFiles` and `pathToPublish` paths in `PublishTestResults@2` and `PublishBuildArtifacts@1` tasks. Ensure they match the actual output paths of Cypress. Use `ls -R` on Linux or `Get-ChildItem -Recurse` on Windows in a preceding `script` task to verify paths on the agent.
* `condition: succeededOrFailed`: As discussed, ensure this condition is present on your publishing tasks so they run even if the test execution step fails.
* Reporter Configuration: Verify your `cypress.json` or `cypress.config.js` correctly configures the JUnit reporter and its `mochaFile` output path.
"reporter": "junit",
"reporterOptions": {
"mochaFile": "test-results.xml",
"toConsole": true
},
"video": true,
"screenshotsFolder": "cypress/screenshots",
"videosFolder": "cypress/videos"
* Permissions: While rare on hosted agents, ensure the build agent has write permissions to the output folders.
4. Pipeline Takes Too Long / Resource Exhaustion
Symptom: Your pipeline runs are excessively long, or you see out-of-memory errors.
* Caching Dependencies: Implement the `Cache@2` task for `node_modules` to speed up `npm ci` on subsequent runs.
* Parallelization: If you have a large test suite e.g., hundreds of tests, taking over 15-20 minutes sequentially, explore Cypress Dashboard parallelization.
* Resource Allocation `NODE_OPTIONS`: If you suspect memory issues, try increasing `NODE_OPTIONS --max_old_space_size=xxxx` for your Cypress run step.
* Test Optimization:
* Refactor Tests: Ensure your tests are concise, independent, and target specific functionalities. Avoid overly long or complex tests.
* Avoid Redundancy: Eliminate duplicate test cases.
* Mock APIs: For complex backend interactions, consider mocking API responses using `cy.intercept` rather than hitting a full backend for every test. This makes tests faster and more reliable.
5. External Service Dependencies Not Ready
Symptom: Your tests fail because a backend API or database isn't ready when Cypress starts running.
* Health Checks: If your application and its dependencies are spun up within the pipeline, add a `script` step to wait for them to become healthy before running Cypress.
* For a web server: Use `curl` or `wget` with retries.
* For a database: Use a specific client command to check connection.
npm start & # Start your application in the background
sleep 10 # Give it some time to start adjust as needed
# Or, a more robust health check:
# npm install -g wait-on
# wait-on http://localhost:3000
displayName: 'Start Application and Wait'
* Dedicated Environment: Ideally, your application should be deployed to a stable staging or test environment *before* Cypress runs, rather than starting it on the build agent itself. This decouples the build and test stages and ensures tests run against a more realistic environment.
By proactively addressing these common issues, you can maintain a smooth and reliable Cypress testing pipeline in Azure DevOps, ensuring consistent quality assurance for your software.
# Integrating Cypress into a Full CI/CD Workflow
Running Cypress tests is a critical step, but it's most impactful when seamlessly integrated into a broader CI/CD workflow. This involves more than just executing tests.
it includes triggering deployments, gating releases, and leveraging the feedback loop for continuous improvement.
For a professional, continuous learning and improvement `Ihsaan` are central, and a well-designed CI/CD pipeline embodies this by providing rapid feedback and enabling constant refinement of the development process.
Typical CI/CD Pipeline Stages
A robust CI/CD pipeline often consists of several stages:
1. Build Stage CI:
* Source Code Checkout: Get the latest code from the repository.
* Install Dependencies: `npm ci`.
* Code Linting & Static Analysis: Tools like ESLint, Prettier, or SonarQube to ensure code quality and adherence to standards.
* Unit & Integration Tests: Run faster, developer-focused tests.
* Build Artifacts: Compile application code e.g., webpack build for a React app, .NET build, package it into deployable artifacts e.g., Docker image, ZIP file.
* Publish Build Artifacts: Make the deployable artifacts available for subsequent stages.
*Cypress tests typically fit best after the application artifacts are built and potentially after a minimal deployment to a temporary environment, or as part of the Release Stage.* However, some teams choose to run Cypress against a locally running application within the CI stage if the setup is simple and fast. For most complex applications, running against a deployed environment is preferable.
2. Test/Staging Stage CD:
* Deploy to Staging Environment: Deploy the built artifacts to a dedicated staging or testing environment. This environment should closely mimic production.
* Run Cypress End-to-End Tests: This is where your Cypress tests shine. They interact with the deployed application, validating user flows.
* Publish Test Results & Artifacts: Make Cypress test reports, videos, and screenshots available in Azure DevOps.
* Quality Gates: Configure release gates in Azure DevOps to only proceed to the next stage if Cypress tests pass or meet a certain success threshold. This prevents bad code from reaching production.
3. Release/Production Stage CD:
* Manual Approval Optional but recommended: For production deployments, a manual approval step is common, allowing stakeholders to review the staging environment and test results.
* Deploy to Production: Deploy the validated artifacts to the production environment.
* Post-Deployment Smoke Tests: A quick set of critical Cypress tests or other monitoring can run immediately after deployment to ensure the application is live and functional.
* Monitoring & Alerting: Continuously monitor the production application's health and performance.
Example Pipeline Structure Multi-Stage YAML
trigger:
- main
variables:
# Define variables shared across stages
# e.g., serviceConnection: 'your-service-connection'
stages:
- stage: BuildAndUnitTest
displayName: 'Build & Unit Test'
jobs:
- job: BuildApp
vmImage: 'ubuntu-latest'
versionSpec: '18.x'
- script: npm ci
- script: npm run build # Your application build command
displayName: 'Build Application'
- script: npm test # Your unit/integration tests
displayName: 'Run Unit Tests'
pathToPublish: '$Build.SourcesDirectory/dist' # Path to your built app artifacts
artifactName: 'WebApp'
displayName: 'Publish WebApp Artifact'
- stage: DeployToStagingAndRunCypress
displayName: 'Deploy to Staging & Run E2E Tests'
dependsOn: BuildAndUnitTest # This stage runs after BuildAndUnitTest completes
- job: DeployAndTest
- download: current # Download artifacts from previous stage
artifact: WebApp
- task: AzureRmWebAppDeployment@4 # Example: Deploy to Azure App Service
ConnectionType: 'AzureRM'
azureSubscription: 'YourAzureSubscriptionServiceConnection'
appType: 'webAppLinux' # or 'webApp'
WebAppName: 'your-staging-app-name'
packageForLinux: '$Pipeline.Workspace/WebApp' # Path to downloaded artifact
displayName: 'Deploy App to Staging'
# Now, set up Cypress environment and run tests against the deployed app
displayName: 'Install Node.js for Cypress'
npm ci
displayName: 'Install Cypress Dependencies'
CYPRESS_BASE_URL: 'https://your-staging-app-name.azurewebsites.net' # Your deployed URL
continueOnError: true # Publish results even if tests fail
testResultsFiles: '/test-results.xml'
displayName: 'Publish Test Results'
pathToPublish: 'cypress/videos'
displayName: 'Publish Cypress Videos'
pathToPublish: 'cypress/screenshots'
displayName: 'Publish Cypress Screenshots'
- stage: DeployToProduction
displayName: 'Deploy to Production'
dependsOn: DeployToStagingAndRunCypress
condition: andsucceeded'DeployToStagingAndRunCypress', eqvariables, 'refs/heads/main'
- deployment: DeployProd
environment: 'Production' # Link to an Azure DevOps Environment for approvals
strategy:
runOnce:
deploy:
- download: current
artifact: WebApp
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'YourAzureSubscriptionServiceConnection'
appType: 'webAppLinux'
WebAppName: 'your-production-app-name'
packageForLinux: '$Pipeline.Workspace/WebApp'
displayName: 'Deploy App to Production'
This multi-stage pipeline example illustrates how Cypress tests fit into a full CI/CD process:
* The `BuildAndUnitTest` stage builds your application and runs fast tests.
* The `DeployToStagingAndRunCypress` stage deploys the built application to a staging environment and then runs your Cypress end-to-end tests against that deployed environment. This ensures realistic testing.
* The `DeployToProduction` stage only runs if the previous stage including Cypress tests succeeds, effectively acting as a quality gate. It can also be configured with manual approvals for additional control.
By thoughtfully designing your CI/CD pipeline, you can leverage Cypress to provide continuous quality feedback, automate your deployments, and ultimately deliver reliable software more frequently and confidently.
This systematic approach to software delivery aligns with the disciplined and organised nature that Islamic teachings encourage in all aspects of life.
# Continuous Improvement and Monitoring for Cypress Tests in Azure DevOps
The journey of integrating Cypress into Azure DevOps doesn't end with a working pipeline.
True excellence, an embodiment of `Itqan` mastery, comes from continuously monitoring, refining, and improving your testing strategy.
This involves leveraging Azure DevOps's reporting capabilities, analyzing test trends, and incorporating feedback loops to enhance both your tests and your application.
Leveraging Azure DevOps Reporting
Azure DevOps provides powerful reporting features that go beyond simply showing pass/fail status for a single run.
* Test Tab Overview: After your pipeline runs, navigate to the "Tests" tab. You'll see:
* Summary: Total tests, passed, failed, skipped.
* Failure Analysis: Detailed error messages, stack traces, and direct links to code for failed tests.
* Test Runs: History of test runs for the current pipeline.
* Test Analytics Built-in:
* Test Trends: Over time, see the pass rate, average test duration, and total tests. This helps identify degradation in quality or performance.
* Top Failing Tests: Pinpoint the tests that fail most frequently, indicating potential flakiness or persistent issues in your application or tests.
* Failure Types: Categorize failures e.g., assertion failures, timeouts, network errors to understand the root cause.
* Test Flakiness: Azure DevOps attempts to identify flaky tests tests that pass and fail intermittently without code changes. This is crucial, as flaky tests erode confidence in your test suite.
* Duration Trends: Monitor how long your tests are taking over time. Spikes might indicate performance regressions in your application or inefficient tests.
To access Test Analytics, go to Test Plans -> Analytics in Azure DevOps, and you can create custom widgets on your dashboards.
Monitoring and Maintenance of Test Suite
Just like application code, test code requires continuous maintenance.
* Regular Review of Test Failures: Don't ignore failing tests. Investigate them promptly.
* Is it a bug?: If so, create a work item bug directly from the failed test result in Azure DevOps.
* Is it a flaky test?: Analyze videos and screenshots. If it's timing-related, adjust `cy.wait` or `defaultCommandTimeout`. If it's an environment issue, refine your pipeline setup.
* Is it a bad test?: If the test is brittle, poorly written, or targets an unstable element, refactor or rewrite it.
* Performance Monitoring:
* Identify Slow Tests: Use the "Test Analytics" to find the slowest tests. Can they be optimized? Are they doing too much?
* Parallelization: If your test suite grows, reconsider parallelization to keep execution times low.
* Remove Obsolete Tests: As features change or are removed, ensure corresponding tests are updated or deleted. Stale tests add unnecessary overhead and confusion.
* Keep Cypress Up-to-Date: Regularly update your Cypress version to benefit from performance improvements, new features, and bug fixes. Check Cypress's release notes for breaking changes.
Feedback Loops for Continuous Improvement
A hallmark of a mature CI/CD pipeline is the presence of effective feedback loops.
* Notifications: Configure Azure DevOps notifications e.g., email, Microsoft Teams, Slack for pipeline failures, especially for critical stages like production deployments or Cypress E2E test failures. Rapid notification ensures immediate attention to issues.
* Dashboard Integration: Create Azure DevOps dashboards with widgets displaying key test metrics:
* Current pipeline status
* Test pass rate trends
* Number of failed tests over time
* Top failing tests
* Test duration
This visualizes the health of your application and test suite at a glance.
* Collaboration: Encourage developers, QAs, and product owners to regularly review test results and contribute to test maintenance. A collaborative approach fosters shared ownership of quality. Use pull request policies in Azure DevOps to require successful Cypress test runs before merging code.
* Retrospectives: Periodically review your testing process, including pipeline performance and test effectiveness, in team retrospectives. Identify bottlenecks, areas for automation, and opportunities for further optimization.
By adopting a mindset of continuous improvement and diligently monitoring your Cypress test pipeline in Azure DevOps, you transform automated testing from a mere checklist item into a powerful engine for delivering high-quality, reliable software, which aligns with the Islamic principle of seeking excellence in all endeavors.
This systematic and diligent approach helps ensure that your work is not only effective but also refined over time, seeking the best possible outcome.
---
Frequently Asked Questions
# What is Cypress and why use it for E2E testing?
Cypress is a modern front-end testing tool built for the web.
It's used for end-to-end E2E testing, which simulates real user interactions with your application.
It's popular because it's fast, reliable, developer-friendly, and offers features like automatic waiting, time-travel debugging, and video recording of test runs, making it easier to write, run, and debug tests compared to traditional frameworks.
# What is Azure DevOps and how does it relate to CI/CD?
Azure DevOps is a Microsoft product that provides a complete set of development tools and services for planning, building, and deploying software.
It includes Git repositories, CI/CD pipelines Azure Pipelines, artifact management, test plans, and project management capabilities.
It helps teams automate the entire software development lifecycle, from code commit to deployment, enabling Continuous Integration CI and Continuous Delivery CD.
# Can I run Cypress tests on a Windows agent in Azure DevOps?
Yes, you can run Cypress tests on a Windows agent in Azure DevOps by setting `vmImage: 'windows-latest'` in your pipeline YAML.
However, for Node.js applications and Cypress specifically, `ubuntu-latest` is often recommended as it generally offers faster build times and might be more resource-efficient.
# How do I ensure Cypress runs in headless mode in Azure DevOps?
To ensure Cypress runs in headless mode without a graphical browser interface in Azure DevOps, you must set the `CI` environment variable to `true` for the step that executes your Cypress tests.
For example, `env: CI: 'true'`. This prevents Cypress from attempting to launch a visible browser, which would fail on a headless CI agent.
# What is the purpose of `npm ci` vs `npm install` in a CI pipeline?
`npm ci` clean install is designed for CI environments.
It performs a clean installation of dependencies directly from your `package-lock.json` file, ensuring consistent and reproducible builds by deleting `node_modules` first.
`npm install` is more flexible, updating `package-lock.json` if needed, which is suitable for local development but less predictable for CI.
Always use `npm ci` in your CI pipelines for reliability.
# How do I publish Cypress test results in Azure DevOps?
You publish Cypress test results using the `PublishTestResults@2` task.
First, configure Cypress to output results in JUnit XML format e.g., using `mocha-junit-reporter` and `--reporter junit --reporter-options 'mochaFile=./test-results.xml'`. Then, specify the path to this XML file in the `testResultsFiles` input of the `PublishTestResults` task.
This makes test results visible in the "Tests" tab of your pipeline run.
# Why are my Cypress videos and screenshots not showing up in Azure DevOps?
Cypress videos and screenshots are published as build artifacts using the `PublishBuildArtifacts@1` task.
Ensure the `pathToPublish` in this task correctly points to your Cypress `videosFolder` default `cypress/videos` and `screenshotsFolder` default `cypress/screenshots`. Also, ensure the `condition: succeededOrFailed` is set on this task so that artifacts are published even if tests fail.
# How can I pass environment variables to Cypress tests in Azure DevOps?
You can pass environment variables to your Cypress tests by setting them in the `env` block of the `script` task that runs Cypress.
For example, `env: CYPRESS_BASE_URL: 'https://staging.myapp.com'`. For sensitive information, use Azure DevOps secret variables or variable groups linked to Azure Key Vault and reference them in the `env` block.
# How do I handle secrets like API keys in Cypress tests within Azure DevOps?
Never hardcode secrets directly in your YAML files.
Use Azure DevOps secret variables, which can be configured in the pipeline settings UI and marked as secret.
For enhanced security and reusability, use Variable Groups, ideally linked to Azure Key Vault.
Variables from these sources can then be referenced as `$MySecretVariable` in your pipeline steps and passed to Cypress via the `env` block.
# Can Cypress tests be parallelized in Azure DevOps?
Yes, Cypress tests can be parallelized to reduce overall execution time.
The most robust method is using the Cypress Dashboard Service with a record key.
You configure parallel jobs in your Azure DevOps pipeline YAML `strategy.parallel`, and Cypress Dashboard automatically distributes the test specs across the available agents. This can significantly speed up large test suites.
# What is `continueOnError: true` used for in Cypress test steps?
`continueOnError: true` is an important setting for the `script` task that runs your Cypress tests.
If this is set, the pipeline will continue to execute subsequent steps even if the Cypress test step fails e.g., if tests fail. This is crucial because it ensures that test results and artifacts videos, screenshots are still published, allowing you to debug failed tests effectively, rather than the pipeline stopping immediately.
# How can I cache Node.js dependencies in Azure DevOps for faster Cypress builds?
You can use the `Cache@2` task to cache your `node_modules` folder. Place the `Cache@2` task before your `npm ci` step.
Configure its `key` based on `package-lock.json` and its `path` to your npm cache directory or `node_modules`. This significantly speeds up subsequent pipeline runs by avoiding repeated downloads and installations of dependencies.
# My Cypress tests are flaky in CI. What should I do?
Flaky tests are common and frustrating. Address them by:
1. Ensuring Environment Consistency: Match Node.js versions, use `npm ci`.
2. Improving Waits: Use `cy.wait'@alias'` for network requests, or increase `defaultCommandTimeout` in Cypress config if elements consistently time out.
3. Test Retries: Configure Cypress's `retries` option in `cypress.json` to rerun failed tests e.g., `runMode: 2`. While this helps mask transient flakiness, the ultimate goal should be to fix the underlying cause.
4. Analyze Artifacts: Use videos and screenshots to pinpoint the exact moment of failure.
# How do I debug Cypress test failures in Azure DevOps?
Debugging involves:
1. Reviewing Test Results: Check the "Tests" tab for detailed error messages and stack traces.
2. Downloading Artifacts: Download the Cypress videos and screenshots published as artifacts. Videos show the entire test run, and screenshots capture the UI at the point of failure. This visual evidence is invaluable.
3. Logs: Examine the pipeline logs for any errors during the `npm run cypress:run` step or related setup.
# Can Cypress tests be run against a deployed application in Azure DevOps?
Yes, this is a highly recommended practice for E2E testing.
In a multi-stage pipeline, you would have a stage that first deploys your application to a staging or test environment e.g., an Azure App Service. Then, in a subsequent job or stage, you would run your Cypress tests, setting `CYPRESS_BASE_URL` to the URL of your newly deployed application.
# What are release gates in Azure DevOps and how do they work with Cypress?
Release gates in Azure DevOps are conditions that must be met before a release pipeline can proceed to the next stage.
You can configure a gate to check for "Successful deployment and tests." This means that the Cypress tests run in a previous stage e.g., staging must pass with a certain success threshold before the application can be deployed to the next environment e.g., production. This acts as a crucial quality control mechanism.
# How often should I run Cypress tests in Azure DevOps?
The frequency depends on your team's workflow and application criticality.
* On every commit to main/feature branches: For Continuous Integration, running tests frequently e.g., on every pull request or push to relevant branches provides rapid feedback.
* On scheduled basis: For comprehensive nightly or weekly regressions.
* Before/After deployments: As part of your CD pipeline to validate deployed environments.
The goal is to get feedback as quickly as possible.
# What resources are needed for running Cypress in Azure DevOps?
You'll need:
* An Azure DevOps organization and project.
* An Azure Repos Git repository containing your application and Cypress tests.
* An Azure DevOps pipeline definition `azure-pipelines.yml`.
* Microsoft-hosted agents like `ubuntu-latest` or self-hosted agents.
* A Cypress installation within your project listed in `package.json`.
* Optionally, a Cypress Dashboard account for parallelization and advanced reporting.
# How do I troubleshoot Node.js version issues with Cypress in Azure DevOps?
If you suspect Node.js version issues:
1. Verify `NodeTool@0`: Ensure the `versionSpec` in your `NodeTool@0` task matches a version compatible with your Cypress installation check Cypress documentation for supported Node.js ranges.
2. Check Logs: Look for any npm or Node.js-related errors in the pipeline logs.
3. Local vs. CI: Confirm your local Node.js version using `node -v` matches what's used in CI.
4. `package.json` `engines` field optional: You can specify supported Node.js versions in your `package.json` using the `engines` field, though Azure DevOps won't strictly enforce it unless configured.
# Can I run specific Cypress tests in Azure DevOps e.g., only smoke tests?
Yes, you can run specific Cypress tests by modifying the `cypress run` command in your `package.json` script or directly in the Azure DevOps YAML.
* Specific spec files: `cypress run --spec "cypress/e2e/smoke//*.cy.js"`
* Tags using a plugin like `cypress-realworld-app`: If you're using a tagging plugin, you can run tests with specific tags: `cypress run --env TAGS=smoke`
* CLI options: Pass other Cypress CLI options via your script to filter tests.
This allows for more targeted test runs based on pipeline stage or purpose.
Leave a Reply