I'm using following spec with MiniTest::Spec
and Capybara
:
find_field('Email').must_have_css('[autofocus]')
to check if the field called 'Email' has the autofocus
attribute. The doc says following:
has_css?(path, options = {})
Checks if a given CSS selector is on the page or current node.
As far as I understand, field 'Email' is a node, so calling must_have_css
should definitely work! What I'm doing wrong?
Got an answer by Jonas Nicklas:
No, it shouldn't work. has_css? will check if any of the descendants of the element match the given CSS. It will not check the element itself. Since the autofocus property is likely on the email field itself, has_css? will always return false in this case.
You might try:
find_field('Email')[:autofocus].should be_present
this can also be done with XPath, but I can't recall the syntax off the top of my head.
My solution:
find_field('Email')[:autofocus].must_equal('autofocus')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With