---
id: ui-coverage/configuration/allowedinteractioncommands
title: Allowed Interaction Commands | Cypress UI Coverage
description: >-
  The `allowedInteractionCommands` configuration property allows users to limit
  the interaction commands that are tracked for specific elements in UI
  Coverage.
section: ui-coverage
source_path: docs/ui-coverage/configuration/allowedinteractioncommands.mdx
version: 998ed2fab5510b3f672383c6cb23238bf481edb8
updated_at: '2026-05-24T20:45:33.543Z'
---
# allowedInteractionCommands

UI Coverage tracks [all interaction commands](/llm/markdown/ui-coverage/core-concepts/interactivity.md#Interaction-Commands) by default for comprehensive coverage reporting. The `allowedInteractionCommands` configuration allows you to limit which interaction commands are tracked for specific elements by defining rules based on CSS selectors.

This is particularly useful for filtering out irrelevant interactions or focusing coverage tracking on specific interaction patterns for different types of elements.

## Why use allowedInteractionCommands?

*   **Focused tracking**: Limit coverage tracking to relevant interaction types for specific elements or components to reduce noise in reports.
*   **Component-specific rules**: Apply different interaction tracking rules based on element types or component categories. For example, you may require specific kinds of interactions on complex data-visualization components that are not required in regular interactive elements.

## Syntax

```
{  "uiCoverage": {    "allowedInteractionCommands": [      {        "selector": string,        "commands": [string],        "documentScope": [string],        "comment": string      }    ]  }}
```

### Options

The `allowedInteractionCommands` property accepts an array of objects, where each object defines a rule for limiting interaction commands for elements matching a specific selector.

| Option | Required | Default | Description |
| --- | --- | --- | --- |
| `selector` | Required |  | A CSS selector to identify elements. Supports standard CSS selector syntax, including IDs, classes, attributes, and combinators. |
| `commands` | Required |  | An array of command names (strings) that should be tracked as interactions for elements matching the selector. All other interaction commands will be ignored for these elements. |
| `documentScope` | Optional |  | An array of CSS selectors that identify document hosts (iframes or shadow DOM hosts) that must be ancestors of the matched element. The selector will only match if all specified document hosts are found in the element's ancestor chain. |
| `comment` | Optional |  | A comment describing the purpose of this allowed interaction commands configuration. |

## Examples

### Limiting button interactions to clicks only

#### Config

```
{  "uiCoverage": {    "allowedInteractionCommands": [      {        "selector": "button, [role='button']",        "commands": ["click", "realClick"]      }    ]  }}
```

#### Usage in tests

```
// Only click and realClick will be tracked for buttonscy.get('[data-cy="submit-button"]').click() // ✓ Trackedcy.get('[data-cy="submit-button"]').realClick() // ✓ Trackedcy.get('[data-cy="submit-button"]').hover() // ✗ Not trackedcy.get('[data-cy="submit-button"]').focus() // ✗ Not tracked
```

### Different rules for form elements

#### Config

```
{  "uiCoverage": {    "allowedInteractionCommands": [      {        "selector": "input[type='text'], textarea",        "commands": ["type", "clear", "realType"]      },      {        "selector": "select",        "commands": ["select", "click"]      },      {        "selector": "input[type='checkbox'], input[type='radio']",        "commands": ["check", "uncheck", "click"]      }    ]  }}
```

#### Usage in tests

```
// Text inputs: only type, clear, and realType are trackedcy.get('[data-cy="username"]').type('john_doe') // ✓ Trackedcy.get('[data-cy="username"]').clear() // ✓ Trackedcy.get('[data-cy="username"]').focus() // ✗ Not tracked// Select elements: only select and click are trackedcy.get('[data-cy="country"]').select('US') // ✓ Trackedcy.get('[data-cy="country"]').click() // ✓ Trackedcy.get('[data-cy="country"]').hover() // ✗ Not tracked// Checkboxes/Radio buttons: check, uncheck, and click are trackedcy.get('[data-cy="agree-terms"]').check() // ✓ Trackedcy.get('[data-cy="agree-terms"]').click() // ✓ Tracked
```

### Excluding hover interactions for mobile components

#### Config

```
{  "uiCoverage": {    "allowedInteractionCommands": [      {        "selector": "[data-mobile='true']",        "commands": ["click", "tap", "swipe", "type"]      }    ]  }}
```

#### Usage in tests

```
// Mobile components: hover interactions are excludedcy.get('[data-mobile="true"][data-cy="menu-item"]').click() // ✓ Trackedcy.get('[data-mobile="true"][data-cy="menu-item"]').tap() // ✓ Trackedcy.get('[data-mobile="true"][data-cy="menu-item"]').hover() // ✗ Not tracked
```

### Allowing assertions as interactions

Note that because `allowedInteractionCommands` replaces the allowed interactions, if you add `assert` as an interaction, remember to also add any other acceptable interactions to the list.

#### Config

```
{  "uiCoverage": {    "allowedInteractionCommands": [      {        "selector": "button[data-no-explicit-interaction='true']",        "commands": ["assert"]      }    ]  }}
```

#### Usage in tests

```
// Any assertions on matching elements are trackedcy.get('button[data-no-explicit-interaction="true"]').should('exist) // ✓ Trackedcy.get('button[data-no-explicit-interaction="true"]').should('be.visible) // ✓ Trackedcy.get('button[data-no-explicit-interaction="true"]').click() // ✗ Not tracked
```

### Scoping interaction commands to shadow DOM

When you need to limit interaction commands for elements within a specific shadow DOM host, use the `documentScope` property to scope your selector to that document context.

#### Config

```
{  "uiCoverage": {    "allowedInteractionCommands": [      {        "selector": "button",        "commands": ["click"],        "documentScope": ["custom-component"]      }    ]  }}
```

#### HTML

```
<body>  <button id="root-button">Root Button</button>  <custom-component>    #shadow-dom      <button id="shadow-button">Shadow Button</button>  </custom-component></body>
```

#### Usage in tests

```
// Root button: all interactions tracked (default behavior)cy.get('#root-button').click() // ✓ Trackedcy.get('#root-button').hover() // ✓ Tracked// Shadow DOM button: only click trackedcy.get('custom-component').shadow().find('#shadow-button').click() // ✓ Trackedcy.get('custom-component').shadow().find('#shadow-button').hover() // ✗ Not tracked
```

* * *

### Scoping interaction commands to iframes

You can also scope interaction command rules to elements within specific iframes using `documentScope`.

#### Config

```
{  "uiCoverage": {    "allowedInteractionCommands": [      {        "selector": "input",        "commands": ["type", "clear"],        "documentScope": ["#embedded-form"]      }    ]  }}
```

#### HTML

```
<body>  <input id="root-input" />  <iframe id="embedded-form" src="http://www.foo.com">    <html>      <body>        <input id="embedded-input" />      </body>    </html>  </iframe></body>
```

#### Usage in tests

```
// Root input: all interactions tracked (default behavior)cy.get('#root-input').type('text') // ✓ Trackedcy.get('#root-input').focus() // ✓ Tracked// Embedded input: only type and clear trackedcy.get('#embedded-form').then(($iframe) => {  cy.wrap($iframe.contents().find('#embedded-input')).type('text') // ✓ Tracked  cy.wrap($iframe.contents().find('#embedded-input')).focus() // ✗ Not tracked})
```

## Notes

*   Elements that don't match any selector will have all interaction commands tracked (default behavior).
*   If an element matches multiple selectors, commands from all matching rules will be allowed. A high degree of specificity for these selectors is recommended.
*   Command names are case-sensitive and must match exactly as they appear in your test code.
*   This configuration works separately from `additionalInteractionCommands`. Custom commands do **not** need to be globally defined as `additionalInteractionCommands` in order to be declared here.
