mardi 3 mars 2020

Getting checkboxes checked in Cypress if id is auto-generated

There's a code (not written by me) that contains unique id-s for each checkbox in each table row, which is generated by the system. It looks as below and "12345" is generated automatically for each row added as well as the paths.

The question is, how to specify for testing in cypress, which row I want to check.

The code I'm testing:

<tr class="" xxx-yyy="document-aaa"><td><input id="12345" type="checkbox"><label for="12345"></label></td><td xxx-yyy="document-bbb">word_document.docx</td><td class="text-right"><button class="text-grey-dark" xxx-yyy="delete-document"><svg focusable="false" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 32 32" aria-hidden="true" class="inline-block" style="will-change: transform;"><path d="Ab13457GHT45"></path><path d="Zxf-67-HJKSx7"></path></svg> delete</button></td></tr>

And the only option I got working in cypress is using "first", but this doesn't allow me to check for example the second one or several checkboxes out of many.

      .first()
      .find('[type="checkbox"]')
      .check({ force: true });```



Aucun commentaire:

Enregistrer un commentaire