From 5ee4357cd69fb14057729301a8b6328efca60134 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 17 Nov 2008 14:21:16 -0500 Subject: [PATCH] Add set_hidden_field and submit_form methods ND/BH --- lib/webrat/core/form.rb | 4 ++++ lib/webrat/core/scope.rb | 10 ++++++++++ lib/webrat/core/session.rb | 2 ++ 3 files changed, 16 insertions(+) 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