whitespace changes

This commit is contained in:
Mike Gaffney 2009-06-04 12:18:31 -05:00
parent e46df8c6f9
commit f3a12adaa9
11 changed files with 85 additions and 85 deletions

View File

@ -53,7 +53,7 @@ module Webrat
# Set the key that Selenium uses to determine the browser running. Default *firefox # Set the key that Selenium uses to determine the browser running. Default *firefox
attr_accessor :selenium_browser_key attr_accessor :selenium_browser_key
# Set the timeout for waiting for the browser process to start # Set the timeout for waiting for the browser process to start
attr_accessor :selenium_browser_startup_timeout attr_accessor :selenium_browser_startup_timeout

View File

@ -2,7 +2,7 @@ module Webrat
module Selenium module Selenium
class ApplicationServer class ApplicationServer
include Webrat::Selenium::SilenceStream include Webrat::Selenium::SilenceStream
def self.boot def self.boot

View File

@ -2,7 +2,7 @@ module Webrat
module Selenium module Selenium
class SeleniumRCServer class SeleniumRCServer
include Webrat::Selenium::SilenceStream include Webrat::Selenium::SilenceStream
def self.boot def self.boot
@ -32,8 +32,8 @@ module Webrat
def remote_control def remote_control
return @remote_control if @remote_control return @remote_control if @remote_control
@remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", @remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0",
Webrat.configuration.selenium_server_port, Webrat.configuration.selenium_server_port,
Webrat.configuration.selenium_browser_startup_timeout) Webrat.configuration.selenium_browser_startup_timeout)
@remote_control.jar_file = jar_path @remote_control.jar_file = jar_path

View File

@ -5,61 +5,61 @@ require "webrat/selenium/application_server"
module Webrat module Webrat
class TimeoutError < WebratError class TimeoutError < WebratError
end end
class SeleniumResponse class SeleniumResponse
attr_reader :body attr_reader :body
attr_reader :session attr_reader :session
def initialize(session, body) def initialize(session, body)
@session = session @session = session
@body = body @body = body
end end
def selenium def selenium
session.selenium session.selenium
end end
end end
class SeleniumSession class SeleniumSession
include Webrat::SaveAndOpenPage include Webrat::SaveAndOpenPage
include Webrat::Selenium::SilenceStream include Webrat::Selenium::SilenceStream
def initialize(*args) # :nodoc: def initialize(*args) # :nodoc:
end end
def simulate def simulate
end end
def automate def automate
yield yield
end end
def visit(url) def visit(url)
selenium.open(url) selenium.open(url)
end end
webrat_deprecate :visits, :visit webrat_deprecate :visits, :visit
def fill_in(field_identifier, options) def fill_in(field_identifier, options)
locator = "webrat=#{field_identifier}" locator = "webrat=#{field_identifier}"
selenium.wait_for_element locator, :timeout_in_seconds => 5 selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.type(locator, "#{options[:with]}") selenium.type(locator, "#{options[:with]}")
end end
webrat_deprecate :fills_in, :fill_in webrat_deprecate :fills_in, :fill_in
def response def response
SeleniumResponse.new(self, response_body) SeleniumResponse.new(self, response_body)
end end
def response_body #:nodoc: def response_body #:nodoc:
selenium.get_html_source selenium.get_html_source
end end
def current_url def current_url
selenium.location selenium.location
end end
def click_button(button_text_or_regexp = nil, options = {}) def click_button(button_text_or_regexp = nil, options = {})
if button_text_or_regexp.is_a?(Hash) && options == {} if button_text_or_regexp.is_a?(Hash) && options == {}
pattern, options = nil, button_text_or_regexp pattern, options = nil, button_text_or_regexp
@ -68,159 +68,159 @@ module Webrat
end end
pattern ||= '*' pattern ||= '*'
locator = "button=#{pattern}" locator = "button=#{pattern}"
selenium.wait_for_element locator, :timeout_in_seconds => 5 selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.click locator selenium.click locator
end end
webrat_deprecate :clicks_button, :click_button webrat_deprecate :clicks_button, :click_button
def click_link(link_text_or_regexp, options = {}) def click_link(link_text_or_regexp, options = {})
pattern = adjust_if_regexp(link_text_or_regexp) pattern = adjust_if_regexp(link_text_or_regexp)
locator = "webratlink=#{pattern}" locator = "webratlink=#{pattern}"
selenium.wait_for_element locator, :timeout_in_seconds => 5 selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.click locator selenium.click locator
end end
webrat_deprecate :clicks_link, :click_link webrat_deprecate :clicks_link, :click_link
def click_link_within(selector, link_text, options = {}) def click_link_within(selector, link_text, options = {})
locator = "webratlinkwithin=#{selector}|#{link_text}" locator = "webratlinkwithin=#{selector}|#{link_text}"
selenium.wait_for_element locator, :timeout_in_seconds => 5 selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.click locator selenium.click locator
end end
webrat_deprecate :clicks_link_within, :click_link_within webrat_deprecate :clicks_link_within, :click_link_within
def select(option_text, options = {}) def select(option_text, options = {})
id_or_name_or_label = options[:from] id_or_name_or_label = options[:from]
if id_or_name_or_label if id_or_name_or_label
select_locator = "webrat=#{id_or_name_or_label}" select_locator = "webrat=#{id_or_name_or_label}"
else else
select_locator = "webratselectwithoption=#{option_text}" select_locator = "webratselectwithoption=#{option_text}"
end end
selenium.wait_for_element select_locator, :timeout_in_seconds => 5 selenium.wait_for_element select_locator, :timeout_in_seconds => 5
selenium.select(select_locator, option_text) selenium.select(select_locator, option_text)
end end
webrat_deprecate :selects, :select webrat_deprecate :selects, :select
def choose(label_text) def choose(label_text)
locator = "webrat=#{label_text}" locator = "webrat=#{label_text}"
selenium.wait_for_element locator, :timeout_in_seconds => 5 selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.click locator selenium.click locator
end end
webrat_deprecate :chooses, :choose webrat_deprecate :chooses, :choose
def check(label_text) def check(label_text)
locator = "webrat=#{label_text}" locator = "webrat=#{label_text}"
selenium.wait_for_element locator, :timeout_in_seconds => 5 selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.click locator selenium.click locator
end end
alias_method :uncheck, :check alias_method :uncheck, :check
webrat_deprecate :checks, :check webrat_deprecate :checks, :check
def fire_event(field_identifier, event) def fire_event(field_identifier, event)
locator = "webrat=#{Regexp.escape(field_identifier)}" locator = "webrat=#{Regexp.escape(field_identifier)}"
selenium.fire_event(locator, "#{event}") selenium.fire_event(locator, "#{event}")
end end
def key_down(field_identifier, key_code) def key_down(field_identifier, key_code)
locator = "webrat=#{Regexp.escape(field_identifier)}" locator = "webrat=#{Regexp.escape(field_identifier)}"
selenium.key_down(locator, key_code) selenium.key_down(locator, key_code)
end end
def key_up(field_identifier, key_code) def key_up(field_identifier, key_code)
locator = "webrat=#{Regexp.escape(field_identifier)}" locator = "webrat=#{Regexp.escape(field_identifier)}"
selenium.key_up(locator, key_code) selenium.key_up(locator, key_code)
end end
def wait_for(params={}) def wait_for(params={})
timeout = params[:timeout] || 5 timeout = params[:timeout] || 5
message = params[:message] || "Timeout exceeded" message = params[:message] || "Timeout exceeded"
begin_time = Time.now begin_time = Time.now
while (Time.now - begin_time) < timeout while (Time.now - begin_time) < timeout
value = nil value = nil
begin begin
value = yield value = yield
rescue Exception => e rescue Exception => e
raise e unless yieldable_exceptions.include?(e.class) raise e unless yieldable_exceptions.include?(e.class)
end end
return value if value return value if value
sleep 0.25 sleep 0.25
end end
raise Webrat::TimeoutError.new(message + " (after #{timeout} sec)") raise Webrat::TimeoutError.new(message + " (after #{timeout} sec)")
true true
end end
def selenium def selenium
return $browser if $browser return $browser if $browser
setup setup
$browser $browser
end end
webrat_deprecate :browser, :selenium webrat_deprecate :browser, :selenium
def save_and_open_screengrab def save_and_open_screengrab
return unless File.exist?(saved_page_dir) return unless File.exist?(saved_page_dir)
filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.png" filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.png"
if $browser.chrome_backend? if $browser.chrome_backend?
$browser.capture_entire_page_screenshot(filename, '') $browser.capture_entire_page_screenshot(filename, '')
else else
$browser.capture_screenshot(filename) $browser.capture_screenshot(filename)
end end
open_in_browser(filename) open_in_browser(filename)
end end
def yieldable_exceptions def yieldable_exceptions
return [::Selenium::CommandError, Webrat::WebratError] unless lib_defined?(::Spec::Expectations::ExpectationNotMetError) return [::Selenium::CommandError, Webrat::WebratError] unless lib_defined?(::Spec::Expectations::ExpectationNotMetError)
[::Spec::Expectations::ExpectationNotMetError, ::Selenium::CommandError, Webrat::WebratError] [::Spec::Expectations::ExpectationNotMetError, ::Selenium::CommandError, Webrat::WebratError]
end end
protected protected
def lib_defined?(library) def lib_defined?(library)
defined?(library) defined?(library)
end end
def setup #:nodoc: def setup #:nodoc:
Webrat::Selenium::SeleniumRCServer.boot Webrat::Selenium::SeleniumRCServer.boot
Webrat::Selenium::ApplicationServer.boot Webrat::Selenium::ApplicationServer.boot
create_browser create_browser
$browser.start $browser.start
extend_selenium extend_selenium
define_location_strategies define_location_strategies
$browser.window_maximize $browser.window_maximize
end end
def create_browser def create_browser
$browser = ::Selenium::Client::Driver.new(Webrat.configuration.selenium_server_address || "localhost", $browser = ::Selenium::Client::Driver.new(Webrat.configuration.selenium_server_address || "localhost",
Webrat.configuration.selenium_server_port, Webrat.configuration.selenium_browser_key, "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port}") Webrat.configuration.selenium_server_port, Webrat.configuration.selenium_browser_key, "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port}")
$browser.set_speed(0) unless Webrat.configuration.selenium_server_address $browser.set_speed(0) unless Webrat.configuration.selenium_server_address
at_exit do at_exit do
silence_stream(STDOUT) do silence_stream(STDOUT) do
$browser.stop $browser.stop
end end
end end
end end
def adjust_if_regexp(text_or_regexp) #:nodoc: def adjust_if_regexp(text_or_regexp) #:nodoc:
if text_or_regexp.is_a?(Regexp) if text_or_regexp.is_a?(Regexp)
"evalregex:#{text_or_regexp.inspect}" "evalregex:#{text_or_regexp.inspect}"
@ -228,13 +228,13 @@ module Webrat
"evalregex:/#{text_or_regexp}/" "evalregex:/#{text_or_regexp}/"
end end
end end
def extend_selenium #:nodoc: def extend_selenium #:nodoc:
extensions_file = File.join(File.dirname(__FILE__), "selenium_extensions.js") extensions_file = File.join(File.dirname(__FILE__), "selenium_extensions.js")
extenions_js = File.read(extensions_file) extenions_js = File.read(extensions_file)
selenium.get_eval(extenions_js) selenium.get_eval(extenions_js)
end end
def define_location_strategies #:nodoc: def define_location_strategies #:nodoc:
Dir[File.join(File.dirname(__FILE__), "location_strategy_javascript", "*.js")].sort.each do |file| Dir[File.join(File.dirname(__FILE__), "location_strategy_javascript", "*.js")].sort.each do |file|
strategy_js = File.read(file) strategy_js = File.read(file)

View File

@ -12,7 +12,7 @@ module Webrat
ensure ensure
stream.reopen(old_stream) stream.reopen(old_stream)
end end
end end
end end
end end
end end

View File

@ -5,35 +5,35 @@ class FakeModel
end end
class WebratController < ApplicationController class WebratController < ApplicationController
def form def form
end end
def submit def submit
render :text => "OK <a href='/' id='link_id'>Test Link Text</a>" render :text => "OK <a href='/' id='link_id'>Test Link Text</a>"
end end
def internal_redirect def internal_redirect
redirect_to submit_path redirect_to submit_path
end end
def infinite_redirect def infinite_redirect
redirect_to infinite_redirect_path redirect_to infinite_redirect_path
end end
def external_redirect def external_redirect
redirect_to "http://google.com" redirect_to "http://google.com"
end end
def before_redirect_form def before_redirect_form
end end
def redirect_to_show_params def redirect_to_show_params
redirect_to show_params_path(:custom_param => "123") redirect_to show_params_path(:custom_param => "123")
end end
def show_params def show_params
render :text => params.to_json render :text => params.to_json
end end
end end

View File

@ -42,7 +42,7 @@ class ButtonClickTest < ActionController::IntegrationTest
visit buttons_path visit buttons_path
click_button "button_image_text" click_button "button_image_text"
end end
# <input type="button" ...> # <input type="button" ...>
test "should click image with type button by id" do test "should click image with type button by id" do
visit buttons_path visit buttons_path
@ -76,5 +76,5 @@ class ButtonClickTest < ActionController::IntegrationTest
visit buttons_path visit buttons_path
click_button "input_image_alt" click_button "input_image_alt"
end end
end end

View File

@ -12,7 +12,7 @@ class LinkClickTest < ActionController::IntegrationTest
click_link "link_by_id" click_link "link_by_id"
assert_contain("Link:link_by_id") assert_contain("Link:link_by_id")
end end
test "should click link by title" do test "should click link by title" do
visit links_path visit links_path
click_link "LinkByTitle" click_link "LinkByTitle"

View File

@ -92,11 +92,11 @@ describe Webrat::Configuration do
it 'should default selenium browser key to *firefox' do it 'should default selenium browser key to *firefox' do
@config.selenium_browser_key.should == '*firefox' @config.selenium_browser_key.should == '*firefox'
end end
it 'should default selenium browser startup timeout to 5 seconds' do it 'should default selenium browser startup timeout to 5 seconds' do
@config.selenium_browser_startup_timeout.should == 5 @config.selenium_browser_startup_timeout.should == 5
end end
it 'should allow overriding of the browser startup timeout' do it 'should allow overriding of the browser startup timeout' do
@config.selenium_browser_startup_timeout = 10 @config.selenium_browser_startup_timeout = 10
@config.selenium_browser_startup_timeout.should == 10 @config.selenium_browser_startup_timeout.should == 10

View File

@ -94,7 +94,7 @@ describe "have_xpath" do
node.should have_xpath("//a[@href='http://example.org']") node.should have_xpath("//a[@href='http://example.org']")
end end
end end
it "should allow descendant selectors in the block" do it "should allow descendant selectors in the block" do
@body.should have_xpath("//div[@id='main']") do |node| @body.should have_xpath("//div[@id='main']") do |node|
node.should have_xpath("//ul//a") node.should have_xpath("//ul//a")

View File

@ -4,22 +4,22 @@ require "webrat/selenium/silence_stream"
require "webrat/selenium/selenium_session" require "webrat/selenium/selenium_session"
describe Webrat::SeleniumSession do describe Webrat::SeleniumSession do
before :each do before :each do
Webrat.configuration.mode = :selenium Webrat.configuration.mode = :selenium
@selenium = Webrat::SeleniumSession.new() @selenium = Webrat::SeleniumSession.new()
end end
it "should provide a list yieldable exceptions without spec if spec isn't defined" do it "should provide a list yieldable exceptions without spec if spec isn't defined" do
@selenium.should_receive(:lib_defined?).with(::Spec::Expectations::ExpectationNotMetError).and_return(false) @selenium.should_receive(:lib_defined?).with(::Spec::Expectations::ExpectationNotMetError).and_return(false)
@selenium.yieldable_exceptions.should == [::Selenium::CommandError, Webrat::WebratError] @selenium.yieldable_exceptions.should == [::Selenium::CommandError, Webrat::WebratError]
end end
it "should provide a list yieldable exceptions with rspec" do it "should provide a list yieldable exceptions with rspec" do
@selenium.should_receive(:lib_defined?).with(::Spec::Expectations::ExpectationNotMetError).and_return(true) @selenium.should_receive(:lib_defined?).with(::Spec::Expectations::ExpectationNotMetError).and_return(true)
@selenium.yieldable_exceptions.should == [::Spec::Expectations::ExpectationNotMetError, ::Selenium::CommandError, Webrat::WebratError] @selenium.yieldable_exceptions.should == [::Spec::Expectations::ExpectationNotMetError, ::Selenium::CommandError, Webrat::WebratError]
end end
it "should throw timeout instead of spec expectionnotmet error" do it "should throw timeout instead of spec expectionnotmet error" do
begin begin
@selenium.wait_for(:timeout => 0.1) do @selenium.wait_for(:timeout => 0.1) do
@ -29,7 +29,7 @@ describe Webrat::SeleniumSession do
rescue Webrat::TimeoutError rescue Webrat::TimeoutError
end end
end end
it "should throw timeout instead of selenium command error" do it "should throw timeout instead of selenium command error" do
begin begin
@selenium.wait_for(:timeout => 0.1) do @selenium.wait_for(:timeout => 0.1) do
@ -39,7 +39,7 @@ describe Webrat::SeleniumSession do
rescue Webrat::TimeoutError rescue Webrat::TimeoutError
end end
end end
it "should throw timeout instead of webrat error" do it "should throw timeout instead of webrat error" do
begin begin
@selenium.wait_for(:timeout => 0.1) do @selenium.wait_for(:timeout => 0.1) do
@ -49,5 +49,5 @@ describe Webrat::SeleniumSession do
rescue Webrat::TimeoutError rescue Webrat::TimeoutError
end end
end end
end end