Skip to content

Commit

Permalink
[#187748472] Fix step 'I fill in "..." with "..." inside any "..."'
Browse files Browse the repository at this point in the history
  • Loading branch information
FLeinzi committed Jun 7, 2024
1 parent eee2542 commit 8bfac8f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/spreewald/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/rails-7_capybara-3/.ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.2.0
3 changes: 3 additions & 0 deletions tests/shared/app/controllers/forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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'
1 change: 1 addition & 0 deletions tests/shared/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 10 additions & 0 deletions tests/shared/features/shared/web_steps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 8bfac8f

Please sign in to comment.