Merge commit 'cornel/lh_110'
Conflicts: History.txt
This commit is contained in:
commit
1731681e79
31
History.txt
31
History.txt
@ -5,17 +5,18 @@
|
|||||||
* Removed init.rb auto-require of webrat/rails
|
* Removed init.rb auto-require of webrat/rails
|
||||||
* Removed auto-require of webrat/rails when requiring webrat when RAILS_ENV is
|
* Removed auto-require of webrat/rails when requiring webrat when RAILS_ENV is
|
||||||
defined
|
defined
|
||||||
|
|
||||||
In your env.rb or test_helper.rb file, ensure you have something like:
|
In your env.rb or test_helper.rb file, ensure you have something like:
|
||||||
|
|
||||||
require "webrat"
|
require "webrat"
|
||||||
|
|
||||||
Webrat.configure do |config|
|
Webrat.configure do |config|
|
||||||
config.mode = :rails
|
config.mode = :rails
|
||||||
end
|
end
|
||||||
|
|
||||||
* Major enhancements
|
* Major enhancements
|
||||||
|
|
||||||
|
* Added Selenium grid configuration and support. (Amos King && Cornel Borcean)
|
||||||
* Added select_time, select_date, and select_datetime to API. [#36] (Ben Mabey)
|
* Added select_time, select_date, and select_datetime to API. [#36] (Ben Mabey)
|
||||||
* Use Hpricot and REXML when not parsing with Nokogiri (on JRuby, for example)
|
* Use Hpricot and REXML when not parsing with Nokogiri (on JRuby, for example)
|
||||||
|
|
||||||
@ -79,9 +80,9 @@
|
|||||||
* Fixed bug where Webrat would lose complex parameters (like foo[bar[baz]][])
|
* Fixed bug where Webrat would lose complex parameters (like foo[bar[baz]][])
|
||||||
in Merb due to not correctly merging Mashes. (Drew Colthorp)
|
in Merb due to not correctly merging Mashes. (Drew Colthorp)
|
||||||
* Extend Rails' ActionController::IntegrationTest instead of
|
* Extend Rails' ActionController::IntegrationTest instead of
|
||||||
ActionController::Integration::Session (Fixes using Webrat's #select method and
|
ActionController::Integration::Session (Fixes using Webrat's #select method and
|
||||||
avoids usage of method_missing)
|
avoids usage of method_missing)
|
||||||
* Ensure that Webrat::MechanizeSession.request_page always uses an absolute
|
* Ensure that Webrat::MechanizeSession.request_page always uses an absolute
|
||||||
URL. (Graham Ashton)
|
URL. (Graham Ashton)
|
||||||
* Strip anchor tags from URIs before passing to Rails integration session
|
* Strip anchor tags from URIs before passing to Rails integration session
|
||||||
(Noah Davis)
|
(Noah Davis)
|
||||||
@ -104,14 +105,14 @@
|
|||||||
* 1 Minor enhancement
|
* 1 Minor enhancement
|
||||||
|
|
||||||
* Fix compatibility with Nokogiri 1.1.0 on MRI
|
* Fix compatibility with Nokogiri 1.1.0 on MRI
|
||||||
|
|
||||||
== 0.3.2 / 2008-11-08
|
== 0.3.2 / 2008-11-08
|
||||||
|
|
||||||
* 1 Minor enhancement
|
* 1 Minor enhancement
|
||||||
|
|
||||||
* Fixes behavior or have_tag when a block is passed. It passes the matched node(s)
|
* Fixes behavior or have_tag when a block is passed. It passes the matched node(s)
|
||||||
to the block for further specs again. (Carl Lerche)
|
to the block for further specs again. (Carl Lerche)
|
||||||
|
|
||||||
== 0.3.1 / 2008-11-07
|
== 0.3.1 / 2008-11-07
|
||||||
|
|
||||||
* 1 Minor enhancement
|
* 1 Minor enhancement
|
||||||
@ -127,7 +128,7 @@
|
|||||||
* Added experimental Selenium support (Luke Melia)
|
* Added experimental Selenium support (Luke Melia)
|
||||||
* Add have_selector, have_xpath, have_tag and contain matchers from Merb
|
* Add have_selector, have_xpath, have_tag and contain matchers from Merb
|
||||||
* Switch from Hpricot to Nokogiri for XML parsing (thanks, Aaron Patterson)
|
* Switch from Hpricot to Nokogiri for XML parsing (thanks, Aaron Patterson)
|
||||||
|
|
||||||
* 37 Minor enhancements
|
* 37 Minor enhancements
|
||||||
|
|
||||||
* Added #within for manipulating the current page within a selector scope
|
* Added #within for manipulating the current page within a selector scope
|
||||||
@ -174,7 +175,7 @@
|
|||||||
* Switched tests to specs, and from Mocha to RSpec's mocking library
|
* Switched tests to specs, and from Mocha to RSpec's mocking library
|
||||||
* Add support to click_button for IDs (Gwyn Morfey)
|
* Add support to click_button for IDs (Gwyn Morfey)
|
||||||
* Miscellaneous core refactorings (Jan Suchal)
|
* Miscellaneous core refactorings (Jan Suchal)
|
||||||
|
|
||||||
* 8 Bug fixes
|
* 8 Bug fixes
|
||||||
|
|
||||||
* Fix initialization of WWW::Mechanize (Derek Kastner)
|
* Fix initialization of WWW::Mechanize (Derek Kastner)
|
||||||
@ -186,7 +187,7 @@
|
|||||||
* Don't explode if encountering inputs with no type attribute (assume text)
|
* Don't explode if encountering inputs with no type attribute (assume text)
|
||||||
* Fix bug where choosing a radio button in a series with a default submitted the
|
* Fix bug where choosing a radio button in a series with a default submitted the
|
||||||
incorrect field value (Luke Melia)
|
incorrect field value (Luke Melia)
|
||||||
|
|
||||||
== 0.2.0 / 2008-04-04
|
== 0.2.0 / 2008-04-04
|
||||||
|
|
||||||
* 4 Major enhancements
|
* 4 Major enhancements
|
||||||
@ -196,12 +197,12 @@
|
|||||||
* Add basic support for Rails-generated JavaScript link tags
|
* Add basic support for Rails-generated JavaScript link tags
|
||||||
* Add support for checkboxes (Patches from Kyle Hargraves and Jarkko Laine)
|
* Add support for checkboxes (Patches from Kyle Hargraves and Jarkko Laine)
|
||||||
* Add support for textarea fields (Sacha Schlegel)
|
* Add support for textarea fields (Sacha Schlegel)
|
||||||
|
|
||||||
* 8 Minor enhancements
|
* 8 Minor enhancements
|
||||||
|
|
||||||
* Added reloads method to reload the page (Kamal Fariz Mahyuddi)
|
* Added reloads method to reload the page (Kamal Fariz Mahyuddi)
|
||||||
* Prevent making a request if clicking on local anchor link (Kamal Fariz Mahyuddi)
|
* Prevent making a request if clicking on local anchor link (Kamal Fariz Mahyuddi)
|
||||||
* Added clicks_link_within(selector, link_text), allowing restricting link search
|
* Added clicks_link_within(selector, link_text), allowing restricting link search
|
||||||
to within a given css selector (Luke Melia)
|
to within a given css selector (Luke Melia)
|
||||||
* Allow specifying the input name/label when doing a select (David Chelimsky)
|
* Allow specifying the input name/label when doing a select (David Chelimsky)
|
||||||
* Raise a specific exception if the developer tries to manipulate form elements
|
* Raise a specific exception if the developer tries to manipulate form elements
|
||||||
@ -209,7 +210,7 @@
|
|||||||
* Add support for alternate POST, PUT and DELETE link clicking (Kyle Hargraves)
|
* Add support for alternate POST, PUT and DELETE link clicking (Kyle Hargraves)
|
||||||
* Change clicks_link to find the shortest matching link (Luke Melia)
|
* Change clicks_link to find the shortest matching link (Luke Melia)
|
||||||
* Improve matching for labels in potentially ambiguous cases
|
* Improve matching for labels in potentially ambiguous cases
|
||||||
|
|
||||||
* 7 Bug fixes
|
* 7 Bug fixes
|
||||||
|
|
||||||
* Fix incorrect serializing of collection inputs, i.e. name contains []
|
* Fix incorrect serializing of collection inputs, i.e. name contains []
|
||||||
|
@ -1,60 +1,79 @@
|
|||||||
|
require "webrat/core_extensions/deprecate"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
|
|
||||||
# Configures Webrat. If this is not done, Webrat will be created
|
# Configures Webrat. If this is not done, Webrat will be created
|
||||||
# with all of the default settings.
|
# with all of the default settings.
|
||||||
def self.configure(configuration = Webrat::Configuration.new)
|
def self.configure(configuration = Webrat::Configuration.new)
|
||||||
yield configuration if block_given?
|
yield configuration if block_given?
|
||||||
@@configuration = configuration
|
@@configuration = configuration
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.configuration # :nodoc:
|
def self.configuration # :nodoc:
|
||||||
@@configuration ||= Webrat::Configuration.new
|
@@configuration ||= Webrat::Configuration.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# Webrat can be configured using the Webrat.configure method. For example:
|
# Webrat can be configured using the Webrat.configure method. For example:
|
||||||
#
|
#
|
||||||
# Webrat.configure do |config|
|
# Webrat.configure do |config|
|
||||||
# config.parse_with_nokogiri = false
|
# config.parse_with_nokogiri = false
|
||||||
# end
|
# end
|
||||||
class Configuration
|
class Configuration
|
||||||
|
|
||||||
# Should XHTML be parsed with Nokogiri? Defaults to true, except on JRuby. When false, Hpricot and REXML are used
|
# Should XHTML be parsed with Nokogiri? Defaults to true, except on JRuby. When false, Hpricot and REXML are used
|
||||||
attr_writer :parse_with_nokogiri
|
attr_writer :parse_with_nokogiri
|
||||||
|
|
||||||
# Webrat's mode, set automatically when requiring webrat/rails, webrat/merb, etc.
|
# Webrat's mode, set automatically when requiring webrat/rails, webrat/merb, etc.
|
||||||
attr_accessor :mode # :nodoc:
|
attr_reader :mode # :nodoc:
|
||||||
|
|
||||||
# Save and open pages with error status codes (500-599) in a browser? Defualts to true.
|
# Save and open pages with error status codes (500-599) in a browser? Defualts to true.
|
||||||
attr_writer :open_error_files
|
attr_writer :open_error_files
|
||||||
|
|
||||||
# Which environment should the selenium tests be run in? Defaults to selenium.
|
|
||||||
attr_accessor :selenium_environment
|
|
||||||
|
|
||||||
# Which port should the selenium tests be run on? Defaults to 3001.
|
# Which rails environment should the selenium tests be run in? Defaults to selenium.
|
||||||
attr_accessor :selenium_port
|
attr_accessor :application_environment
|
||||||
|
webrat_deprecate :selenium_environment, :application_environment
|
||||||
|
|
||||||
|
# Which port is the application running on for selenium testing? Defaults to 3001.
|
||||||
|
attr_accessor :application_port
|
||||||
|
webrat_deprecate :selenium_port, :application_port
|
||||||
|
|
||||||
|
# Which server the application is running on for selenium testing? Defaults to localhost
|
||||||
|
attr_accessor :application_address
|
||||||
|
|
||||||
|
# Which server Selenium server is running on. Defaults to nil(server starts in webrat process and runs locally)
|
||||||
|
attr_accessor :selenium_server_address
|
||||||
|
|
||||||
|
# Which server Selenium port is running on. Defaults to 4444
|
||||||
|
attr_accessor :selenium_server_port
|
||||||
|
|
||||||
|
# Set the key that Selenium uses to determine the browser running. Default *firefox
|
||||||
|
attr_accessor :selenium_browser_key
|
||||||
|
|
||||||
def initialize # :nodoc:
|
def initialize # :nodoc:
|
||||||
self.open_error_files = true
|
self.open_error_files = true
|
||||||
self.parse_with_nokogiri = !Webrat.on_java?
|
self.parse_with_nokogiri = !Webrat.on_java?
|
||||||
self.selenium_environment = :selenium
|
self.application_environment = :selenium
|
||||||
self.selenium_port = 3001
|
self.application_port = 3001
|
||||||
|
self.application_address = 'localhost'
|
||||||
|
self.selenium_server_port = 4444
|
||||||
|
self.selenium_browser_key = '*firefox'
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_with_nokogiri? #:nodoc:
|
def parse_with_nokogiri? #:nodoc:
|
||||||
@parse_with_nokogiri ? true : false
|
@parse_with_nokogiri ? true : false
|
||||||
end
|
end
|
||||||
|
|
||||||
def open_error_files? #:nodoc:
|
def open_error_files? #:nodoc:
|
||||||
@open_error_files ? true : false
|
@open_error_files ? true : false
|
||||||
end
|
end
|
||||||
|
|
||||||
# Allows setting of webrat's mode, valid modes are:
|
# Allows setting of webrat's mode, valid modes are:
|
||||||
# :rails, :selenium, :rack, :sinatra, :mechanize, :merb
|
# :rails, :selenium, :rack, :sinatra, :mechanize, :merb
|
||||||
def mode=(mode)
|
def mode=(mode)
|
||||||
@mode = mode
|
@mode = mode
|
||||||
require("webrat/#{mode}")
|
require("webrat/#{mode}")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
@ -5,41 +5,42 @@ require "webrat/selenium/selenium_session"
|
|||||||
require "webrat/selenium/matchers"
|
require "webrat/selenium/matchers"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
|
|
||||||
def self.with_selenium_server #:nodoc:
|
def self.with_selenium_server #:nodoc:
|
||||||
start_selenium_server
|
start_selenium_server
|
||||||
yield
|
yield
|
||||||
stop_selenium_server
|
stop_selenium_server
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.start_selenium_server #:nodoc:
|
def self.start_selenium_server #:nodoc:
|
||||||
remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", 4444, 5)
|
unless Webrat.configuration.selenium_server_address
|
||||||
remote_control.jar_file = File.expand_path(__FILE__ + "../../../../vendor/selenium-server.jar")
|
remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5)
|
||||||
remote_control.start :background => true
|
remote_control.jar_file = File.expand_path(__FILE__ + "../../../../vendor/selenium-server.jar")
|
||||||
TCPSocket.wait_for_service :host => "0.0.0.0", :port => 4444
|
remote_control.start :background => true
|
||||||
|
end
|
||||||
|
TCPSocket.wait_for_service :host => (Webrat.configuration.selenium_server_address || "0.0.0.0"), :port => Webrat.configuration.selenium_server_port
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.stop_selenium_server #:nodoc:
|
def self.stop_selenium_server #:nodoc:
|
||||||
remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", 4444, 5)
|
::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5).stop unless Webrat.configuration.selenium_server_address
|
||||||
remote_control.stop
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.start_app_server #:nodoc:
|
def self.start_app_server #:nodoc:
|
||||||
pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid")
|
pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid")
|
||||||
system("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=#{Webrat.configuration.selenium_port} --environment=#{Webrat.configuration.selenium_environment} --pid #{pid_file} &")
|
system("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &")
|
||||||
TCPSocket.wait_for_service :host => "0.0.0.0", :port => Webrat.configuration.selenium_port.to_i
|
TCPSocket.wait_for_service :host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.stop_app_server #:nodoc:
|
def self.stop_app_server #:nodoc:
|
||||||
pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid")
|
pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid")
|
||||||
system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
|
system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# To use Webrat's Selenium support, you'll need the selenium-client gem installed.
|
# To use Webrat's Selenium support, you'll need the selenium-client gem installed.
|
||||||
# Activate it with (for example, in your <tt>env.rb</tt>):
|
# Activate it with (for example, in your <tt>env.rb</tt>):
|
||||||
#
|
#
|
||||||
# require "webrat"
|
# require "webrat"
|
||||||
#
|
#
|
||||||
# Webrat.configure do |config|
|
# Webrat.configure do |config|
|
||||||
# config.mode = :selenium
|
# config.mode = :selenium
|
||||||
# end
|
# end
|
||||||
|
@ -3,56 +3,56 @@ require "webrat/core/save_and_open_page"
|
|||||||
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
|
||||||
|
|
||||||
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=#{Regexp.escape(field_identifier)}"
|
locator = "webrat=#{Regexp.escape(field_identifier)}"
|
||||||
selenium.wait_for_element locator, 5
|
selenium.wait_for_element locator, 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 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
|
||||||
@ -61,11 +61,11 @@ module Webrat
|
|||||||
end
|
end
|
||||||
pattern ||= '*'
|
pattern ||= '*'
|
||||||
locator = "button=#{pattern}"
|
locator = "button=#{pattern}"
|
||||||
|
|
||||||
selenium.wait_for_element locator, 5
|
selenium.wait_for_element locator, 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 = {})
|
||||||
@ -74,53 +74,53 @@ module Webrat
|
|||||||
selenium.wait_for_element locator, 5
|
selenium.wait_for_element locator, 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, 5
|
selenium.wait_for_element locator, 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, 5
|
selenium.wait_for_element select_locator, 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, 5
|
selenium.wait_for_element locator, 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, 5
|
selenium.wait_for_element locator, 5
|
||||||
selenium.check locator
|
selenium.check locator
|
||||||
end
|
end
|
||||||
|
|
||||||
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)
|
||||||
@ -130,7 +130,7 @@ module Webrat
|
|||||||
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"
|
||||||
@ -154,21 +154,21 @@ module Webrat
|
|||||||
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
|
||||||
@ -176,25 +176,31 @@ module Webrat
|
|||||||
end
|
end
|
||||||
open_in_browser(filename)
|
open_in_browser(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def setup #:nodoc:
|
def setup #:nodoc:
|
||||||
silence_stream(STDOUT) do
|
silence_stream(STDOUT) do
|
||||||
Webrat.start_selenium_server
|
Webrat.start_selenium_server
|
||||||
Webrat.start_app_server
|
Webrat.start_app_server
|
||||||
end
|
end
|
||||||
|
|
||||||
$browser = ::Selenium::Client::Driver.new("localhost", 4444, "*firefox", "http://0.0.0.0:3001")
|
create_browser
|
||||||
$browser.set_speed(0)
|
|
||||||
$browser.start
|
$browser.start
|
||||||
teardown_at_exit
|
teardown_at_exit
|
||||||
|
|
||||||
extend_selenium
|
extend_selenium
|
||||||
define_location_strategies
|
define_location_strategies
|
||||||
$browser.window_maximize
|
$browser.window_maximize
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def create_browser
|
||||||
|
$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}")
|
||||||
|
$browser.set_speed(0) unless Webrat.configuration.selenium_server_address
|
||||||
|
end
|
||||||
|
|
||||||
def teardown_at_exit #:nodoc:
|
def teardown_at_exit #:nodoc:
|
||||||
at_exit do
|
at_exit do
|
||||||
silence_stream(STDOUT) do
|
silence_stream(STDOUT) do
|
||||||
@ -204,21 +210,21 @@ module Webrat
|
|||||||
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}"
|
||||||
else
|
else
|
||||||
"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)
|
||||||
|
@ -7,53 +7,74 @@ describe Webrat::Configuration do
|
|||||||
it "should have a mode" do
|
it "should have a mode" do
|
||||||
Webrat.configuration.should respond_to(:mode)
|
Webrat.configuration.should respond_to(:mode)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should use Nokogiri as the parser by default" do
|
it "should use Nokogiri as the parser by default" do
|
||||||
Webrat.stub!(:on_java? => false)
|
Webrat.stub!(:on_java? => false)
|
||||||
config = Webrat::Configuration.new
|
config = Webrat::Configuration.new
|
||||||
config.should parse_with_nokogiri
|
config.should parse_with_nokogiri
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not use Nokogiri as the parser when on JRuby" do
|
it "should not use Nokogiri as the parser when on JRuby" do
|
||||||
Webrat.stub!(:on_java? => true)
|
Webrat.stub!(:on_java? => true)
|
||||||
config = Webrat::Configuration.new
|
config = Webrat::Configuration.new
|
||||||
config.should_not parse_with_nokogiri
|
config.should_not parse_with_nokogiri
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should open error files by default" do
|
it "should open error files by default" do
|
||||||
config = Webrat::Configuration.new
|
config = Webrat::Configuration.new
|
||||||
config.should open_error_files
|
config.should open_error_files
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should use 'selenium' as the selenium environment by default" do
|
|
||||||
config = Webrat::Configuration.new
|
|
||||||
config.selenium_environment.should == :selenium
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should use 3001 as the selenium port by default" do
|
|
||||||
config = Webrat::Configuration.new
|
|
||||||
config.selenium_port.should == 3001
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should be configurable with a block" do
|
it "should be configurable with a block" do
|
||||||
Webrat.configure do |config|
|
Webrat.configure do |config|
|
||||||
config.open_error_files = false
|
config.open_error_files = false
|
||||||
end
|
end
|
||||||
|
|
||||||
config = Webrat.configuration
|
config = Webrat.configuration
|
||||||
config.should_not open_error_files
|
config.should_not open_error_files
|
||||||
end
|
end
|
||||||
|
|
||||||
[:rails,
|
[:rails,
|
||||||
:selenium,
|
:selenium,
|
||||||
:rack,
|
:rack,
|
||||||
:sinatra,
|
:sinatra,
|
||||||
:merb,
|
:merb,
|
||||||
:mechanize].each do |mode|
|
:mechanize].each do |mode|
|
||||||
it "should require correct lib when in #{mode} mode" do
|
it "should require correct lib when in #{mode} mode" do
|
||||||
config = Webrat::Configuration.new
|
config = Webrat::Configuration.new
|
||||||
config.should_receive(:require).with("webrat/#{mode}")
|
config.should_receive(:require).with("webrat/#{mode}")
|
||||||
config.mode = mode
|
config.mode = mode
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
describe "Selenium" do
|
||||||
|
before :each do
|
||||||
|
@config = Webrat::Configuration.new
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should use 'selenium' as the application environment by default" do
|
||||||
|
@config.application_environment.should == :selenium
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should use 3001 as the application port by default" do
|
||||||
|
@config.application_port.should == 3001
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should default application address to localhost' do
|
||||||
|
@config.application_address.should == 'localhost'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should default selenium server address to nil' do
|
||||||
|
@config.selenium_server_address.should be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should default selenium server port to 4444' do
|
||||||
|
@config.selenium_server_port.should == 4444
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should default selenium browser key to *firefox' do
|
||||||
|
@config.selenium_browser_key.should == '*firefox'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
44
spec/private/selenium/selenium_session_spec.rb
Normal file
44
spec/private/selenium/selenium_session_spec.rb
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||||
|
require "action_controller"
|
||||||
|
require "action_controller/integration"
|
||||||
|
require "webrat/selenium"
|
||||||
|
|
||||||
|
describe Webrat::SeleniumSession do
|
||||||
|
|
||||||
|
describe "create browser" do
|
||||||
|
|
||||||
|
it "should start the local selenium client and set speed to 0 when selenium_server_address is nil" do
|
||||||
|
selenium_session = Webrat::SeleniumSession.new
|
||||||
|
browser = mock "mock browser"
|
||||||
|
::Selenium::Client::Driver.should_receive(:new).with("localhost", Webrat.configuration.selenium_server_port, "*firefox", "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port}").and_return browser
|
||||||
|
browser.should_receive(:set_speed).with(0)
|
||||||
|
selenium_session.send :create_browser
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should start the remote selenium client when selenium_server_address is set" do
|
||||||
|
Webrat.configuration.selenium_server_address = 'foo address'
|
||||||
|
selenium_session = Webrat::SeleniumSession.new
|
||||||
|
browser = mock "mock browser"
|
||||||
|
::Selenium::Client::Driver.should_receive(:new).with(Webrat.configuration.selenium_server_address, Webrat.configuration.selenium_server_port, "*firefox", "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port}").and_return browser
|
||||||
|
browser.should_not_receive(:set_speed)
|
||||||
|
selenium_session.send :create_browser
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should use the config specifications" do
|
||||||
|
Webrat.configuration.selenium_server_port = 'selenium port'
|
||||||
|
Webrat.configuration.selenium_server_address = 'selenium address'
|
||||||
|
Webrat.configuration.application_port = 'app port'
|
||||||
|
Webrat.configuration.application_address = 'app address'
|
||||||
|
Webrat.configuration.selenium_browser_key = 'browser key'
|
||||||
|
|
||||||
|
selenium_session = Webrat::SeleniumSession.new
|
||||||
|
browser = mock "mock browser"
|
||||||
|
::Selenium::Client::Driver.should_receive(:new).with('selenium address',
|
||||||
|
'selenium port', 'browser key',
|
||||||
|
"http://app address:app port").and_return browser
|
||||||
|
browser.should_not_receive(:set_speed)
|
||||||
|
selenium_session.send :create_browser
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
52
spec/private/selenium/selenium_spec.rb
Normal file
52
spec/private/selenium/selenium_spec.rb
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||||
|
require "action_controller"
|
||||||
|
require "action_controller/integration"
|
||||||
|
require "webrat/selenium"
|
||||||
|
|
||||||
|
RAILS_ROOT = "/"
|
||||||
|
|
||||||
|
|
||||||
|
describe Webrat, "Selenium" do
|
||||||
|
|
||||||
|
it "should start the app server with correct config options" do
|
||||||
|
pid_file = "file"
|
||||||
|
File.should_receive(:expand_path).with(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid").and_return pid_file
|
||||||
|
Webrat.should_receive(:system).with("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &")
|
||||||
|
TCPSocket.should_receive(:wait_for_service).with(:host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i)
|
||||||
|
Webrat.start_app_server
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "start_selenium_server" do
|
||||||
|
it "should not start the local selenium server if the selenium_server_address is set" do
|
||||||
|
Webrat.configuration.selenium_server_address = 'foo address'
|
||||||
|
::Selenium::RemoteControl::RemoteControl.should_not_receive(:new)
|
||||||
|
TCPSocket.should_receive(:wait_for_service).with(:host => Webrat.configuration.selenium_server_address, :port => Webrat.configuration.selenium_server_port)
|
||||||
|
Webrat.start_selenium_server
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should start the local selenium server if the selenium_server_address is set" do
|
||||||
|
remote_control = mock "selenium remote control"
|
||||||
|
::Selenium::RemoteControl::RemoteControl.should_receive(:new).with("0.0.0.0", Webrat.configuration.selenium_server_port, 5).and_return remote_control
|
||||||
|
remote_control.should_receive(:jar_file=).with(/selenium-server\.jar/)
|
||||||
|
remote_control.should_receive(:start).with(:background => true)
|
||||||
|
TCPSocket.should_receive(:wait_for_service).with(:host => "0.0.0.0", :port => Webrat.configuration.selenium_server_port)
|
||||||
|
Webrat.start_selenium_server
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "stop_selenium_server" do
|
||||||
|
|
||||||
|
it "should not attempt to stop the server if the selenium_server_address is set" do
|
||||||
|
Webrat.configuration.selenium_server_address = 'foo address'
|
||||||
|
::Selenium::RemoteControl::RemoteControl.should_not_receive(:new)
|
||||||
|
Webrat.stop_selenium_server
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should stop the local server is the selenium_server_address is nil" do
|
||||||
|
remote_control = mock "selenium remote control"
|
||||||
|
::Selenium::RemoteControl::RemoteControl.should_receive(:new).with("0.0.0.0", Webrat.configuration.selenium_server_port, 5).and_return remote_control
|
||||||
|
remote_control.should_receive(:stop)
|
||||||
|
Webrat.stop_selenium_server
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user