webrat 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/History.txt +140 -30
  2. data/README.rdoc +85 -0
  3. data/Rakefile +72 -22
  4. data/install.rb +1 -1
  5. data/lib/webrat.rb +12 -17
  6. data/lib/webrat/core.rb +9 -7
  7. data/lib/webrat/core/configuration.rb +87 -0
  8. data/lib/webrat/core/{area.rb → elements/area.rb} +7 -20
  9. data/lib/webrat/core/elements/element.rb +33 -0
  10. data/lib/webrat/core/elements/field.rb +394 -0
  11. data/lib/webrat/core/elements/form.rb +103 -0
  12. data/lib/webrat/core/elements/label.rb +31 -0
  13. data/lib/webrat/core/{link.rb → elements/link.rb} +15 -26
  14. data/lib/webrat/core/elements/select_option.rb +35 -0
  15. data/lib/webrat/core/locators.rb +13 -85
  16. data/lib/webrat/core/locators/area_locator.rb +38 -0
  17. data/lib/webrat/core/locators/button_locator.rb +54 -0
  18. data/lib/webrat/core/locators/field_by_id_locator.rb +37 -0
  19. data/lib/webrat/core/locators/field_labeled_locator.rb +56 -0
  20. data/lib/webrat/core/locators/field_locator.rb +25 -0
  21. data/lib/webrat/core/locators/field_named_locator.rb +41 -0
  22. data/lib/webrat/core/locators/form_locator.rb +19 -0
  23. data/lib/webrat/core/locators/label_locator.rb +34 -0
  24. data/lib/webrat/core/locators/link_locator.rb +66 -0
  25. data/lib/webrat/core/locators/locator.rb +20 -0
  26. data/lib/webrat/core/locators/select_option_locator.rb +59 -0
  27. data/lib/webrat/core/logging.rb +5 -9
  28. data/lib/webrat/core/matchers/have_content.rb +19 -44
  29. data/lib/webrat/core/matchers/have_selector.rb +15 -2
  30. data/lib/webrat/core/matchers/have_tag.rb +15 -2
  31. data/lib/webrat/core/matchers/have_xpath.rb +21 -28
  32. data/lib/webrat/core/methods.rb +32 -15
  33. data/lib/webrat/core/mime.rb +3 -3
  34. data/lib/webrat/core/save_and_open_page.rb +50 -0
  35. data/lib/webrat/core/scope.rb +183 -41
  36. data/lib/webrat/core/session.rb +125 -63
  37. data/lib/webrat/core/xml.rb +115 -0
  38. data/lib/webrat/core/xml/hpricot.rb +19 -0
  39. data/lib/webrat/core/xml/nokogiri.rb +76 -0
  40. data/lib/webrat/core/xml/rexml.rb +24 -0
  41. data/lib/webrat/core_extensions/deprecate.rb +1 -1
  42. data/lib/webrat/mechanize.rb +58 -12
  43. data/lib/webrat/merb.rb +7 -73
  44. data/lib/webrat/merb_session.rb +65 -0
  45. data/lib/webrat/rack.rb +1 -1
  46. data/lib/webrat/rails.rb +56 -55
  47. data/lib/webrat/rspec-rails.rb +13 -0
  48. data/lib/webrat/selenium.rb +92 -1
  49. data/lib/webrat/selenium/matchers.rb +146 -0
  50. data/lib/webrat/selenium/selenium_session.rb +179 -80
  51. data/lib/webrat/sinatra.rb +14 -4
  52. data/vendor/selenium-server.jar +0 -0
  53. metadata +36 -17
  54. data/README.txt +0 -90
  55. data/TODO.txt +0 -10
  56. data/init.rb +0 -3
  57. data/lib/webrat/core/field.rb +0 -332
  58. data/lib/webrat/core/flunk.rb +0 -7
  59. data/lib/webrat/core/form.rb +0 -130
  60. data/lib/webrat/core/label.rb +0 -18
  61. data/lib/webrat/core/nokogiri.rb +0 -44
  62. data/lib/webrat/core/select_option.rb +0 -29
  63. data/lib/webrat/rails/redirect_actions.rb +0 -18
@@ -28,12 +28,25 @@ module Webrat
28
28
  #
29
29
  # ==== Returns
30
30
  # HaveSelector:: A new have selector matcher.
31
- # ---
32
- # @api public
33
31
  def have_selector(expected, &block)
34
32
  HaveSelector.new(expected, &block)
35
33
  end
36
34
  alias_method :match_selector, :have_selector
37
35
 
36
+
37
+ # Asserts that the body of the response contains
38
+ # the supplied selector
39
+ def assert_have_selector(expected)
40
+ hs = HaveSelector.new(expected)
41
+ assert hs.matches?(response_body), hs.failure_message
42
+ end
43
+
44
+ # Asserts that the body of the response
45
+ # does not contain the supplied string or regepx
46
+ def assert_have_no_selector(expected)
47
+ hs = HaveSelector.new(expected)
48
+ assert !hs.matches?(response_body), hs.negative_failure_message
49
+ end
50
+
38
51
  end
39
52
  end
@@ -3,7 +3,6 @@ module Webrat
3
3
  module HaveTagMatcher
4
4
 
5
5
  class HaveTag < ::Webrat::Matchers::HaveSelector #:nodoc:
6
-
7
6
  # ==== Returns
8
7
  # String:: The failure message.
9
8
  def failure_message
@@ -46,13 +45,27 @@ module Webrat
46
45
 
47
46
  Nokogiri::CSS::Parser.parse(selector).map { |ast| ast.to_xpath }
48
47
  end
49
-
50
48
  end
51
49
 
52
50
  def have_tag(name, attributes = {}, &block)
53
51
  HaveTag.new([name, attributes], &block)
54
52
  end
53
+
55
54
  alias_method :match_tag, :have_tag
55
+
56
+ # Asserts that the body of the response contains
57
+ # the supplied tag with the associated selectors
58
+ def assert_have_tag(name, attributes = {})
59
+ ht = HaveTag.new([name, attributes])
60
+ assert ht.matches?(response_body), ht.failure_message
61
+ end
62
+
63
+ # Asserts that the body of the response
64
+ # does not contain the supplied string or regepx
65
+ def assert_have_no_tag(name, attributes = {})
66
+ ht = HaveTag.new([name, attributes])
67
+ assert !ht.matches?(response_body), ht.negative_failure_message
68
+ end
56
69
 
57
70
  end
58
71
  end
@@ -1,3 +1,6 @@
1
+ require "webrat/core/xml/nokogiri"
2
+ require "webrat/core/xml/rexml"
3
+
1
4
  module Webrat
2
5
  module Matchers
3
6
 
@@ -8,7 +11,7 @@ module Webrat
8
11
  end
9
12
 
10
13
  def matches?(stringlike)
11
- if defined?(Nokogiri::XML)
14
+ if Webrat.configuration.parse_with_nokogiri?
12
15
  matches_nokogiri?(stringlike)
13
16
  else
14
17
  matches_rexml?(stringlike)
@@ -16,9 +19,13 @@ module Webrat
16
19
  end
17
20
 
18
21
  def matches_rexml?(stringlike)
19
- @query = query
22
+ if REXML::Node === stringlike || Array === stringlike
23
+ @query = query.map { |q| q.gsub(%r'//', './') }
24
+ else
25
+ @query = query
26
+ end
20
27
 
21
- @document = rexml_document(stringlike)
28
+ @document = Webrat.rexml_document(stringlike)
22
29
 
23
30
  matched = @query.map do |q|
24
31
  if @document.is_a?(Array)
@@ -38,32 +45,10 @@ module Webrat
38
45
  @query = query
39
46
  end
40
47
 
41
- @document = Webrat.nokogiri_document(stringlike)
48
+ @document = Webrat::XML.document(stringlike)
42
49
  matched = @document.xpath(*@query)
43
50
  matched.any? && (!@block || @block.call(matched))
44
51
  end
45
-
46
- def rexml_document(stringlike)
47
- stringlike = stringlike.body.to_s if stringlike.respond_to?(:body)
48
-
49
- case stringlike
50
- when REXML::Document
51
- stringlike.root
52
- when REXML::Node, Array
53
- @query = query.map { |q| q.gsub(%r'//', './') }
54
- stringlike
55
- else
56
- begin
57
- REXML::Document.new(stringlike.to_s).root
58
- rescue REXML::ParseException => e
59
- if e.message.include?("second root element")
60
- REXML::Document.new("<fake-root-element>#{stringlike}</fake-root-element>").root
61
- else
62
- raise e
63
- end
64
- end
65
- end
66
- end
67
52
 
68
53
  def query
69
54
  [@expected].flatten.compact
@@ -89,12 +74,20 @@ module Webrat
89
74
  #
90
75
  # ==== Returns
91
76
  # HaveXpath:: A new have xpath matcher.
92
- # ---
93
- # @api public
94
77
  def have_xpath(expected, &block)
95
78
  HaveXpath.new(expected, &block)
96
79
  end
97
80
  alias_method :match_xpath, :have_xpath
98
81
 
82
+ def assert_have_xpath(expected, &block)
83
+ hs = HaveXpath.new(expected, &block)
84
+ assert hs.matches?(response_body), hs.failure_message
85
+ end
86
+
87
+ def assert_have_no_xpath(expected, &block)
88
+ hs = HaveXpath.new(expected, &block)
89
+ assert !hs.matches?(response_body), hs.negative_failure_message
90
+ end
91
+
99
92
  end
100
93
  end
@@ -5,13 +5,20 @@ module Webrat
5
5
  meths.each do |meth|
6
6
  self.class_eval <<-RUBY
7
7
  def #{meth}(*args, &blk)
8
- @_webrat_session ||= ::Webrat::MerbSession.new
9
- @_webrat_session.#{meth}(*args, &blk)
8
+ webrat_session.#{meth}(*args, &blk)
10
9
  end
11
10
  RUBY
12
11
  end
13
12
  end
14
13
 
14
+ def webrat
15
+ webrat_session
16
+ end
17
+
18
+ def webrat_session
19
+ @_webrat_session ||= ::Webrat.session_class.new(self)
20
+ end
21
+
15
22
  # all of these methods delegate to the @session, which should
16
23
  # be created transparently.
17
24
  #
@@ -23,22 +30,32 @@ module Webrat
23
30
  :within,
24
31
  :header, :http_accept, :basic_auth,
25
32
  :save_and_open_page,
26
- :fill_in,
27
- :check,
28
- :uncheck,
29
- :choose,
30
- :select,
31
- :attach_file,
32
- :cookies,
33
- :response,
33
+ :fills_in, :fill_in,
34
+ :checks, :check,
35
+ :unchecks, :uncheck,
36
+ :chooses, :choose,
37
+ :selects, :select,
38
+ :attaches_file, :attach_file,
34
39
  :current_page,
35
40
  :current_url,
36
- :click_link,
37
- :click_area,
38
- :click_button,
41
+ :clicks_link, :click_link,
42
+ :clicks_area, :click_area,
43
+ :clicks_button, :click_button,
39
44
  :reload, :reloads,
40
- :clicks_link_within,
41
- :field_labeled
45
+ :clicks_link_within, :click_link_within,
46
+ :field_labeled,
47
+ :select_option,
48
+ :set_hidden_field, :submit_form,
49
+ :request_page, :current_dom,
50
+ :response_body,
51
+ :selects_date, :selects_time, :selects_datetime,
52
+ :select_date, :select_time, :select_datetime,
53
+ :field_by_xpath,
54
+ :field_with_id,
55
+ :selenium,
56
+ :simulate, :automate
57
+
58
+
42
59
 
43
60
  end
44
61
  end
@@ -1,7 +1,7 @@
1
- module Webrat
2
- module MIME
1
+ module Webrat #:nodoc:
2
+ module MIME #:nodoc:
3
3
 
4
- def self.mime_type(string_or_symbol)
4
+ def self.mime_type(string_or_symbol) #:nodoc:
5
5
  if string_or_symbol.is_a?(String)
6
6
  string_or_symbol
7
7
  else
@@ -0,0 +1,50 @@
1
+ module Webrat
2
+ module SaveAndOpenPage
3
+ # Saves the page out to RAILS_ROOT/tmp/ and opens it in the default
4
+ # web browser if on OS X. Useful for debugging.
5
+ #
6
+ # Example:
7
+ # save_and_open_page
8
+ def save_and_open_page
9
+ return unless File.exist?(saved_page_dir)
10
+
11
+ filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.html"
12
+
13
+ File.open(filename, "w") do |f|
14
+ f.write rewrite_css_and_image_references(response_body)
15
+ end
16
+
17
+ open_in_browser(filename)
18
+ end
19
+
20
+ def open_in_browser(path) # :nodoc
21
+ platform = ruby_platform
22
+ if platform =~ /cygwin/ || platform =~ /win32/
23
+ `rundll32 url.dll,FileProtocolHandler #{path.gsub("/", "\\\\")}`
24
+ elsif platform =~ /darwin/
25
+ `open #{path}`
26
+ end
27
+ end
28
+
29
+ def rewrite_css_and_image_references(response_html) # :nodoc:
30
+ return response_html unless doc_root
31
+ response_html.gsub(/"\/(stylesheets|images)/, doc_root + '/\1')
32
+ end
33
+
34
+ def saved_page_dir #:nodoc:
35
+ File.expand_path(".")
36
+ end
37
+
38
+ def doc_root #:nodoc:
39
+ nil
40
+ end
41
+
42
+ private
43
+
44
+ # accessor for testing
45
+ def ruby_platform
46
+ RUBY_PLATFORM
47
+ end
48
+
49
+ end
50
+ end
@@ -1,11 +1,14 @@
1
- require "nokogiri"
2
- require "webrat/core/form"
1
+ require "webrat/core/elements/form"
3
2
  require "webrat/core/locators"
3
+ require "webrat/core_extensions/deprecate"
4
4
 
5
5
  module Webrat
6
+ # An HTML element (link, button, field, etc.) that Webrat expected was not found on the page
7
+ class NotFoundError < WebratError
8
+ end
9
+
6
10
  class Scope
7
11
  include Logging
8
- include Flunk
9
12
  include Locators
10
13
 
11
14
  def self.from_page(session, response, response_body) #:nodoc:
@@ -22,9 +25,15 @@ module Webrat
22
25
  end
23
26
  end
24
27
 
28
+ attr_reader :session
29
+
25
30
  def initialize(session, &block) #:nodoc:
26
31
  @session = session
27
32
  instance_eval(&block) if block_given?
33
+
34
+ if @selector && scoped_dom.nil?
35
+ raise Webrat::NotFoundError.new("The scope was not found on the page: #{@selector.inspect}")
36
+ end
28
37
  end
29
38
 
30
39
  # Verifies an input field or textarea exists on the current page, and stores a value for
@@ -43,7 +52,17 @@ module Webrat
43
52
  field.set(options[:with])
44
53
  end
45
54
 
46
- alias_method :fills_in, :fill_in
55
+ webrat_deprecate :fills_in, :fill_in
56
+
57
+ # Verifies that a hidden field exists on the current page and sets
58
+ # the value to that given by the <tt>:to</tt> option.
59
+ #
60
+ # Example:
61
+ # set_hidden_field 'user_id', :to => 1
62
+ def set_hidden_field(field_locator, options = {})
63
+ field = locate_field(field_locator, HiddenField)
64
+ field.set(options[:to])
65
+ end
47
66
 
48
67
  # Verifies that an input checkbox exists on the current page and marks it
49
68
  # as checked, so that the value will be submitted with the form.
@@ -54,7 +73,7 @@ module Webrat
54
73
  locate_field(field_locator, CheckboxField).check
55
74
  end
56
75
 
57
- alias_method :checks, :check
76
+ webrat_deprecate :checks, :check
58
77
 
59
78
  # Verifies that an input checkbox exists on the current page and marks it
60
79
  # as unchecked, so that the value will not be submitted with the form.
@@ -65,7 +84,7 @@ module Webrat
65
84
  locate_field(field_locator, CheckboxField).uncheck
66
85
  end
67
86
 
68
- alias_method :unchecks, :uncheck
87
+ webrat_deprecate :unchecks, :uncheck
69
88
 
70
89
  # Verifies that an input radio button exists on the current page and marks it
71
90
  # as checked, so that the value will be submitted with the form.
@@ -76,7 +95,7 @@ module Webrat
76
95
  locate_field(field_locator, RadioField).choose
77
96
  end
78
97
 
79
- alias_method :chooses, :choose
98
+ webrat_deprecate :chooses, :choose
80
99
 
81
100
  # Verifies that a an option element exists on the current page with the specified
82
101
  # text. You can optionally restrict the search to a specific select list by
@@ -84,14 +103,106 @@ module Webrat
84
103
  # a label. Stores the option's value to be sent when the form is submitted.
85
104
  #
86
105
  # Examples:
87
- # selects "January"
88
- # selects "February", :from => "event_month"
89
- # selects "February", :from => "Event Month"
90
- def selects(option_text, options = {})
91
- find_select_option(option_text, options[:from]).choose
106
+ # select "January"
107
+ # select "February", :from => "event_month"
108
+ # select "February", :from => "Event Month"
109
+ def select(option_text, options = {})
110
+ select_option(option_text, options[:from]).choose
92
111
  end
93
112
 
94
- alias_method :select, :selects
113
+ webrat_deprecate :selects, :select
114
+
115
+ DATE_TIME_SUFFIXES = {
116
+ :year => '1i',
117
+ :month => '2i',
118
+ :day => '3i',
119
+ :hour => '4i',
120
+ :minute => '5i'
121
+ }
122
+
123
+ # Verifies that date elements (year, month, day) exist on the current page
124
+ # with the specified values. You can optionally restrict the search to a specific
125
+ # date's elements by assigning <tt>options[:from]</tt> the value of the date's
126
+ # label. Selects all the date elements with date provided. The date provided may
127
+ # be a string or a Date/Time object.
128
+ #
129
+ # Rail's convention is used for detecting the date elements. All elements
130
+ # are assumed to have a shared prefix. You may also specify the prefix
131
+ # by assigning <tt>options[:id_prefix]</tt>.
132
+ #
133
+ # Examples:
134
+ # select_date "January 23, 2004"
135
+ # select_date "April 26, 1982", :from => "Birthday"
136
+ # select_date Date.parse("December 25, 2000"), :from => "Event"
137
+ # select_date "April 26, 1982", :id_prefix => 'birthday'
138
+ def select_date(date_to_select, options ={})
139
+ date = date_to_select.is_a?(Date) || date_to_select.is_a?(Time) ?
140
+ date_to_select : Date.parse(date_to_select)
141
+
142
+ id_prefix = locate_id_prefix(options) do
143
+ year_field = FieldByIdLocator.new(@session, dom, /(.*?)_#{DATE_TIME_SUFFIXES[:year]}$/).locate
144
+ raise NotFoundError.new("No date fields were found") unless year_field && year_field.id =~ /(.*?)_1i/
145
+ $1
146
+ end
147
+
148
+ select date.year, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:year]}"
149
+ select date.strftime('%B'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:month]}"
150
+ select date.day, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:day]}"
151
+ end
152
+
153
+ webrat_deprecate :selects_date, :select_date
154
+
155
+ # Verifies that time elements (hour, minute) exist on the current page
156
+ # with the specified values. You can optionally restrict the search to a specific
157
+ # time's elements by assigning <tt>options[:from]</tt> the value of the time's
158
+ # label. Selects all the time elements with date provided. The time provided may
159
+ # be a string or a Time object.
160
+ #
161
+ # Rail's convention is used for detecting the time elements. All elements are
162
+ # assumed to have a shared prefix. You may specify the prefix by assigning
163
+ # <tt>options[:id_prefix]</tt>.
164
+ #
165
+ # Note: Just like Rails' time_select helper this assumes the form is using
166
+ # 24 hour select boxes, and not 12 hours with AM/PM.
167
+ #
168
+ # Examples:
169
+ # select_time "9:30"
170
+ # select_date "3:30PM", :from => "Party Time"
171
+ # select_date Time.parse("10:00PM"), :from => "Event"
172
+ # select_date "10:30AM", :id_prefix => 'meeting'
173
+ def select_time(time_to_select, options ={})
174
+ time = time_to_select.is_a?(Time) ? time_to_select : Time.parse(time_to_select)
175
+
176
+ id_prefix = locate_id_prefix(options) do
177
+ hour_field = FieldByIdLocator.new(@session, dom, /(.*?)_#{DATE_TIME_SUFFIXES[:hour]}$/).locate
178
+ raise NotFoundError.new("No time fields were found") unless hour_field && hour_field.id =~ /(.*?)_4i/
179
+ $1
180
+ end
181
+
182
+ select time.hour.to_s.rjust(2,'0'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:hour]}"
183
+ select time.min.to_s.rjust(2,'0'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:minute]}"
184
+ end
185
+
186
+ webrat_deprecate :selects_time, :select_time
187
+
188
+ # Verifies and selects all the date and time elements on the current page.
189
+ # See #select_time and #select_date for more details and available options.
190
+ #
191
+ # Examples:
192
+ # select_datetime "January 23, 2004 10:30AM"
193
+ # select_datetime "April 26, 1982 7:00PM", :from => "Birthday"
194
+ # select_datetime Time.parse("December 25, 2000 15:30"), :from => "Event"
195
+ # select_datetime "April 26, 1982 5:50PM", :id_prefix => 'birthday'
196
+ def select_datetime(time_to_select, options ={})
197
+ time = time_to_select.is_a?(Time) ? time_to_select : Time.parse(time_to_select)
198
+
199
+ options[:id_prefix] ||= (options[:from] ? FieldByIdLocator.new(@session, dom, options[:from]).locate : nil)
200
+
201
+ select_date time, options
202
+ select_time time, options
203
+ end
204
+
205
+ webrat_deprecate :selects_datetime, :select_datetime
95
206
 
96
207
  # Verifies that an input file field exists on the current page and sets
97
208
  # its value to the given +file+, so that the file will be uploaded
@@ -104,13 +215,22 @@ module Webrat
104
215
  locate_field(field_locator, FileField).set(path, content_type)
105
216
  end
106
217
 
107
- alias_method :attaches_file, :attach_file
108
-
218
+ webrat_deprecate :attaches_file, :attach_file
219
+
220
+ # Issues a request for the URL pointed to by an <tt>area</tt> tag
221
+ # on the current page, follows any redirects, and verifies the
222
+ # final page load was successful.
223
+ #
224
+ # The area used is the first area whose title or id contains the
225
+ # given +area_name+ (case is ignored).
226
+ #
227
+ # Example:
228
+ # click_area 'Australia'
109
229
  def click_area(area_name)
110
230
  find_area(area_name).click
111
231
  end
112
232
 
113
- alias_method :clicks_area, :click_area
233
+ webrat_deprecate :clicks_area, :click_area
114
234
 
115
235
  # Issues a request for the URL pointed to by a link on the current page,
116
236
  # follows any redirects, and verifies the final page load was successful.
@@ -124,17 +244,23 @@ module Webrat
124
244
  # Passing a :method in the options hash overrides the HTTP method used
125
245
  # for making the link request
126
246
  #
247
+ # It will try to find links by (in order of precedence):
248
+ # innerHTML, with simple &nbsp; handling
249
+ # title
250
+ # id
251
+ #
252
+ # innerHTML and title are matchable by text subtring or Regexp
253
+ # id is matchable by full text equality or Regexp
254
+ #
127
255
  # Example:
128
256
  # click_link "Sign up"
129
- #
130
257
  # click_link "Sign up", :javascript => false
131
- #
132
258
  # click_link "Sign up", :method => :put
133
- def click_link(link_text, options = {})
134
- find_link(link_text).click(options)
259
+ def click_link(text_or_title_or_id, options = {})
260
+ find_link(text_or_title_or_id).click(options)
135
261
  end
136
262
 
137
- alias_method :clicks_link, :click_link
263
+ webrat_deprecate :clicks_link, :click_link
138
264
 
139
265
  # Verifies that a submit button exists for the form, then submits the form, follows
140
266
  # any redirects, and verifies the final page was successful.
@@ -149,7 +275,19 @@ module Webrat
149
275
  find_button(value).click
150
276
  end
151
277
 
152
- alias_method :clicks_button, :click_button
278
+ webrat_deprecate :clicks_button, :click_button
279
+
280
+ # Submit the form with the given id.
281
+ #
282
+ # Note that +click_button+ is usually preferrable for simulating
283
+ # form submissions, as you may specify part of the button text
284
+ # rather than the form id.
285
+ #
286
+ # Example:
287
+ # submit_form 'login'
288
+ def submit_form(id)
289
+ FormLocator.new(@session, dom, id).locate.submit
290
+ end
153
291
 
154
292
  def dom # :nodoc:
155
293
  return @dom if @dom
@@ -164,16 +302,22 @@ module Webrat
164
302
  end
165
303
 
166
304
  protected
167
-
305
+
168
306
  def page_dom #:nodoc:
169
307
  return @response.dom if @response.respond_to?(:dom)
170
- dom = Webrat.nokogiri_document(@response_body)
308
+
309
+ if @session.xml_content_type?
310
+ dom = Webrat::XML.xml_document(@response_body)
311
+ else
312
+ dom = Webrat::XML.html_document(@response_body)
313
+ end
314
+
171
315
  Webrat.define_dom_method(@response, dom)
172
316
  return dom
173
317
  end
174
318
 
175
- def scoped_dom #:nodoc:
176
- Webrat.nokogiri_document(@scope.dom.search(@selector).first.to_html)
319
+ def scoped_dom
320
+ Webrat::XML.css_at(@scope.dom, @selector)
177
321
  end
178
322
 
179
323
  def locate_field(field_locator, *field_types) #:nodoc:
@@ -184,25 +328,23 @@ module Webrat
184
328
  end
185
329
  end
186
330
 
187
- def areas #:nodoc:
188
- dom.search("area").map do |element|
189
- Area.new(@session, element)
190
- end
191
- end
192
-
193
- def links #:nodoc:
194
- dom.search("a[@href]").map do |link_element|
195
- Link.new(@session, link_element)
331
+ def locate_id_prefix(options, &location_strategy) #:nodoc:
332
+ return options[:id_prefix] if options[:id_prefix]
333
+
334
+ if options[:from]
335
+ if (label = LabelLocator.new(@session, dom, options[:from]).locate)
336
+ label.for_id
337
+ else
338
+ raise NotFoundError.new("Could not find the label with text #{options[:from]}")
339
+ end
340
+ else
341
+ yield
196
342
  end
197
343
  end
198
344
 
199
345
  def forms #:nodoc:
200
- return @forms if @forms
201
-
202
- @forms = dom.search("form").map do |form_element|
203
- Form.new(@session, form_element)
204
- end
346
+ @forms ||= Form.load_all(@session, dom)
205
347
  end
206
348
 
207
349
  end
208
- end
350
+ end