David Kahn
2010-Oct-14 20:46 UTC
Cucumber Selenium web step to verify value of input field
I have an input field with an id which has a value. The web_steps.rb method does not find the value. Is this the right step to use to check an input field? It works fine for a text_area but not an input. Scenario steps (tried both ways): Then the "travel_card_number_gate" field should contain "5" Then the "#travel_card_number_gate" field should contain "5" From web_steps.rb Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should contain "([^\"]*)"$/ do |field, selector, value| with_scope(selector) do field = find_field(field) field_value = (field.tag_name == ''textarea'') ? field.text : field.value if field_value.respond_to? :should field_value.should =~ /#{value}/ else assert_match(/#{value}/, field_value) end end end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2010-Oct-14 20:50 UTC
Re: Cucumber Selenium web step to verify value of input field
PS, this is the error message: Then the "travel_card_number_gate" field should contain "5" # features/step_definitions/web_steps.rb:150 expected: /5/, got: "" (using =~) Diff: @@ -1,2 +1 @@ -/5/ (RSpec::Expectations::ExpectationNotMetError) ./features/step_definitions/web_steps.rb:155:in `block (2 levels) in <top (required)>'' ./features/step_definitions/web_steps.rb:14:in `with_scope'' ./features/step_definitions/web_steps.rb:151:in `/^the "([^\"]*)" field(?: within "([^\"]*)")? should contain "([^\"]*)"$/'' features/travel_card.feature:453:in `Then the "travel_card_number_gate" field should contain "5"'' On Thu, Oct 14, 2010 at 3:46 PM, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org>wrote:> I have an input field with an id which has a value. The web_steps.rb method > does not find the value. Is this the right step to use to check an input > field? It works fine for a text_area but not an input. > > Scenario steps (tried both ways): > Then the "travel_card_number_gate" field should contain "5" > Then the "#travel_card_number_gate" field should contain "5" > > From web_steps.rb > Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should contain > "([^\"]*)"$/ do |field, selector, value| > with_scope(selector) do > field = find_field(field) > field_value = (field.tag_name == ''textarea'') ? field.text : field.value > if field_value.respond_to? :should > field_value.should =~ /#{value}/ > else > assert_match(/#{value}/, field_value) > end > end > end >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.