How to automatically add `data-cy` or `data-test` to react app?

Viewed 2414

I got a task of writing automated end to end UI tests for existing React application. I want to follow what cypress docs suggestion, use data-cy attribute values for selecting elements:

enter image description here

But there is no such attribute introduced by dev team in the application. Is there any way to automatically (any library) add data-cy or data-test attributes to existing react app. Or is there any easy way to do it manually, especially due to React's component architecture?

PS: adding selenium tag too because testing using selenium also involves element selection.

1 Answers

Instead doing it via cypress. Get the code from dev, add your

data-cy or data-test

by yourself and ask your dev team to approve your changes.

please do not waste time on this.

Related