Skip to content

[DevEx]: Refactor test selectors to use helpers and card ids #1361

Description

@itsalaidbacklife

Improvement Summary

We should refactor the way that tests select GameCard elements in the DOM to use helper functions and the ids of cards, rather then rank-suit strings

Detailed Description

Currently all the cypress tests identify cards in the DOM via a selector pattern of data-{location}-card={rank-suit} e.g. data-player-hand-card=0-13 for the king of clubs in the player's hand. We can simplify this in two ways:

  • Update these selectors in the DOM to use the cards' ids rather than rank-suit strings e.g. `data-player-hand-card=KC for the king of clubs in the player's hand
  • Define an enum with all the values for where cards can be e.g. CardLocation.PLAYER_HAND, CardLocation.OPPONENT_POINTS with string values for all the different selector locations
  • Create a function getCard(card, location) which inputs a card object and location (string enum) that calls cy.get() to get the chosen card in the chosen location
  • e.g. this would call cy.get(data-${location}-card="${card.id}" to get the selected card and allow chaining
  • Update all the existing test code selecting cards to call the above helper.
  • Update the docs to describe this new pattern

This will offer a more transparent selector pattern for test code that supports better autocompletion

Metadata

Metadata

Assignees

No one assigned

    Labels

    dev experienceImprovements to the code base that make it easier/better/more enjoyable to contribute to Cuttletesting automation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions