Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress Studio: Generate DOM selectors based on the ARIA role name & label #30309

Open
john-ngai-bb opened this issue Sep 27, 2024 · 0 comments
Labels
experiment: studio Issues when using experimentalStudio type: accessibility ♿️ Improvements for accessibility type: feature New feature that does not currently exist

Comments

@john-ngai-bb
Copy link

What would you like?

Current Behaviour

The generated test code locates the DOM elements via their class names.

describe('', () => {
  it('The add template button is visible', () => {
    /* ==== Generated with Cypress Studio ==== */
    cy.get('.class > .another-class').should(
      'have.attr',
      'role',
      'button'
    )
    cy.get('.class > .another-class').should('be.visible')
    cy.get('.class > .another-class').should(
      'have.text',
      'Add template'
    )
    /* ==== End Cypress Studio ==== */
  })
})

Desired Behaviour

The generated test code locates the DOM elements via their ARIA role name and label combination.

The below example uses a DOM selector method from the @testing-library/cypress package, but any equivalent selector method is acceptable.

describe('', () => {
  it('The add template button is visible', () => {
    /* ==== Generated with Cypress Studio ==== */
    cy.findByRole('button', { name: 'Add template' }).should('be.visible')
    /* ==== End Cypress Studio ==== */
  })
})

Why is this needed?

All of our page elements have ARIA role names and labels defined, which are also the most resilient to any future changes we make. Selecting by class names or data-* attributes is not a viable alternative for us.

Therefore, we'd like to request for a feature to optionally generate the test code with DOM selectors that locates elements via their ARIA role name and label combinations. Alternatively, we'd like to see an interface where we could plugin our own selection logic or code generation patterns.

Other

No response

@jennifer-shehane jennifer-shehane added type: accessibility ♿️ Improvements for accessibility experiment: studio Issues when using experimentalStudio type: feature New feature that does not currently exist labels Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experiment: studio Issues when using experimentalStudio type: accessibility ♿️ Improvements for accessibility type: feature New feature that does not currently exist
Projects
None yet
Development

No branches or pull requests

2 participants