Capybara field.has_css? harmonization

I use the following specification with MiniTest::Spec and Capybara :

 find_field('Email').must_have_css('[autofocus]') 

to check if the "Email" field has an autofocus attribute. doc says the following:

has_css? (path, options = {})

Checks if the given CSS selector is on the page or the current node.

As far as I understand, the "Email" field is a node, so the must_have_css call must work! What am I doing wrong?

+4
source share
3 answers

Got a response from Jonas Nicklas :

No, this should not work. has_css? will check if any of the descendants of the element matches the given CSS. He will not check the item himself. Since the autofocus property is most likely in the email field itself, has_css? will always return false in this case.

You can try:

 find_field('Email')[:autofocus].should be_present 

this can also be done with XPath, but I cannot remember the syntax at the top of my head.


My decision:

 find_field('Email')[:autofocus].must_equal('autofocus') 
+7
source

Down to the head. Can you use has_selector?() . Using Rspec wit Capy:

 page.should have_selector('email', autofocus: true) 

Also check out Capybara matchers http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers

0
source

I haven't used MiniTest before, but your syntax for checking an attribute looks right.

I'm worried about your use of find_field. The docs say:

Locate the form field on the page. A field can be found by its name, identifier or label.

It looks like you are trying to find a field based on a label. If so, I would check that you have a for attribute and that it has the correct identifier for the form field you are looking for. To eliminate this problem, you can temporarily mark your form field and look for it explicitly.

0
source

Source: https://habr.com/ru/post/1383249/


All Articles