diff --git a/History.txt b/History.txt index de6283f..482a378 100644 --- a/History.txt +++ b/History.txt @@ -11,7 +11,11 @@ * Filled in tests on click link lh 195 (diabolo) * Added current_url to selenium session lh 215 (Luke Amdor) * Added silence spec to selenium lh 238 (Martin Gamsjaeger aka snusnu) - * Added ability to configure the browser startup timeout for selenium lh 242 (Mike Gaffney) + * Added ability to configure the browser startup timeout for selenium lh 242 (Mike Gaffney, Mark Dodwell) + * Added delegation for field_named lh194 (pivotal labs) + * Added fix to keep from escaping field values in mechanize mode lh256 (jish) + * Adding fixes for click button/link and made the integration specs pass for the same in selenium lh254 (Ldiehl, Matthias Marschall) + * Adding clicking link by id in selenium mode lh221 (larrytheliquid) == 0.4.4 / 2009-04-06 diff --git a/lib/webrat/core/elements/field.rb b/lib/webrat/core/elements/field.rb index 7eecc94..c887167 100644 --- a/lib/webrat/core/elements/field.rb +++ b/lib/webrat/core/elements/field.rb @@ -87,6 +87,8 @@ module Webrat parse_rails_request_params("#{name}=#{escaped_value}") when :merb ::Merb::Parse.query("#{name}=#{escaped_value}") + when :mechanize + { name => value } else { name => escaped_value } end diff --git a/lib/webrat/core/methods.rb b/lib/webrat/core/methods.rb index 57c4085..84f0bbd 100644 --- a/lib/webrat/core/methods.rb +++ b/lib/webrat/core/methods.rb @@ -57,9 +57,7 @@ module Webrat :field_by_xpath, :field_with_id, :selenium, - :simulate, :automate - - - + :simulate, :automate, + :field_named end end diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index 13f3f90..8935da2 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -255,6 +255,7 @@ For example: def_delegators :current_scope, :field_by_xpath def_delegators :current_scope, :field_with_id def_delegators :current_scope, :select_option + def_delegators :current_scope, :field_named private diff --git a/lib/webrat/selenium.rb b/lib/webrat/selenium.rb index 2564645..d47c583 100644 --- a/lib/webrat/selenium.rb +++ b/lib/webrat/selenium.rb @@ -1,13 +1,7 @@ require "webrat" gem "selenium-client", ">=1.2.14" require "selenium/client" - -# active_support already defines silence_stream, no need to do that again if it's already present. -# http://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/kernel/reporting.rb -unless Kernel.respond_to?(:silence_stream) - require "webrat/selenium/silence_stream" -end - +require "webrat/selenium/silence_stream" require "webrat/selenium/selenium_session" require "webrat/selenium/matchers" require "webrat/core_extensions/tcp_socket" diff --git a/lib/webrat/selenium/location_strategy_javascript/button.js b/lib/webrat/selenium/location_strategy_javascript/button.js index add1679..1af6900 100644 --- a/lib/webrat/selenium/location_strategy_javascript/button.js +++ b/lib/webrat/selenium/location_strategy_javascript/button.js @@ -1,12 +1,19 @@ if (locator == '*') { return selenium.browserbot.locationStrategies['xpath'].call(this, "//input[@type='submit']", inDocument, inWindow) } +var buttons = inDocument.getElementsByTagName('button'); var inputs = inDocument.getElementsByTagName('input'); -return $A(inputs).find(function(candidate){ - inputType = candidate.getAttribute('type'); - if (inputType == 'submit' || inputType == 'image') { - var buttonText = $F(candidate); - return (PatternMatcher.matches(locator, buttonText)); - } - return false; +var result = $A(inputs).concat($A(buttons)).find(function(candidate){ + var type = candidate.getAttribute('type'); + if (type == 'submit' || type == 'image' || type == 'button') { + var matches_id = PatternMatcher.matches(locator, candidate.id); + var matches_value = PatternMatcher.matches(locator, candidate.value); + var matches_html = PatternMatcher.matches(locator, candidate.innerHTML); + var matches_alt = PatternMatcher.matches(locator, candidate.alt); + if (matches_id || matches_value || matches_html || matches_alt) { + return true; + } + } + return false; }); +return result; diff --git a/lib/webrat/selenium/location_strategy_javascript/webratlink.js b/lib/webrat/selenium/location_strategy_javascript/webratlink.js index ad71957..2a36308 100644 --- a/lib/webrat/selenium/location_strategy_javascript/webratlink.js +++ b/lib/webrat/selenium/location_strategy_javascript/webratlink.js @@ -1,6 +1,9 @@ var links = inDocument.getElementsByTagName('a'); var candidateLinks = $A(links).select(function(candidateLink) { - return PatternMatcher.matches(locator, getText(candidateLink)); + var textMatched = PatternMatcher.matches(locator, getText(candidateLink)); + var idMatched = PatternMatcher.matches(locator, candidateLink.id); + var titleMatched = PatternMatcher.matches(locator, candidateLink.title); + return textMatched || idMatched || titleMatched; }); if (candidateLinks.length == 0) { return null; diff --git a/lib/webrat/selenium/selenium_session.rb b/lib/webrat/selenium/selenium_session.rb index 0130b5e..0fce80b 100644 --- a/lib/webrat/selenium/selenium_session.rb +++ b/lib/webrat/selenium/selenium_session.rb @@ -41,7 +41,7 @@ module Webrat webrat_deprecate :visits, :visit def fill_in(field_identifier, options) - locator = "webrat=#{Regexp.escape(field_identifier)}" + locator = "webrat=#{field_identifier}" selenium.wait_for_element locator, :timeout_in_seconds => 5 selenium.type(locator, "#{options[:with]}") end diff --git a/lib/webrat/selenium/silence_stream.rb b/lib/webrat/selenium/silence_stream.rb index a458306..f5e54d8 100644 --- a/lib/webrat/selenium/silence_stream.rb +++ b/lib/webrat/selenium/silence_stream.rb @@ -1,14 +1,18 @@ module Webrat module Selenium module SilenceStream - def silence_stream(stream) - old_stream = stream.dup - stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null') - stream.sync = true - yield - ensure - stream.reopen(old_stream) - end + # active_support already defines silence_stream, no need to do that again if it's already present. + # http://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/kernel/reporting.rb + unless Kernel.respond_to?(:silence_stream) + def silence_stream(stream) + old_stream = stream.dup + stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null') + stream.sync = true + yield + ensure + stream.reopen(old_stream) + end + end end end end \ No newline at end of file diff --git a/spec/integration/rails/app/controllers/buttons_controller.rb b/spec/integration/rails/app/controllers/buttons_controller.rb new file mode 100644 index 0000000..c549d1f --- /dev/null +++ b/spec/integration/rails/app/controllers/buttons_controller.rb @@ -0,0 +1,7 @@ +class ButtonsController < ApplicationController + def show + end + def create + render :text => "success" + end +end diff --git a/spec/integration/rails/app/controllers/fields_controller.rb b/spec/integration/rails/app/controllers/fields_controller.rb new file mode 100644 index 0000000..454f153 --- /dev/null +++ b/spec/integration/rails/app/controllers/fields_controller.rb @@ -0,0 +1,4 @@ +class FieldsController < ApplicationController + def show + end +end diff --git a/spec/integration/rails/app/controllers/links_controller.rb b/spec/integration/rails/app/controllers/links_controller.rb new file mode 100644 index 0000000..18860c2 --- /dev/null +++ b/spec/integration/rails/app/controllers/links_controller.rb @@ -0,0 +1,7 @@ +class LinksController < ApplicationController + def show + if params[:value] + render :text => "Link:#{params[:value]}" + end + end +end diff --git a/spec/integration/rails/app/controllers/webrat_controller.rb b/spec/integration/rails/app/controllers/webrat_controller.rb index b117ae8..d754ca7 100644 --- a/spec/integration/rails/app/controllers/webrat_controller.rb +++ b/spec/integration/rails/app/controllers/webrat_controller.rb @@ -5,35 +5,35 @@ class FakeModel end class WebratController < ApplicationController - + def form end - + def submit render :text => "OK Test Link Text" end - + def internal_redirect redirect_to submit_path end - + def infinite_redirect redirect_to infinite_redirect_path end - + def external_redirect redirect_to "http://google.com" end - + def before_redirect_form end - + def redirect_to_show_params redirect_to show_params_path(:custom_param => "123") end - + def show_params render :text => params.to_json end - + end diff --git a/spec/integration/rails/app/helpers/buttons_helper.rb b/spec/integration/rails/app/helpers/buttons_helper.rb new file mode 100644 index 0000000..d8fa3c2 --- /dev/null +++ b/spec/integration/rails/app/helpers/buttons_helper.rb @@ -0,0 +1,2 @@ +module ButtonsHelper +end diff --git a/spec/integration/rails/app/helpers/fields_helper.rb b/spec/integration/rails/app/helpers/fields_helper.rb new file mode 100644 index 0000000..3be7aea --- /dev/null +++ b/spec/integration/rails/app/helpers/fields_helper.rb @@ -0,0 +1,2 @@ +module FieldsHelper +end diff --git a/spec/integration/rails/app/helpers/links_helper.rb b/spec/integration/rails/app/helpers/links_helper.rb new file mode 100644 index 0000000..f6bc988 --- /dev/null +++ b/spec/integration/rails/app/helpers/links_helper.rb @@ -0,0 +1,2 @@ +module LinksHelper +end diff --git a/spec/integration/rails/app/views/buttons/show.html.erb b/spec/integration/rails/app/views/buttons/show.html.erb new file mode 100644 index 0000000..7375623 --- /dev/null +++ b/spec/integration/rails/app/views/buttons/show.html.erb @@ -0,0 +1,11 @@ +