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
data/History.txt CHANGED
@@ -1,3 +1,37 @@
1
+ == 0.4.5 / ?
2
+
3
+ * Major enhancements
4
+
5
+ * Improve performance (~2x) on JRuby by supporting Nokogiri
6
+
7
+ * Minor enhancements
8
+
9
+ * Added support for field_labeled_locators ending in non word characters
10
+ lh 148 (Zach Dennis)
11
+ * Filled in tests on click link lh 195 (diabolo)
12
+ * Added current_url to selenium session lh 215 (Luke Amdor)
13
+ * Added silence spec to selenium lh 238 (Martin Gamsjaeger aka snusnu)
14
+ * Added ability to configure the browser startup timeout for selenium lh 242 (Mike Gaffney)
15
+
16
+ == 0.4.4 / 2009-04-06
17
+
18
+ * Major enhancements
19
+
20
+ * Make selenium process management code more robust and informative
21
+
22
+ * Minor enhancements
23
+
24
+ * Add support for Rails javascript post links (Mark Menard)
25
+ * Upgrade selenium-client dependency to 1.2.14, and update for new waiting
26
+ API (Balint Erdi)
27
+ * Change default app environment from "selenium" to "test"
28
+
29
+ * Bug fixes
30
+
31
+ * Don't create a new instance of WWW::Mechanize for each request
32
+ (Mark Menard)
33
+ * Select fields with duplicate selected options sent an incorrect value (Noah Davis)
34
+
1
35
  == 0.4.3 / 2009-03-17
2
36
 
3
37
  * Minor enhancements
data/Rakefile CHANGED
@@ -106,7 +106,7 @@ end
106
106
 
107
107
  namespace :spec do
108
108
  desc "Run the integration specs"
109
- task :integration => ["integration:rails", "integration:merb", "integration:sinatra"]
109
+ task :integration => ["integration:rails", "integration:merb", "integration:sinatra", "integration:rack"]
110
110
 
111
111
  namespace :integration do
112
112
  desc "Run the Rails integration specs"
@@ -140,7 +140,15 @@ namespace :spec do
140
140
  task :sinatra do
141
141
  Dir.chdir "spec/integration/sinatra" do
142
142
  result = system "rake test"
143
- raise "Sinatra tntegration tests failed" unless result
143
+ raise "Sinatra integration tests failed" unless result
144
+ end
145
+ end
146
+
147
+ desc "Run the Sinatra integration specs"
148
+ task :rack do
149
+ Dir.chdir "spec/integration/rack" do
150
+ result = system "rake test"
151
+ raise "Rack integration tests failed" unless result
144
152
  end
145
153
  end
146
154
  end
@@ -148,4 +156,9 @@ end
148
156
 
149
157
  task :default => :spec
150
158
 
151
- task :precommit => ["spec", "spec:jruby", "spec:integration"]
159
+ task :precommit => ["spec", "spec:jruby", "spec:integration"]
160
+
161
+ desc 'Removes trailing whitespace'
162
+ task :whitespace do
163
+ sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
164
+ end
@@ -53,32 +53,25 @@ module Webrat
53
53
 
54
54
  # Set the key that Selenium uses to determine the browser running. Default *firefox
55
55
  attr_accessor :selenium_browser_key
56
-
57
- # Set the timeout argument for the Selenium jar
58
- attr_accessor :selenium_server_timeout
59
-
60
- # Set the timeout argument for the Selenium server startup
61
- attr_accessor :selenium_server_startup_timeout
62
-
63
- # Set any additional arguments (as a string) to pass to the Selenium RC jar
64
- attr_accessor :selenium_server_args
56
+
57
+ # Set the timeout for waiting for the browser process to start
58
+ attr_accessor :selenium_browser_startup_timeout
65
59
 
66
60
  # How many redirects to the same URL should be halted as an infinite redirect
67
61
  # loop? Defaults to 10
68
62
  attr_accessor :infinite_redirect_limit
69
-
63
+
70
64
  def initialize # :nodoc:
71
65
  self.open_error_files = true
72
- self.parse_with_nokogiri = !Webrat.on_java?
73
- self.application_environment = :selenium
66
+ self.parse_with_nokogiri = true
67
+ self.application_environment = :test
74
68
  self.application_port = 3001
75
69
  self.application_address = 'localhost'
76
- self.application_framework = 'rails'
70
+ self.application_framework = :rails
77
71
  self.selenium_server_port = 4444
78
72
  self.infinite_redirect_limit = 10
79
73
  self.selenium_browser_key = '*firefox'
80
- self.selenium_server_timeout = 5
81
- self.selenium_server_startup_timeout = 120
74
+ self.selenium_browser_startup_timeout = 5
82
75
  end
83
76
 
84
77
  def parse_with_nokogiri? #:nodoc:
@@ -93,7 +86,7 @@ module Webrat
93
86
  # :rails, :selenium, :rack, :sinatra, :mechanize, :merb
94
87
  def mode=(mode)
95
88
  @mode = mode.to_sym
96
-
89
+
97
90
  # This is a temporary hack to support backwards compatibility
98
91
  # with Merb 1.0.8 until it's updated to use the new Webrat.configure
99
92
  # syntax
@@ -2,21 +2,21 @@ require "webrat/core/elements/element"
2
2
 
3
3
  module Webrat
4
4
  class Area < Element #:nodoc:
5
-
5
+
6
6
  def self.xpath_search
7
7
  ".//area"
8
8
  end
9
-
9
+
10
10
  def click(method = nil, options = {})
11
11
  @session.request_page(absolute_href, :get, {})
12
12
  end
13
-
13
+
14
14
  protected
15
-
15
+
16
16
  def href
17
17
  Webrat::XML.attribute(@element, "href")
18
18
  end
19
-
19
+
20
20
  def absolute_href
21
21
  if href =~ /^\?/
22
22
  "#{@session.current_url}#{href}"
@@ -26,6 +26,6 @@ module Webrat
26
26
  href
27
27
  end
28
28
  end
29
-
29
+
30
30
  end
31
- end
31
+ end
@@ -1,33 +1,33 @@
1
1
  module Webrat
2
-
2
+
3
3
  class Element # :nodoc:
4
-
4
+
5
5
  def self.load_all(session, dom)
6
- Webrat::XML.xpath_search(dom, xpath_search).map do |element|
6
+ Webrat::XML.xpath_search(dom, xpath_search).map do |element|
7
7
  load(session, element)
8
8
  end
9
9
  end
10
-
10
+
11
11
  def self.load(session, element)
12
12
  return nil if element.nil?
13
13
  session.elements[Webrat::XML.xpath_to(element)] ||= self.new(session, element)
14
14
  end
15
-
15
+
16
16
  attr_reader :element
17
-
17
+
18
18
  def initialize(session, element)
19
19
  @session = session
20
20
  @element = element
21
21
  end
22
-
22
+
23
23
  def path
24
24
  Webrat::XML.xpath_to(@element)
25
25
  end
26
-
26
+
27
27
  def inspect
28
28
  "#<#{self.class} @element=#{element.inspect}>"
29
29
  end
30
-
30
+
31
31
  end
32
-
33
- end
32
+
33
+ end
@@ -8,10 +8,10 @@ module Webrat
8
8
  # Raised when Webrat is asked to manipulate a disabled form field
9
9
  class DisabledFieldError < WebratError
10
10
  end
11
-
11
+
12
12
  class Field < Element #:nodoc:
13
13
  attr_reader :value
14
-
14
+
15
15
  def self.xpath_search
16
16
  [".//button", ".//input", ".//textarea", ".//select"]
17
17
  end
@@ -19,22 +19,22 @@ module Webrat
19
19
  def self.xpath_search_excluding_hidden
20
20
  [".//button", ".//input[ @type != 'hidden']", ".//textarea", ".//select"]
21
21
  end
22
-
22
+
23
23
  def self.field_classes
24
24
  @field_classes || []
25
25
  end
26
-
26
+
27
27
  def self.inherited(klass)
28
28
  @field_classes ||= []
29
29
  @field_classes << klass
30
30
  # raise args.inspect
31
31
  end
32
-
32
+
33
33
  def self.load(session, element)
34
34
  return nil if element.nil?
35
35
  session.elements[Webrat::XML.xpath_to(element)] ||= field_class(element).new(session, element)
36
36
  end
37
-
37
+
38
38
  def self.field_class(element)
39
39
  case element.name
40
40
  when "button" then ButtonField
@@ -55,7 +55,7 @@ module Webrat
55
55
  end
56
56
  end
57
57
  end
58
-
58
+
59
59
  def initialize(*args)
60
60
  super
61
61
  @value = default_value
@@ -65,7 +65,7 @@ module Webrat
65
65
  return nil if labels.empty?
66
66
  labels.first.text
67
67
  end
68
-
68
+
69
69
  def id
70
70
  Webrat::XML.attribute(@element, "id")
71
71
  end
@@ -73,15 +73,15 @@ module Webrat
73
73
  def disabled?
74
74
  @element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'
75
75
  end
76
-
76
+
77
77
  def raise_error_if_disabled
78
78
  return unless disabled?
79
79
  raise DisabledFieldError.new("Cannot interact with disabled form element (#{self})")
80
80
  end
81
-
81
+
82
82
  def to_param
83
83
  return nil if disabled?
84
-
84
+
85
85
  case Webrat.configuration.mode
86
86
  when :rails
87
87
  parse_rails_request_params("#{name}=#{escaped_value}")
@@ -91,17 +91,17 @@ module Webrat
91
91
  { name => escaped_value }
92
92
  end
93
93
  end
94
-
94
+
95
95
  def set(value)
96
96
  @value = value
97
97
  end
98
-
98
+
99
99
  def unset
100
100
  @value = default_value
101
101
  end
102
-
102
+
103
103
  protected
104
-
104
+
105
105
  def parse_rails_request_params(params)
106
106
  if defined?(ActionController::AbstractRequest)
107
107
  ActionController::AbstractRequest.parse_query_parameters(params)
@@ -113,38 +113,38 @@ module Webrat
113
113
  Rack::Utils.parse_nested_query(params)
114
114
  end
115
115
  end
116
-
116
+
117
117
  def form
118
118
  Form.load(@session, form_element)
119
119
  end
120
-
120
+
121
121
  def form_element
122
122
  parent = @element.parent
123
-
123
+
124
124
  while parent.respond_to?(:parent)
125
125
  return parent if parent.name == 'form'
126
126
  parent = parent.parent
127
127
  end
128
128
  end
129
-
129
+
130
130
  def name
131
131
  Webrat::XML.attribute(@element, "name")
132
132
  end
133
-
133
+
134
134
  def escaped_value
135
135
  CGI.escape(@value.to_s)
136
136
  end
137
-
137
+
138
138
  def labels
139
139
  @labels ||= label_elements.map do |element|
140
140
  Label.load(@session, element)
141
141
  end
142
142
  end
143
-
143
+
144
144
  def label_elements
145
145
  return @label_elements unless @label_elements.nil?
146
146
  @label_elements = []
147
-
147
+
148
148
  parent = @element.parent
149
149
  while parent.respond_to?(:parent)
150
150
  if parent.name == 'label'
@@ -153,18 +153,18 @@ module Webrat
153
153
  end
154
154
  parent = parent.parent
155
155
  end
156
-
156
+
157
157
  unless id.blank?
158
158
  @label_elements += Webrat::XML.xpath_search(form.element, ".//label[@for = '#{id}']")
159
159
  end
160
-
160
+
161
161
  @label_elements
162
162
  end
163
-
163
+
164
164
  def default_value
165
165
  Webrat::XML.attribute(@element, "value")
166
166
  end
167
-
167
+
168
168
  def replace_param_value(params, oval, nval)
169
169
  output = Hash.new
170
170
  params.each do |key, value|
@@ -181,13 +181,13 @@ module Webrat
181
181
  output
182
182
  end
183
183
  end
184
-
184
+
185
185
  class ButtonField < Field #:nodoc:
186
186
 
187
187
  def self.xpath_search
188
188
  [".//button", ".//input[@type = 'submit']", ".//input[@type = 'button']", ".//input[@type = 'image']"]
189
189
  end
190
-
190
+
191
191
  def to_param
192
192
  return nil if @value.nil?
193
193
  super
@@ -210,7 +210,7 @@ module Webrat
210
210
  def self.xpath_search
211
211
  ".//input[@type = 'hidden']"
212
212
  end
213
-
213
+
214
214
  def to_param
215
215
  if collection_name?
216
216
  super
@@ -238,7 +238,7 @@ module Webrat
238
238
  def self.xpath_search
239
239
  ".//input[@type = 'checkbox']"
240
240
  end
241
-
241
+
242
242
  def to_param
243
243
  return nil if @value.nil?
244
244
  super
@@ -248,7 +248,7 @@ module Webrat
248
248
  raise_error_if_disabled
249
249
  set(Webrat::XML.attribute(@element, "value") || "on")
250
250
  end
251
-
251
+
252
252
  def checked?
253
253
  Webrat::XML.attribute(@element, "checked") == "checked"
254
254
  end
@@ -271,11 +271,11 @@ module Webrat
271
271
  end
272
272
 
273
273
  class PasswordField < Field #:nodoc:
274
-
274
+
275
275
  def self.xpath_search
276
276
  ".//input[@type = 'password']"
277
277
  end
278
-
278
+
279
279
  end
280
280
 
281
281
  class RadioField < Field #:nodoc:
@@ -283,31 +283,31 @@ module Webrat
283
283
  def self.xpath_search
284
284
  ".//input[@type = 'radio']"
285
285
  end
286
-
286
+
287
287
  def to_param
288
288
  return nil if @value.nil?
289
289
  super
290
290
  end
291
-
291
+
292
292
  def choose
293
293
  raise_error_if_disabled
294
294
  other_options.each do |option|
295
295
  option.set(nil)
296
296
  end
297
-
297
+
298
298
  set(Webrat::XML.attribute(@element, "value") || "on")
299
299
  end
300
-
300
+
301
301
  def checked?
302
302
  Webrat::XML.attribute(@element, "checked") == "checked"
303
303
  end
304
-
304
+
305
305
  protected
306
306
 
307
307
  def other_options
308
308
  form.fields.select { |f| f.name == name }
309
309
  end
310
-
310
+
311
311
  def default_value
312
312
  if Webrat::XML.attribute(@element, "checked") == "checked"
313
313
  Webrat::XML.attribute(@element, "value") || "on"
@@ -323,7 +323,7 @@ module Webrat
323
323
  def self.xpath_search
324
324
  ".//textarea"
325
325
  end
326
-
326
+
327
327
  protected
328
328
 
329
329
  def default_value
@@ -331,13 +331,13 @@ module Webrat
331
331
  end
332
332
 
333
333
  end
334
-
334
+
335
335
  class FileField < Field #:nodoc:
336
-
336
+
337
337
  def self.xpath_search
338
338
  ".//input[@type = 'file']"
339
339
  end
340
-
340
+
341
341
  attr_accessor :content_type
342
342
 
343
343
  def set(value, content_type = nil)
@@ -352,9 +352,9 @@ module Webrat
352
352
  replace_param_value(super, @value, test_uploaded_file)
353
353
  end
354
354
  end
355
-
355
+
356
356
  protected
357
-
357
+
358
358
  def test_uploaded_file
359
359
  if content_type
360
360
  ActionController::TestUploadedFile.new(@value, content_type)
@@ -386,17 +386,17 @@ module Webrat
386
386
  def options
387
387
  @options ||= SelectOption.load_all(@session, @element)
388
388
  end
389
-
389
+
390
390
  protected
391
391
 
392
392
  def default_value
393
393
  selected_options = Webrat::XML.xpath_search(@element, ".//option[@selected = 'selected']")
394
- selected_options = Webrat::XML.xpath_search(@element, ".//option[position() = 1]") if selected_options.empty?
395
-
394
+ selected_options = Webrat::XML.xpath_search(@element, ".//option[position() = 1]") if selected_options.empty?
395
+
396
396
  selected_options.map do |option|
397
397
  return "" if option.nil?
398
398
  Webrat::XML.attribute(option, "value") || Webrat::XML.inner_html(option)
399
- end
399
+ end.uniq
400
400
  end
401
401
 
402
402
  end
@@ -7,7 +7,7 @@ require "webrat/core/locators/field_named_locator"
7
7
  module Webrat
8
8
  class Form < Element #:nodoc:
9
9
  attr_reader :element
10
-
10
+
11
11
  def self.xpath_search
12
12
  ".//form"
13
13
  end
@@ -15,21 +15,21 @@ module Webrat
15
15
  def fields
16
16
  @fields ||= Field.load_all(@session, @element)
17
17
  end
18
-
18
+
19
19
  def submit
20
20
  @session.request_page(form_action, form_method, params)
21
21
  end
22
-
22
+
23
23
  def field_named(name, *field_types)
24
24
  Webrat::Locators::FieldNamedLocator.new(@session, dom, name, *field_types).locate
25
25
  end
26
-
26
+
27
27
  protected
28
-
28
+
29
29
  def dom
30
30
  Webrat::XML.xpath_at(@session.dom, path)
31
31
  end
32
-
32
+
33
33
  def fields_by_type(field_types)
34
34
  if field_types.any?
35
35
  fields.select { |f| field_types.include?(f.class) }
@@ -37,26 +37,26 @@ module Webrat
37
37
  fields
38
38
  end
39
39
  end
40
-
40
+
41
41
  def params
42
42
  all_params = {}
43
-
43
+
44
44
  fields.each do |field|
45
45
  next if field.to_param.nil?
46
46
  merge(all_params, field.to_param)
47
47
  end
48
-
48
+
49
49
  all_params
50
50
  end
51
-
51
+
52
52
  def form_method
53
53
  Webrat::XML.attribute(@element, "method").blank? ? :get : Webrat::XML.attribute(@element, "method").downcase
54
54
  end
55
-
55
+
56
56
  def form_action
57
57
  Webrat::XML.attribute(@element, "action").blank? ? @session.current_url : Webrat::XML.attribute(@element, "action")
58
58
  end
59
-
59
+
60
60
  def merge(all_params, new_param)
61
61
  new_param.each do |key, value|
62
62
  case all_params[key]
@@ -69,7 +69,7 @@ module Webrat
69
69
  end
70
70
  end
71
71
  end
72
-
72
+
73
73
  def merge_hash_values(a, b) # :nodoc:
74
74
  a.keys.each do |k|
75
75
  if b.has_key?(k)
@@ -85,19 +85,19 @@ module Webrat
85
85
  end
86
86
  a.merge!(b)
87
87
  end
88
-
88
+
89
89
  def hash_classes
90
90
  klasses = [Hash]
91
-
91
+
92
92
  case Webrat.configuration.mode
93
93
  when :rails
94
94
  klasses << HashWithIndifferentAccess
95
95
  when :merb
96
96
  klasses << Mash
97
97
  end
98
-
98
+
99
99
  klasses
100
100
  end
101
-
101
+
102
102
  end
103
103
  end
@@ -2,9 +2,9 @@ require "webrat/core/elements/element"
2
2
 
3
3
  module Webrat
4
4
  class Label < Element #:nodoc:
5
-
5
+
6
6
  attr_reader :element
7
-
7
+
8
8
  def self.xpath_search
9
9
  ".//label"
10
10
  end
@@ -12,13 +12,13 @@ module Webrat
12
12
  def for_id
13
13
  Webrat::XML.attribute(@element, "for")
14
14
  end
15
-
15
+
16
16
  def field
17
17
  Field.load(@session, field_element)
18
18
  end
19
-
19
+
20
20
  protected
21
-
21
+
22
22
  def field_element
23
23
  if for_id.blank?
24
24
  Webrat::XML.xpath_at(@element, *Field.xpath_search_excluding_hidden)
@@ -26,6 +26,6 @@ module Webrat
26
26
  Webrat::XML.css_search(@session.current_dom, "#" + for_id).first
27
27
  end
28
28
  end
29
-
29
+
30
30
  end
31
31
  end