title | description | sidebar_label |
---|---|---|
Supplemental Elements | Cypress UI Coverage |
The `supplementalElements` configuration property allows you to specify parent elements that should be used to supply additional information for identifying and grouping elements. |
supplementalElements |
UI Coverage has logic that automatically identifies and groups elements based on their appearance and structure in the DOM.
Sometimes, an element may not have enough information for Cypress's UI Coverage algorithm to accurately perform identification and grouping. This can cause the same element to be identified as multiple different elements, or multiple different elements to be identified as the same element.
The supplementalElements
configuration property allows users to specify selectors for parent elements that should be used to supply additional information for identifying and grouping elements, thereby allowing UI Coverage to find more suitable identifiers for elements nested within these supplemental elements.
For every element considered interactive and visible by UI Coverage, each element above it in the DOM is run through the supplementalElements
configuration. For each parent element that matches a supplementalSelector
, its significant attributes will be used to help identify and group elements that match the corresponding elementSelector
. If no elementSelector
is specified, the supplemental information will be applied to all descendant elements.
{
"uiCoverage": {
"supplementalElements": [
{
"supplementalSelector": string,
"elementSelector": string
}
]
}
}
Optional. Object[]
An array of objects used to determine which parent elements should be used to supply additional information for identifying and grouping elements. Each object can have the following properties:
Required. String (CSS Selector)
Used to match the parent elements that should be used to supply additional information for identifying and grouping elements.
Optional. String (CSS Selector)
Default: *
(matches any value).
Used to match elements that should receive supplemental information.
{
"uiCoverage": {
"supplementalElements": [
{
"supplementalSelector": ".page-container",
"elementSelector": "*"
}
]
}
}
<!-- Snapshot 1 -->
<body>
<div id="login-page" class="page-container">
<button id="submit">Login</button>
<button id="cancel">Cancel</button>
</div>
</body>
<!-- Snapshot 2 -->
<body>
<div id="signup-page" class="page-container">
<button id="submit">Signup</button>
<button id="cancel">Cancel</button>
</div>
</body>
#login-page #submit
#login-page #cancel
#signup-page #submit
#signup-page #cancel
{
"uiCoverage": {
"supplementalElements": [
{
"supplementalSelector": ".page-container",
"elementSelector": "#submit"
}
]
}
}
<!-- Snapshot 1 -->
<body>
<div id="login-page" class="page-container">
<button id="submit">Login</button>
<button id="cancel">Cancel</button>
</div>
</body>
<!-- Snapshot 2 -->
<body>
<div id="signup-page" class="page-container">
<button id="submit">Signup</button>
<button id="cancel">Cancel</button>
</div>
</body>
#login-page #submit
#signup-page #submit
#cancel