How to add data attributes for test automation

How to add data attributes for test automation

danielviannadanielvianna Posts: 15Questions: 7Answers: 0

I am using cypress to test automation and we are adding data attributes in the application to make the test more stable and avoid using xpath.
There is a part of the app to upload a csv file and I can't add the data attribute for the button in the popup.

I was able to add the attributes for the dropdowns but I can't for the button.

I tryied this but didn't work

the weird is that I did the same in another button and worked

Can someone please help me with this?
Thank you

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    In your code, if you change

            buttons: 'Import '+csv.length+' records',
    

    to be

          buttons: {text: 'Import '+csv.length+' records', className: 'testClass', action: function() {this.submit()} },
    

    you should be good to go. See example here.

    Colin

This discussion has been closed.