I'm improving my tests with RSpec
and capybara-webkit
, trying to delete all the css
and xpath
selectors like
find('#edit_user > div:nth-child(7) > div > div > button').click
and I'm looking for the best option to replace them.
I was going to use the css class
of the elements but some "pro" capybara tester said this is not the best option.
So my question is: can I use the data
attributes in my tests?
If I have an element
<button name="button" type="submit" class="button last" data-test="edit.update">Update/button>
will I be able to do
find('edit.update').click
?
And do you think it is a good idea? If you have more ideas/infos about this topic, feel free to comment!
Capybara.test_id=
, added in 2018 by 5b76480e571. – Colene