Accessibility-Driven Testing

Just test everything?

Are you flossing

after every meal?

Two essentials tests

  • Can users log in?
  • Can they give us money?

Tool recommendations

  • Cypress for end-to-end (e2e) tests
  • Jest + Vue Test Utils for unit tests

What is accessibility-driven testing?

Advantages

  • More reliable
  • Simpler
  • Reveals hidden bugs

How I got here

cy.get('.email-input')
cy.get('.test-email-input')
cy.get('[data-test="email-input"]')

What's the problem?

cy.get('[data-test="email-input"]').type(testUser.email)
cy.get('[data-test="username-input"]').type(testUser.name)
cy.get('[data-test="password-input"]').type(testUser.password)

Think as the user

cy.contains('label', 'email', { matchCase: false }).click()
cy.focused()
  .should('have.attr', 'type', 'email')
  .type(testUser.email)

cy.contains('label', 'name', { matchCase: false }).click()
cy.focused()
  .should('have.attr', 'type', 'text')
  .type(testUser.name)

cy.contains('label', 'password', { matchCase: false }).click()
cy.focused()
  .should('have.attr', 'type', 'password')
  .type(testUser.password)

Too much work... 😓

Reusable custom commands

Cypress.Commands.add('input', (inputType, inputLabel) => {
  inputLabel = inputLabel || inputType 

  cy.contains('label', inputLabel, { matchCase: false }).click()
  
  return cy.focused().should('have.attr', 'type', inputType)
})
cy.input('email').type(testUser.email)
cy.input('text', 'name').type(testUser.name)
cy.input('password').type(testUser.password)
cy.get('[data-test="email-input"]').type(testUser.email)
cy.get('[data-test="username-input"]').type(testUser.name)
cy.get('[data-test="password-input"]').type(testUser.password)

Reveal bugs

cy.contains('button', 'Add to cart').click()

Error!

How to fix?

cy.route("GET", "api/products/1/inventory")
  .as("getProductInventory")
  .wait("@getProductInventory")
cy.wait(5000)

?

?

<button :disabled="isFetchingData" ...>
  Add to cart
</button>

!

Also works for unit tests!

(devs are the users!)

That's all!

Special thanks to my Vuesionary sponsors

  • Vuetify
  • Vue School
  • Vue Mastery
  • Ben Hong

@chrisvfritz

slides.com/chrisvfritz/

adt-2020-03

Accessibility-Driven Testing

By Chris Fritz

Accessibility-Driven Testing

The MIT License (MIT) Copyright (c) 2020-present Chris Fritz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  • 1,369