-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow locating disabled buttons or fields #47
Comments
I strongly agree. I'd like to test that certain fields and buttons start off as disabled, then become enabled as the user changes other data. I had even written the following Capybara extensions before I realized that XPath was doing the filtering automatically (and without an override): Capybara::Node::Element.class_eval do
def enabled?
!disabled?
end
def disabled?
self[:disabled] == 'disabled'
end
end
Capybara::Selector.class_eval do
all[:button].filter(:enabled) { |node, value| value ^ node.disabled? }
all[:button].filter(:disabled) { |node, value| value ^ node.enabled? }
end None of the other XPath selectors take multiple arguments. Thus, I recommend either
|
I agree with jamesarosen, the ability to find a disabled element is crucial to testing the UI of our application. There are many reasons why someone might want to find disabled inputs for testing. Some examples:
I am a fan of the following tweak to the field finder api: |
I agree. Just ran into this issue. Even if a field is disabled you might want to assert its value. Not being able to select the field at all is not optimal to say the least. |
I agree with you guys. I'm having the same issue here. I'm updating the capybara to 2.0 and now I can't find disabled fields. So @jnicklas what do you think? Do we can do a patch? |
I did a temporary monkey patch (shame on me) to we use until we found a solution: module XPath
module HTML
protected
def locate_field(xpath, locator)
locate_field = xpath[attr(:id).equals(locator) | attr(:name).equals(locator) | attr(:placeholder).equals(locator) | attr(:id).equals(anywhere(:label)[string.n.contains(locator)].attr(:for))]
locate_field += descendant(:label)[string.n.contains(locator)].descendant(xpath)
# locate_field[~attr(:disabled)]
end
end
end |
We no longer filter away disabled elements. Capybara 2.1 implements this as a filter instead of hardcoding it in XPath itself. |
Thanks, @jnicklas :) |
👏 |
Commit a8f970d appears to have removed the ability to locate a disabled form field or button. For example, given this HTML:
Then an attempt to merely find the button fails:
I don't think the button xpath should be contingent upon the button being enabled. The button exists, and is visible to the user. I understand that for the purposes of interactivity (clicking/activating it), we may want the button to be "nonexistent". Perhaps it would make sense to include a second parameter to the
#button
method?Then one could do:
Or maybe separate methods specifically for locating enabled buttons/fields:
(I think I prefer the second solution; positional boolean parameters make for poor readability in client code).
Or is there another way to locate disabled buttons/fields that I'm overlooking?
I'd be happy to implement either of the above solutions and submit a pull request, but thought it best to discuss beforehand.
The text was updated successfully, but these errors were encountered: