Skip to main content
Cypress Accessibility+ Add-on

views

Cypress automatically groups certain URL patterns to create views. However, for URLs that are not automatically grouped (e.g., /users/alice and /users/bob are not automatically grouped into /users/*), the views property allows you to specify custom URL patterns to define views. This configuration enhances the clarity and organization of your coverage reports.

The groupBy property of a view definition allows you to create multiple views with a single URL pattern, grouping URLs by the specified named parameter(s).

Why use views?โ€‹

info

Note: setting views impacts both Accessibility and UI Coverage reports. Nesting this property under an accessibility or uiCoverage key is supported, if you need to split them up.

  • Group Dynamic URLs: Group URLs with dynamic path parameters (e.g., /users/alice and /users/bob) that are not ids or uuids into a single view.
  • Organize by Query Parameters: Create views based on query parameters to group URLs where query strings are important to the context of the page.

Syntaxโ€‹

{
"views": [
{
"pattern": string,
"groupBy": [
string
]
}
]
}

Optionsโ€‹

The first pattern that a given URL matches is used as its view. If a URL doesn't match any of the patterns, it is grouped by the default view grouping rules, if possible.

OptionRequiredDefaultDescription
patternRequiredA URL pattern to group matching URLs into a single view. Uses URL Pattern API syntax.
groupByOptionalAn array of named URL parameters used to further subdivide the URLs into multiple views within the same pattern. This is useful for dynamic applications where URLs represent different user interactions or data segments.

Examplesโ€‹

Grouping dynamic path parametersโ€‹

Configโ€‹

{
"views": [
{
"pattern": "https://www.my-app.com/users/*"
}
]
}

Visited URLsโ€‹

https://www.my-app.com/users/alice
https://www.my-app.com/users/bob
https://www.my-app.com/users/bob#settings
https://www.my-app.com/users?assigned=true

Views shown in UIโ€‹

www.my-app.com/users
www.my-app.com/users/*

Using named path parametersโ€‹

Configโ€‹

{
"views": [
{
"pattern": "https://www.my-app.com/users/:name"
}
]
}

Visited URLsโ€‹

https://www.my-app.com/users/alice
https://www.my-app.com/users/bob
https://www.my-app.com/users/bob#settings
https://www.my-app.com/users?assigned=true

Views shown in UIโ€‹

www.my-app.com/users
www.my-app.com/users/:name

Group URLs by named parametersโ€‹

Configโ€‹

{
"views": [
{
"pattern": "https://www.my-app.com/analytics/:type/:id",
"groupBy": ["type"]
}
]
}

Visited URLsโ€‹

https://www.my-app.com/analytics/performance/amara
https://www.my-app.com/analytics/performance/harper
https://www.my-app.com/analytics/usage/amara
https://www.my-app.com/analytics/usage/harper

Views shown in UIโ€‹

www.my-app.com/analytics/performance/:id
www.my-app.com/analytics/usage/:id

Group URLs by named query parametersโ€‹

Configโ€‹

{
"views": [
{
"pattern": "https://www.my-app.com/home?*status=:status{&*}?#*",
"groupBy": ["status"]
}
]
}

Visited URLsโ€‹

https://www.my-app.com/home?page=1&status=done
https://www.my-app.com/home?status=done&group=2
https://www.my-app.com/home?tag=trip&status=new&group=4
https://www.my-app.com/home?tag=trip&status=new#statusView

Views shown in UIโ€‹

www.my-app.com/home?status=done
www.my-app.com/home?status=new

Grouping URLs across subdomainsโ€‹

Configโ€‹

{
"views": [
{
"pattern": "https://*.my-app.com/:path*",
"groupBy": ["path"]
}
]
}

Visited URLsโ€‹

https://staging1.my-app.com/home
https://staging2.my-app.com/home
https://www.my-app.com/home
https://staging1.my-app.com/profile
https://www.my-app.com/profile/edit

Views shown in UIโ€‹

https://*.my-app.com/home
https://*.my-app.com/profile
https://*.my-app.com/profile/edit