diff --git a/lib/spreewald/web_steps.rb b/lib/spreewald/web_steps.rb index bf0a820..b244e30 100644 --- a/lib/spreewald/web_steps.rb +++ b/lib/spreewald/web_steps.rb @@ -620,7 +620,9 @@ containers = all(:css, selector) input = nil containers.detect do |container| - input = container.first(:xpath, XPath::HTML.fillable_field(field)) + input = container.first(:fillable_field, field) + rescue Capybara::ElementNotFound + # Capybara changed the behavior of #first and raises an error when the first container finds no matching field end if input input.set(value) diff --git a/tests/rails-7_capybara-3/.ruby-version b/tests/rails-7_capybara-3/.ruby-version index 4a36342..944880f 100644 --- a/tests/rails-7_capybara-3/.ruby-version +++ b/tests/rails-7_capybara-3/.ruby-version @@ -1 +1 @@ -3.0.0 +3.2.0 diff --git a/tests/shared/app/controllers/forms_controller.rb b/tests/shared/app/controllers/forms_controller.rb index bbd3ca6..21405ac 100644 --- a/tests/shared/app/controllers/forms_controller.rb +++ b/tests/shared/app/controllers/forms_controller.rb @@ -12,6 +12,9 @@ def form1 def form2 end + def form_with_two_inputs_in_separate_css_blocks_with_the_same_selector + end + def select_fields end diff --git a/tests/shared/app/views/forms/form_with_two_inputs_in_separate_css_blocks_with_the_same_selector.html.haml b/tests/shared/app/views/forms/form_with_two_inputs_in_separate_css_blocks_with_the_same_selector.html.haml new file mode 100644 index 0000000..de2b0d5 --- /dev/null +++ b/tests/shared/app/views/forms/form_with_two_inputs_in_separate_css_blocks_with_the_same_selector.html.haml @@ -0,0 +1,8 @@ += form_tag do + .my-container + = label_tag 'first_text_field', 'First Text field' + = text_field_tag 'first_text_field', 'First value' + + .my-container + = label_tag 'second_text_field', 'Second Text field' + = text_field_tag 'second_text_field', 'Second value' diff --git a/tests/shared/config/routes.rb b/tests/shared/config/routes.rb index 29dd846..cd78b6d 100644 --- a/tests/shared/config/routes.rb +++ b/tests/shared/config/routes.rb @@ -22,6 +22,7 @@ get '/forms/disabled_elements', to: 'forms#disabled_elements' get '/forms/form1', to: 'forms#form1' get '/forms/form2', to: 'forms#form2' + get '/forms/form_with_two_inputs_in_separate_css_blocks_with_the_same_selector', to: 'forms#form_with_two_inputs_in_separate_css_blocks_with_the_same_selector' get '/forms/select_fields', to: 'forms#select_fields' get '/forms/invalid_rails_form', to: 'forms#invalid_rails_form' get '/forms/invalid_bootstrap3_form', to: 'forms#invalid_bootstrap3_form' diff --git a/tests/shared/features/shared/web_steps.feature b/tests/shared/features/shared/web_steps.feature index c957b0c..5eefaa8 100644 --- a/tests/shared/features/shared/web_steps.feature +++ b/tests/shared/features/shared/web_steps.feature @@ -416,3 +416,13 @@ Feature: Web steps Scenario: /^the window should be titled "([^"]*)"$/ When I go to "/static_pages/home" Then the window should be titled "spreewald test application" + + + Scenario: I fill in "..." with "..." inside any "..." + When I go to "/forms/form_with_two_inputs_in_separate_css_blocks_with_the_same_selector" + Then the "First Text field" field should contain "First value" + And the "Second Text field" field should contain "Second value" + + When I fill in "Second Text field" with "My new value" inside any ".my-container" + Then the "First Text field" field should contain "First value" + And the "Second Text field" field should contain "My new value"