Reputation: 116
I'm using Cypress to write automated tests. This is for a codebase I have no control over, so I can't make any changes to the app itself.
I'm attempting to run a .each loop to run through a set of collapsible fields to verify the data in each of them is correct. The fields list medical problems and associated data. The issue is that there are two lists of fields, one for active problems, and one for resolved problems, where the only difference between them is the data-cy tags. Those are the only unique identifiers for these elements, so I have to use the data-cy tags to select these without selecting other elements in the same container.
I'd be able to run the exact same .each function on both sets of elements, but I currently can't due to the elements not having the same data-cy tags. Is it possible for me to to have the Cypress .get call search for elements with one of two properties? Something like the following:
cy.get('[data-cy="problem-entry"]' OR '[data-cy="resolved-problem"]')
EDIT: Also, to clarify - I am currently able to get the test to behave by just duplicating the .each loop, once for each data-cy tag. Since the loop is several hundred lines of code, I want to remove the redundancy to clean this up a bit.
Upvotes: 2
Views: 1099
Reputation: 830
This answer is not perfect fix, but may work in your case: if these selectors are the only data-cy with the word "problem" in their value, you could do something like this:cy.get('[data-cy*="problem"]')
. This will choose any data-cy which contains word "problem".
If that is not the case, I would like to address your "EDIT" message: you may put the whole code (several hundred lines) in a Cypress custom command and then call it, so instead of copying the code and calling it twice, you would just call your custom command twice (one line each).
Upvotes: 1