Skip to content
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

rails_error? method does not work for inputs nested deeper than one level #205

Closed
begerdom opened this issue Nov 13, 2023 · 2 comments
Closed

Comments

@begerdom
Copy link
Member

begerdom commented Nov 13, 2023

The rails error detection mechanism works only, if an input is placed as direct child under a container with the field_with_errors class, e.g. a .form-group. That is because it does only check for this class on the direct parent node. See https://github.com/makandra/spreewald/blob/master/lib/spreewald_support/field_errors.rb#L52

In my case the input is nested within an .input-group and the class cannot be found on this one, but is located a bit higher above.

The detection mechanism should rather search for the class on any parent and then check, if such a node can be found. Something like @element.has_xpath?("ancestor-or-self::*[contains(@class, \"#field_with_errors\")]") (compare to custom_error?.

For now, I can use the custom_error? by setting Spreewald.field_error_class = 'field_with_errors' to help because it does exactly that. However, I feel that this should also be the default behavior for the rails_error? method.

@kratob
Copy link
Member

kratob commented Nov 15, 2023

When we fix this: We also need to refactor this code for performance.

The error_present? method takes up to 4 * Capybara.default_max_wait_time if there is no error, since has_xpath? will wait if there is no match.

We have to use has_no_xpath? etc. according to whether we currently expect, or not expect there to be an error.

@kratob kratob mentioned this issue Dec 5, 2023
@kratob
Copy link
Member

kratob commented Dec 21, 2023

Fixed in 4.6.0 and performance improved.

@kratob kratob closed this as completed Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants