jwilger-webrat 0.4.3.4 → 0.4.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/History.txt +34 -0
  2. data/Rakefile +16 -3
  3. data/lib/webrat/core/configuration.rb +9 -16
  4. data/lib/webrat/core/elements/area.rb +7 -7
  5. data/lib/webrat/core/elements/element.rb +11 -11
  6. data/lib/webrat/core/elements/field.rb +50 -50
  7. data/lib/webrat/core/elements/form.rb +17 -17
  8. data/lib/webrat/core/elements/label.rb +6 -6
  9. data/lib/webrat/core/elements/link.rb +13 -11
  10. data/lib/webrat/core/elements/select_option.rb +9 -9
  11. data/lib/webrat/core/locators/area_locator.rb +10 -10
  12. data/lib/webrat/core/locators/button_locator.rb +13 -13
  13. data/lib/webrat/core/locators/field_by_id_locator.rb +8 -8
  14. data/lib/webrat/core/locators/field_labeled_locator.rb +11 -11
  15. data/lib/webrat/core/locators/field_locator.rb +7 -7
  16. data/lib/webrat/core/locators/field_named_locator.rb +10 -10
  17. data/lib/webrat/core/locators/form_locator.rb +6 -6
  18. data/lib/webrat/core/locators/label_locator.rb +9 -9
  19. data/lib/webrat/core/locators/link_locator.rb +12 -12
  20. data/lib/webrat/core/locators/locator.rb +5 -5
  21. data/lib/webrat/core/locators/select_option_locator.rb +11 -11
  22. data/lib/webrat/core/locators.rb +2 -2
  23. data/lib/webrat/core/logging.rb +7 -4
  24. data/lib/webrat/core/matchers/have_content.rb +12 -12
  25. data/lib/webrat/core/matchers/have_selector.rb +9 -9
  26. data/lib/webrat/core/matchers/have_tag.rb +4 -4
  27. data/lib/webrat/core/matchers/have_xpath.rb +24 -24
  28. data/lib/webrat/core/methods.rb +14 -10
  29. data/lib/webrat/core/mime.rb +3 -3
  30. data/lib/webrat/core/save_and_open_page.rb +9 -9
  31. data/lib/webrat/core/scope.rb +54 -52
  32. data/lib/webrat/core/session.rb +20 -13
  33. data/lib/webrat/core/xml/hpricot.rb +3 -3
  34. data/lib/webrat/core/xml/nokogiri.rb +11 -11
  35. data/lib/webrat/core/xml/rexml.rb +3 -3
  36. data/lib/webrat/core/xml.rb +16 -16
  37. data/lib/webrat/core_extensions/blank.rb +1 -1
  38. data/lib/webrat/core_extensions/deprecate.rb +1 -1
  39. data/lib/webrat/core_extensions/detect_mapped.rb +4 -4
  40. data/lib/webrat/core_extensions/meta_class.rb +1 -1
  41. data/lib/webrat/core_extensions/tcp_socket.rb +27 -0
  42. data/lib/webrat/mechanize.rb +9 -9
  43. data/lib/webrat/merb.rb +1 -1
  44. data/lib/webrat/merb_session.rb +10 -10
  45. data/lib/webrat/rack_test.rb +32 -0
  46. data/lib/webrat/rails.rb +2 -2
  47. data/lib/webrat/rspec-rails.rb +2 -2
  48. data/lib/webrat/selenium/application_server.rb +75 -0
  49. data/lib/webrat/selenium/matchers/have_content.rb +4 -4
  50. data/lib/webrat/selenium/matchers/have_selector.rb +4 -4
  51. data/lib/webrat/selenium/matchers/have_tag.rb +16 -16
  52. data/lib/webrat/selenium/matchers/have_xpath.rb +4 -4
  53. data/lib/webrat/selenium/matchers.rb +1 -1
  54. data/lib/webrat/selenium/merb_application_server.rb +50 -0
  55. data/lib/webrat/selenium/rails_application_server.rb +44 -0
  56. data/lib/webrat/selenium/selenium_rc_server.rb +90 -0
  57. data/lib/webrat/selenium/selenium_session.rb +22 -31
  58. data/lib/webrat/selenium/silence_stream.rb +14 -0
  59. data/lib/webrat/selenium/sinatra_application_server.rb +37 -0
  60. data/lib/webrat/selenium.rb +5 -81
  61. data/lib/webrat.rb +8 -11
  62. metadata +10 -2
@@ -1,4 +1,6 @@
1
1
  require "webrat/core/save_and_open_page"
2
+ require "webrat/selenium/selenium_rc_server"
3
+ require "webrat/selenium/application_server"
2
4
 
3
5
  module Webrat
4
6
  class TimeoutError < WebratError
@@ -20,6 +22,7 @@ module Webrat
20
22
 
21
23
  class SeleniumSession
22
24
  include Webrat::SaveAndOpenPage
25
+ include Webrat::Selenium::SilenceStream
23
26
 
24
27
  def initialize(*args) # :nodoc:
25
28
  end
@@ -31,16 +34,15 @@ module Webrat
31
34
  yield
32
35
  end
33
36
 
34
- def visit(url, timeout = nil)
37
+ def visit(url)
35
38
  selenium.open(url)
36
- selenium.wait_for_page_to_load(timeout)
37
39
  end
38
40
 
39
41
  webrat_deprecate :visits, :visit
40
42
 
41
43
  def fill_in(field_identifier, options)
42
44
  locator = "webrat=#{Regexp.escape(field_identifier)}"
43
- selenium.wait_for_element locator, Webrat.configuration.selenium_server_timeout
45
+ selenium.wait_for_element locator, :timeout_in_seconds => 5
44
46
  selenium.type(locator, "#{options[:with]}")
45
47
  end
46
48
 
@@ -54,6 +56,10 @@ module Webrat
54
56
  selenium.get_html_source
55
57
  end
56
58
 
59
+ def current_url
60
+ selenium.location
61
+ end
62
+
57
63
  def click_button(button_text_or_regexp = nil, options = {})
58
64
  if button_text_or_regexp.is_a?(Hash) && options == {}
59
65
  pattern, options = nil, button_text_or_regexp
@@ -63,7 +69,7 @@ module Webrat
63
69
  pattern ||= '*'
64
70
  locator = "button=#{pattern}"
65
71
 
66
- selenium.wait_for_element locator, Webrat.configuration.selenium_server_timeout
72
+ selenium.wait_for_element locator, :timeout_in_seconds => 5
67
73
  selenium.click locator
68
74
  end
69
75
 
@@ -72,7 +78,7 @@ module Webrat
72
78
  def click_link(link_text_or_regexp, options = {})
73
79
  pattern = adjust_if_regexp(link_text_or_regexp)
74
80
  locator = "webratlink=#{pattern}"
75
- selenium.wait_for_element locator, Webrat.configuration.selenium_server_timeout
81
+ selenium.wait_for_element locator, :timeout_in_seconds => 5
76
82
  selenium.click locator
77
83
  end
78
84
 
@@ -80,7 +86,7 @@ module Webrat
80
86
 
81
87
  def click_link_within(selector, link_text, options = {})
82
88
  locator = "webratlinkwithin=#{selector}|#{link_text}"
83
- selenium.wait_for_element locator, Webrat.configuration.selenium_server_timeout
89
+ selenium.wait_for_element locator, :timeout_in_seconds => 5
84
90
  selenium.click locator
85
91
  end
86
92
 
@@ -95,7 +101,7 @@ module Webrat
95
101
  select_locator = "webratselectwithoption=#{option_text}"
96
102
  end
97
103
 
98
- selenium.wait_for_element select_locator, Webrat.configuration.selenium_server_timeout
104
+ selenium.wait_for_element select_locator, :timeout_in_seconds => 5
99
105
  selenium.select(select_locator, option_text)
100
106
  end
101
107
 
@@ -103,7 +109,7 @@ module Webrat
103
109
 
104
110
  def choose(label_text)
105
111
  locator = "webrat=#{label_text}"
106
- selenium.wait_for_element locator, Webrat.configuration.selenium_server_timeout
112
+ selenium.wait_for_element locator, :timeout_in_seconds => 5
107
113
  selenium.click locator
108
114
  end
109
115
 
@@ -111,7 +117,7 @@ module Webrat
111
117
 
112
118
  def check(label_text)
113
119
  locator = "webrat=#{label_text}"
114
- selenium.wait_for_element locator, Webrat.configuration.selenium_server_timeout
120
+ selenium.wait_for_element locator, :timeout_in_seconds => 5
115
121
  selenium.click locator
116
122
  end
117
123
  alias_method :uncheck, :check
@@ -134,7 +140,7 @@ module Webrat
134
140
  end
135
141
 
136
142
  def wait_for(params={})
137
- timeout = params[:timeout] || Webrat.configuration.selenium_server_timeout
143
+ timeout = params[:timeout] || 5
138
144
  message = params[:message] || "Timeout exceeded"
139
145
 
140
146
  begin_time = Time.now
@@ -180,26 +186,13 @@ module Webrat
180
186
  end
181
187
 
182
188
  protected
183
- def silence_stream(stream)
184
- old_stream = stream.dup
185
- stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
186
- stream.sync = true
187
- yield
188
- ensure
189
- stream.reopen(old_stream)
190
- end
191
189
 
192
190
  def setup #:nodoc:
193
- silence_stream(STDOUT) do
194
- silence_stream(STDERR) do
195
- Webrat.start_selenium_server
196
- Webrat.start_app_server
197
- end
198
- end
191
+ Webrat::Selenium::SeleniumRCServer.boot
192
+ Webrat::Selenium::ApplicationServer.boot
199
193
 
200
194
  create_browser
201
195
  $browser.start
202
- teardown_at_exit
203
196
 
204
197
  extend_selenium
205
198
  define_location_strategies
@@ -211,14 +204,12 @@ module Webrat
211
204
  $browser = ::Selenium::Client::Driver.new(Webrat.configuration.selenium_server_address || "localhost",
212
205
  Webrat.configuration.selenium_server_port, Webrat.configuration.selenium_browser_key, "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port}")
213
206
  $browser.set_speed(0) unless Webrat.configuration.selenium_server_address
214
- end
215
207
 
216
- def teardown_at_exit #:nodoc:
217
208
  at_exit do
218
- silence_stream(STDOUT) do
219
- $browser.stop
220
- Webrat.stop_app_server
221
- Webrat.stop_selenium_server
209
+ silence_stream(STDERR) do
210
+ silence_stream(STDOUT) do
211
+ $browser.stop
212
+ end
222
213
  end
223
214
  end
224
215
  end
@@ -0,0 +1,14 @@
1
+ module Webrat
2
+ module Selenium
3
+ module SilenceStream
4
+ def silence_stream(stream)
5
+ old_stream = stream.dup
6
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
7
+ stream.sync = true
8
+ yield
9
+ ensure
10
+ stream.reopen(old_stream)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ module Webrat
2
+ module Selenium
3
+
4
+ class SinatraApplicationServer < ApplicationServer
5
+
6
+ def start
7
+ fork do
8
+ File.open('rack.pid', 'w') { |fp| fp.write Process.pid }
9
+ exec 'rackup', File.expand_path(Dir.pwd + '/config.ru'), '-p', Webrat.configuration.application_port.to_s
10
+ end
11
+ end
12
+
13
+ def stop
14
+ silence_stream(STDERR) do
15
+ silence_stream(STDOUT) do
16
+ pid = File.read(pid_file)
17
+ system("kill -9 #{pid}")
18
+ FileUtils.rm_f pid_file
19
+ end
20
+ end
21
+ end
22
+
23
+ def fail
24
+ $stderr.puts
25
+ $stderr.puts
26
+ $stderr.puts "==> Failed to boot the Sinatra application server... exiting!"
27
+ exit
28
+ end
29
+
30
+ def pid_file
31
+ prepare_pid_file(Dir.pwd, 'rack.pid')
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
@@ -1,90 +1,13 @@
1
1
  require "webrat"
2
- gem "selenium-client", "=1.2.10"
2
+ gem "selenium-client", ">=1.2.14"
3
3
  require "selenium/client"
4
+
5
+ require "webrat/selenium/silence_stream"
4
6
  require "webrat/selenium/selenium_session"
5
7
  require "webrat/selenium/matchers"
8
+ require "webrat/core_extensions/tcp_socket"
6
9
 
7
10
  module Webrat
8
-
9
- def self.with_selenium_server #:nodoc:
10
- start_selenium_server
11
- yield
12
- stop_selenium_server
13
- end
14
-
15
- def self.start_selenium_server #:nodoc:
16
- unless Webrat.configuration.selenium_server_address
17
- remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0",
18
- Webrat.configuration.selenium_server_port,
19
- Webrat.configuration.selenium_server_startup_timeout)
20
- remote_control.jar_file = File.expand_path(__FILE__ + "../../../../vendor/selenium-server.jar")
21
- remote_control.additional_args = Webrat.configuration.selenium_server_args
22
- remote_control.start :background => true
23
- end
24
- TCPSocket.wait_for_service :host => (Webrat.configuration.selenium_server_address || "0.0.0.0"),
25
- :port => Webrat.configuration.selenium_server_port
26
- end
27
-
28
- def self.stop_selenium_server #:nodoc:
29
- ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5).stop unless Webrat.configuration.selenium_server_address
30
- end
31
-
32
- def self.pid_file
33
- if File.exists?('config.ru')
34
- prepare_pid_file(Dir.pwd, 'rack.pid')
35
- else
36
- prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid")
37
- end
38
- end
39
- # Start the appserver for the underlying framework to test
40
- #
41
- # Sinatra: requires a config.ru in the root of your sinatra app to use this
42
- # Merb: Attempts to use bin/merb and falls back to the system merb
43
- # Rails: Calls mongrel_rails to startup the appserver
44
- def self.start_app_server
45
- case Webrat.configuration.application_framework
46
- when :sinatra
47
- fork do
48
- File.open('rack.pid', 'w') { |fp| fp.write Process.pid }
49
- exec 'rackup', File.expand_path(Dir.pwd + '/config.ru'), '-p', Webrat.configuration.application_port.to_s
50
- end
51
- when :merb
52
- cmd = 'merb'
53
- if File.exist?('bin/merb')
54
- cmd = 'bin/merb'
55
- end
56
- system("#{cmd} -d -p #{Webrat.configuration.application_port} -e #{Webrat.configuration.application_environment}")
57
- else # rails
58
- system("mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &")
59
- end
60
- TCPSocket.wait_for_service :host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i
61
- end
62
-
63
- # Stop the appserver for the underlying framework under test
64
- #
65
- # Sinatra: Reads and kills the pid from the pid file created on startup
66
- # Merb: Reads and kills the pid from the pid file created on startup
67
- # Rails: Calls mongrel_rails stop to kill the appserver
68
- def self.stop_app_server
69
- case Webrat.configuration.application_framework
70
- when :sinatra
71
- pid = File.read('rack.pid')
72
- system("kill -9 #{pid}")
73
- FileUtils.rm_f 'rack.pid'
74
- when :merb
75
- pid = File.read("log/merb.#{Webrat.configuration.application_port}.pid")
76
- system("kill -9 #{pid}")
77
- FileUtils.rm_f "log/merb.#{Webrat.configuration.application_port}.pid"
78
- else # rails
79
- system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
80
- end
81
- end
82
-
83
- def self.prepare_pid_file(file_path, pid_file_name)
84
- FileUtils.mkdir_p File.expand_path(file_path)
85
- File.expand_path("#{file_path}/#{pid_file_name}")
86
- end
87
-
88
11
  # To use Webrat's Selenium support, you'll need the selenium-client gem installed.
89
12
  # Activate it with (for example, in your <tt>env.rb</tt>):
90
13
  #
@@ -147,6 +70,7 @@ module Webrat
147
70
  end
148
71
  end
149
72
  end
73
+
150
74
  if defined?(ActionController::IntegrationTest)
151
75
  module ActionController #:nodoc:
152
76
  IntegrationTest.class_eval do
data/lib/webrat.rb CHANGED
@@ -7,26 +7,23 @@ module Webrat
7
7
  class WebratError < StandardError
8
8
  end
9
9
 
10
- VERSION = '0.4.3.4'
10
+ VERSION = '0.4.4.2'
11
11
 
12
12
  def self.require_xml
13
- gem "nokogiri", ">= 1.0.6"
14
-
15
13
  if on_java?
16
- # We need Nokogiri's CSS to XPath support, even if using REXML and Hpricot for parsing and searching
17
- require "nokogiri/css"
18
- require "hpricot"
19
- require "rexml/document"
14
+ gem "nokogiri", ">= 1.2.4"
20
15
  else
21
- require "nokogiri"
22
- require "webrat/core/xml/nokogiri"
16
+ gem "nokogiri", ">= 1.0.6"
23
17
  end
18
+
19
+ require "nokogiri"
20
+ require "webrat/core/xml/nokogiri"
24
21
  end
25
-
22
+
26
23
  def self.on_java?
27
24
  RUBY_PLATFORM =~ /java/
28
25
  end
29
-
26
+
30
27
  end
31
28
 
32
29
  Webrat.require_xml
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwilger-webrat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3.4
4
+ version: 0.4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Helmkamp
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-24 00:00:00 -07:00
12
+ date: 2009-05-28 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -85,13 +85,16 @@ files:
85
85
  - lib/webrat/core_extensions/detect_mapped.rb
86
86
  - lib/webrat/core_extensions/meta_class.rb
87
87
  - lib/webrat/core_extensions/nil_to_param.rb
88
+ - lib/webrat/core_extensions/tcp_socket.rb
88
89
  - lib/webrat/mechanize.rb
89
90
  - lib/webrat/merb.rb
90
91
  - lib/webrat/merb_session.rb
91
92
  - lib/webrat/rack.rb
93
+ - lib/webrat/rack_test.rb
92
94
  - lib/webrat/rails.rb
93
95
  - lib/webrat/rspec-rails.rb
94
96
  - lib/webrat/selenium
97
+ - lib/webrat/selenium/application_server.rb
95
98
  - lib/webrat/selenium/location_strategy_javascript
96
99
  - lib/webrat/selenium/location_strategy_javascript/button.js
97
100
  - lib/webrat/selenium/location_strategy_javascript/label.js
@@ -105,8 +108,13 @@ files:
105
108
  - lib/webrat/selenium/matchers/have_tag.rb
106
109
  - lib/webrat/selenium/matchers/have_xpath.rb
107
110
  - lib/webrat/selenium/matchers.rb
111
+ - lib/webrat/selenium/merb_application_server.rb
112
+ - lib/webrat/selenium/rails_application_server.rb
108
113
  - lib/webrat/selenium/selenium_extensions.js
114
+ - lib/webrat/selenium/selenium_rc_server.rb
109
115
  - lib/webrat/selenium/selenium_session.rb
116
+ - lib/webrat/selenium/silence_stream.rb
117
+ - lib/webrat/selenium/sinatra_application_server.rb
110
118
  - lib/webrat/selenium.rb
111
119
  - lib/webrat/sinatra.rb
112
120
  - lib/webrat.rb