diff --git a/lib/webrat/core/form.rb b/lib/webrat/core/form.rb index 02efed6..29bbe1b 100644 --- a/lib/webrat/core/form.rb +++ b/lib/webrat/core/form.rb @@ -74,6 +74,10 @@ module Webrat labels.detect { |label| label.matches_text?(label_text) } end + def matches_id?(id) + @element["id"] == id.to_s + end + protected def fields_by_type(field_types) diff --git a/lib/webrat/core/scope.rb b/lib/webrat/core/scope.rb index bfb0bee..489ef35 100644 --- a/lib/webrat/core/scope.rb +++ b/lib/webrat/core/scope.rb @@ -44,6 +44,11 @@ module Webrat alias_method :fills_in, :fill_in + def set_hidden_field(field_locator, options = {}) + field = locate_field(field_locator, HiddenField) + field.set(options[:to]) + end + # Verifies that an input checkbox exists on the current page and marks it # as checked, so that the value will be submitted with the form. # @@ -256,6 +261,11 @@ module Webrat alias_method :clicks_button, :click_button + def submit_form(id) + form = forms.detect { |f| f.matches_id?(id) } + form.submit + end + def dom # :nodoc: return @dom if @dom diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index 9bcdde5..dac1149 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -180,6 +180,8 @@ module Webrat end def_delegators :current_scope, :fill_in, :fills_in + def_delegators :current_scope, :set_hidden_field + def_delegators :current_scope, :submit_form def_delegators :current_scope, :check, :checks def_delegators :current_scope, :uncheck, :unchecks def_delegators :current_scope, :choose, :chooses