...

/

Cypress’s Advanced Test Automation Capabilities

Cypress’s Advanced Test Automation Capabilities

Explore advanced Cypress features: retry mechanism, time-based output validation, CI integration, and component testing.

Let’s explore the advanced features of the Cypress framework that front-end developers and SDETs can use.

Note: Measuring code coverage is also considered a powerful capability within software test automation. However, since we covered the abilities of code coverage with Istanbul and Babel in a previous chapter, we won’t repeat it here.

Cypress test retries

When creating test automation scenarios, one of the most complex cases and the most time-consuming is test stability and flakiness. Tests can often fail due to platform availability, environmental issues (such as loss of network connectivity on the test machine), synchronization issues on the web application under tests, and so on. For such cases, Cypress offers a test retry mechanism that, in cases of failures, will attempt to rerun tests up to three times prior to marking them as failed.

To use this feature globally for all our tests, we need to add a short block of code to the cypress.json file, as shown here:

Press + to interact
{
"retries": {
// Configure retry attempts for 'cypress run'
// Default is 0
"runMode": 2,
// Configure retry attempts for 'cypress open'
// Default is 0
"openMode": 0
}
}

Alternatively, to use this feature on a test-by-test case basis, we need to include this code block within the JavaScript test spec:

Press + to interact
It(
'do something',
{
retries: {
runMode: 2,
openMode: 1,
},
},// ... rest of the code
);

When using the retry mechanism, all flaky and retried test executions are visible in the Cypress web-based dashboard. We can go to the project test suite menu, and within the “Flaky tests” option, we can look at the identified flaky test cases, as well as see the overall percentage of flakiness within the project. We can then analyze and decide what the next steps are for these unstable ...