(Some background if it helps: our Rails app has a bunch of potentially repetitive dynamically-generated forms using double-nested fields, with ids in the pattern foo_attributes_0_bar_attributes_0_bat_12, where basically the first two numbers increment based on how many repetitions of the nested form there are, and the last number is the id of the particular "bat" object. This makes selection in Cucumber for testing difficult!)
I am trying to write some steps like this:
When I check the 1st checkbox with the value "Bat 12"
or
When I check the 3rd checkbox with id matching "bar_attributes_bat"
I have the following working, but my method of finding the checkboxes (or fields) seems pretty crappy and inefficient to me:
When /^I check the (\d+)(st|nd|rd|th) checkbox with the value "([^"]*)"$/ do |number, junk, value|
check(page.all("input").select {|el| el.node['value'] == value}[(number.to_i-1)].node['id'])
end
When /^I check the (\d+)(st|nd|rd|th) checkbox with id matching "([^"]*)"$/ do |number, junk, id_string|
check(page.all("input").select {|el| el.node['id'] && el.node['id'].match(/#{id_string}/)}[(number.to_i-1)].node['id'])
end
Is there a better way to select these input elements?
When /^I check the (\d+)(st|nd|rd|th) checkbox with the value "([^"]*)"$/ do |index, junk, value|
page.all("input[value='#{value}']")[index.to_i-1].check
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With