I'm currently working on a large project that uses many custom React components that I do not control. So it's not an option for me to modify them, and it's infeasible for me to make a pull request for every single custom component that doesn't have the behavior that I want.
I'm seeking to use Cypress to interact with these components. However, these custom components don't seem to support the use of data-*
or id
props. The text of these components could change depending upon the language the user is using.
The only way I see that you're able to get elements in Cypress is by finding what classes are assigned to them and selecting based upon the class value.
Cypress documentation says that you should never do this as it's likely to change, and it is.
However, I've been trying to find alternative solutions but have not been able to find any other solutions.
Is there a good way to force a the outermost html element of a react component that you don't control to take on an data-*
or id
attribute, or any other solution that can be used for robust Cypress testing?