Skip to content

Commit

Permalink
Merge commit 'cornel/lh_110'
Browse files Browse the repository at this point in the history
Conflicts:
	History.txt
  • Loading branch information
brynary committed Jan 17, 2009
2 parents 9ea7d94 + 0a75799 commit 1731681
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 119 deletions.
31 changes: 16 additions & 15 deletions History.txt
Expand Up @@ -5,17 +5,18 @@
* Removed init.rb auto-require of webrat/rails
* Removed auto-require of webrat/rails when requiring webrat when RAILS_ENV is
defined

In your env.rb or test_helper.rb file, ensure you have something like:

require "webrat"

Webrat.configure do |config|
config.mode = :rails
end

* 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)
* Use Hpricot and REXML when not parsing with Nokogiri (on JRuby, for example)

Expand Down Expand Up @@ -79,9 +80,9 @@
* Fixed bug where Webrat would lose complex parameters (like foo[bar[baz]][])
in Merb due to not correctly merging Mashes. (Drew Colthorp)
* 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)
* Ensure that Webrat::MechanizeSession.request_page always uses an absolute
* Ensure that Webrat::MechanizeSession.request_page always uses an absolute
URL. (Graham Ashton)
* Strip anchor tags from URIs before passing to Rails integration session
(Noah Davis)
Expand All @@ -104,14 +105,14 @@
* 1 Minor enhancement

* Fix compatibility with Nokogiri 1.1.0 on MRI

== 0.3.2 / 2008-11-08

* 1 Minor enhancement

* 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)

== 0.3.1 / 2008-11-07

* 1 Minor enhancement
Expand All @@ -127,7 +128,7 @@
* Added experimental Selenium support (Luke Melia)
* Add have_selector, have_xpath, have_tag and contain matchers from Merb
* Switch from Hpricot to Nokogiri for XML parsing (thanks, Aaron Patterson)

* 37 Minor enhancements

* Added #within for manipulating the current page within a selector scope
Expand Down Expand Up @@ -174,7 +175,7 @@
* Switched tests to specs, and from Mocha to RSpec's mocking library
* Add support to click_button for IDs (Gwyn Morfey)
* Miscellaneous core refactorings (Jan Suchal)

* 8 Bug fixes

* Fix initialization of WWW::Mechanize (Derek Kastner)
Expand All @@ -186,7 +187,7 @@
* 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
incorrect field value (Luke Melia)

== 0.2.0 / 2008-04-04

* 4 Major enhancements
Expand All @@ -196,20 +197,20 @@
* Add basic support for Rails-generated JavaScript link tags
* Add support for checkboxes (Patches from Kyle Hargraves and Jarkko Laine)
* Add support for textarea fields (Sacha Schlegel)

* 8 Minor enhancements

* Added reloads method to reload the page (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)
* Allow specifying the input name/label when doing a select (David Chelimsky)
* Raise a specific exception if the developer tries to manipulate form elements
before loading a page (James Deville)
* Add support for alternate POST, PUT and DELETE link clicking (Kyle Hargraves)
* Change clicks_link to find the shortest matching link (Luke Melia)
* Improve matching for labels in potentially ambiguous cases

* 7 Bug fixes

* Fix incorrect serializing of collection inputs, i.e. name contains []
Expand Down
59 changes: 39 additions & 20 deletions lib/webrat/core/configuration.rb
@@ -1,60 +1,79 @@
require "webrat/core_extensions/deprecate"

module Webrat

# 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)
yield configuration if block_given?
@@configuration = configuration
end

def self.configuration # :nodoc:
@@configuration ||= Webrat::Configuration.new
end

# Webrat can be configured using the Webrat.configure method. For example:
#
#
# Webrat.configure do |config|
# config.parse_with_nokogiri = false
# end
class Configuration

# Should XHTML be parsed with Nokogiri? Defaults to true, except on JRuby. When false, Hpricot and REXML are used
attr_writer :parse_with_nokogiri

# 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.
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.
attr_accessor :selenium_port
# Which rails environment should the selenium tests be run in? Defaults to selenium.
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:
self.open_error_files = true
self.parse_with_nokogiri = !Webrat.on_java?
self.selenium_environment = :selenium
self.selenium_port = 3001
self.application_environment = :selenium
self.application_port = 3001
self.application_address = 'localhost'
self.selenium_server_port = 4444
self.selenium_browser_key = '*firefox'
end

def parse_with_nokogiri? #:nodoc:
@parse_with_nokogiri ? true : false
end

def open_error_files? #:nodoc:
@open_error_files ? true : false
end

# Allows setting of webrat's mode, valid modes are:
# :rails, :selenium, :rack, :sinatra, :mechanize, :merb
def mode=(mode)
@mode = mode
require("webrat/#{mode}")
end

end

end
31 changes: 16 additions & 15 deletions lib/webrat/selenium.rb
Expand Up @@ -5,41 +5,42 @@
require "webrat/selenium/matchers"

module Webrat

def self.with_selenium_server #:nodoc:
start_selenium_server
yield
stop_selenium_server
end

def self.start_selenium_server #:nodoc:
remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", 4444, 5)
remote_control.jar_file = File.expand_path(__FILE__ + "../../../../vendor/selenium-server.jar")
remote_control.start :background => true
TCPSocket.wait_for_service :host => "0.0.0.0", :port => 4444
unless Webrat.configuration.selenium_server_address
remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5)
remote_control.jar_file = File.expand_path(__FILE__ + "../../../../vendor/selenium-server.jar")
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

def self.stop_selenium_server #:nodoc:
remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", 4444, 5)
remote_control.stop
::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5).stop unless Webrat.configuration.selenium_server_address
end

def self.start_app_server #:nodoc:
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} &")
TCPSocket.wait_for_service :host => "0.0.0.0", :port => Webrat.configuration.selenium_port.to_i
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 => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i
end

def self.stop_app_server #:nodoc:
pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid")
system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
end

# 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>):
#
# require "webrat"
#
#
# Webrat.configure do |config|
# config.mode = :selenium
# end
Expand Down

0 comments on commit 1731681

Please sign in to comment.