Cypress Dashboard (Cloud) service - Build an Automation Script
/// <reference types="cypress" /> // This script runs Cypress tests with recording enabled and verifies Dashboard data via API const dashboardProjectId = '<your-project-id>' const dashboardRecordKey = Cypress.env('CYPRESS_RECORD_KEY') // Step 1: Run tests with recording // This is normally done outside test code, but we simulate here for demonstration // Step 2: After tests run, verify Dashboard data via API describe('Cypress Dashboard Verification', () => { it('should verify test run data on Cypress Dashboard', () => { // Call Cypress Dashboard API to get latest runs cy.request({ method: 'GET', url: `https://dashboard.cypress.io/projects/${dashboardProjectId}/runs`, headers: { Authorization: `Bearer ${dashboardRecordKey}` } }).then((response) => { expect(response.status).to.eq(200) const runs = response.body.runs expect(runs).to.have.length.greaterThan(0) const latestRun = runs[0] expect(latestRun).to.have.property('stats') expect(latestRun.stats).to.have.property('tests') expect(latestRun.stats).to.have.property('passes') expect(latestRun.stats).to.have.property('failures') // Check that passes + failures equals total tests expect(latestRun.stats.passes + latestRun.stats.failures).to.eq(latestRun.stats.tests) // Verify screenshots and videos exist for failed tests if (latestRun.stats.failures > 0) { expect(latestRun).to.have.property('screenshots') expect(latestRun.screenshots.length).to.be.greaterThan(0) expect(latestRun).to.have.property('videos') expect(latestRun.videos.length).to.be.greaterThan(0) } }) }) })
This test script uses Cypress to verify that the Cypress Dashboard service correctly records test runs.
First, it assumes tests have been run with the --record flag and a valid record key.
Then, it calls the Cypress Dashboard API to fetch the latest test runs for the project.
Assertions check that the API response is successful, that the latest run has test statistics, and that the sum of passes and failures equals total tests.
If there are failed tests, it verifies that screenshots and videos are present in the run data.
We use environment variables for sensitive keys and explicit assertions for clarity and reliability.
Now add data-driven testing to verify Dashboard test run data for 3 different projects with different record keys.
Practice
Cypress Dashboard (Cloud) service?Solution
Step 1: Understand the role of Cypress Dashboard
The Cypress Dashboard service collects test results and shows them online.Step 2: Compare options with this role
Only To collect and display test results online for better tracking describes collecting and displaying test results online for tracking.Final Answer:
To collect and display test results online for better tracking -> Option BQuick Check:
Cypress Dashboard = Online test results tracking [OK]
- Thinking Dashboard runs tests locally
- Confusing Dashboard with test script writing
- Assuming Dashboard replaces test runner
Solution
Step 1: Recall the command to send results
The--recordoption is used with the project key to send test results to the Dashboard.Step 2: Verify other options
Options like--upload,--sync, and--pushare not valid Cypress commands for this purpose.Final Answer:
--record -> Option CQuick Check:
Send results = --record [OK]
- Using --upload instead of --record
- Confusing with git push commands
- Omitting the project key with --record
cypress run --record --key abc123, what is the expected outcome?Solution
Step 1: Analyze the command options
The command includes--recordand a project keyabc123, which means results will be sent to the Dashboard.Step 2: Understand the effect
Tests run normally and results are uploaded to the Dashboard service using the provided key.Final Answer:
Tests run and results are sent to Dashboard with key abc123 -> Option AQuick Check:
--record + key = send results [OK]
- Assuming tests run without sending results
- Thinking project key is optional
- Confusing local save with Dashboard upload
cypress run --record but get an error about missing project key. What is the fix?Solution
Step 1: Identify the error cause
The error about missing project key means--recordwas used without specifying--key.Step 2: Apply the fix
Add--key your_project_keyto the command to authenticate and send results.Final Answer:
Add the --key option with your project key -> Option AQuick Check:
Missing key error = add --key [OK]
- Ignoring the missing key error
- Removing --record instead of adding key
- Assuming update fixes key error
Solution
Step 1: Understand flaky test tracking
Flaky tests are unstable tests that sometimes fail. Cypress Dashboard can track retries and failures.Step 2: Identify best practice
Using--recordwith the project key sends results to Dashboard, and enabling retries in Dashboard helps track flaky tests.Final Answer:
Use --record with project key and enable Dashboard retries -> Option DQuick Check:
Track flaky tests = record + retries [OK]
- Relying on manual screenshots only
- Disabling recording loses Dashboard benefits
- Using email reports misses real-time tracking
Ready to prove it?
Pass the test and this pattern moves unknown
