webrat 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -1
- data/Gemfile +19 -0
- data/History.txt +29 -0
- data/Rakefile +27 -63
- data/Thorfile +117 -0
- data/lib/webrat.rb +11 -3
- data/lib/webrat/{mechanize.rb → adapters/mechanize.rb} +0 -0
- data/lib/webrat/adapters/merb.rb +11 -0
- data/lib/webrat/{rack.rb → adapters/rack.rb} +0 -0
- data/lib/webrat/{rails.rb → adapters/rails.rb} +2 -23
- data/lib/webrat/{sinatra.rb → adapters/sinatra.rb} +0 -2
- data/lib/webrat/core.rb +0 -1
- data/lib/webrat/core/configuration.rb +6 -16
- data/lib/webrat/core/elements/area.rb +2 -2
- data/lib/webrat/core/elements/element.rb +3 -3
- data/lib/webrat/core/elements/field.rb +106 -30
- data/lib/webrat/core/elements/form.rb +4 -4
- data/lib/webrat/core/elements/label.rb +4 -4
- data/lib/webrat/core/elements/link.rb +6 -6
- data/lib/webrat/core/elements/select_option.rb +15 -2
- data/lib/webrat/core/locators.rb +1 -1
- data/lib/webrat/core/locators/area_locator.rb +3 -3
- data/lib/webrat/core/locators/button_locator.rb +6 -6
- data/lib/webrat/core/locators/field_by_id_locator.rb +3 -3
- data/lib/webrat/core/locators/field_labeled_locator.rb +2 -2
- data/lib/webrat/core/locators/field_named_locator.rb +3 -3
- data/lib/webrat/core/locators/form_locator.rb +1 -1
- data/lib/webrat/core/locators/label_locator.rb +2 -2
- data/lib/webrat/core/locators/link_locator.rb +7 -7
- data/lib/webrat/core/locators/select_option_locator.rb +5 -5
- data/lib/webrat/core/logging.rb +4 -5
- data/lib/webrat/core/matchers/have_content.rb +2 -7
- data/lib/webrat/core/matchers/have_xpath.rb +3 -28
- data/lib/webrat/core/methods.rb +1 -0
- data/lib/webrat/core/scope.rb +17 -2
- data/lib/webrat/core/session.rb +2 -1
- data/lib/webrat/core/xml.rb +41 -84
- data/lib/webrat/integrations/merb.rb +10 -0
- data/lib/webrat/integrations/rails.rb +25 -0
- data/lib/webrat/integrations/rspec-rails.rb +11 -0
- data/lib/webrat/integrations/selenium.rb +11 -0
- data/lib/webrat/rspec-rails.rb +2 -10
- data/lib/webrat/selenium.rb +0 -10
- data/lib/webrat/selenium/application_servers.rb +1 -1
- data/lib/webrat/selenium/application_servers/external.rb +1 -1
- data/lib/webrat/selenium/location_strategy_javascript/label.js +29 -3
- data/lib/webrat/selenium/location_strategy_javascript/webrat.js +1 -0
- data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +24 -4
- data/lib/webrat/selenium/selenium_rc_server.rb +2 -2
- data/lib/webrat/selenium/selenium_session.rb +21 -2
- data/lib/webrat/selenium/silence_stream.rb +1 -1
- data/spec/integration/mechanize/spec/spec_helper.rb +3 -1
- data/spec/integration/rails/app/controllers/{application.rb → application_controller.rb} +0 -0
- data/spec/integration/rails/app/controllers/webrat_controller.rb +3 -0
- data/spec/integration/rails/app/views/buttons/show.html.erb +0 -2
- data/spec/integration/rails/app/views/webrat/buttons.html.erb +0 -2
- data/spec/integration/rails/app/views/webrat/within.html.erb +3 -0
- data/spec/integration/rails/config/environment.rb +1 -1
- data/spec/integration/rails/config/routes.rb +1 -0
- data/spec/integration/rails/test/integration/button_click_test.rb +12 -26
- data/spec/integration/rails/test/integration/fill_in_test.rb +1 -1
- data/spec/integration/rails/test/integration/link_click_test.rb +1 -1
- data/spec/integration/rails/test/integration/webrat_test.rb +35 -9
- data/spec/integration/rails/test/test_helper.rb +1 -0
- data/spec/private/core/configuration_spec.rb +2 -31
- data/spec/private/core/field_spec.rb +14 -16
- data/spec/private/mechanize/mechanize_adapter_spec.rb +0 -2
- data/spec/private/nokogiri_spec.rb +2 -2
- data/spec/private/rails/rails_adapter_spec.rb +0 -27
- data/spec/public/basic_auth_spec.rb +13 -2
- data/spec/public/click_button_spec.rb +10 -12
- data/spec/public/click_link_spec.rb +21 -0
- data/spec/public/fill_in_spec.rb +15 -0
- data/spec/public/matchers/have_selector_spec.rb +4 -0
- data/spec/public/select_spec.rb +232 -26
- data/spec/spec_helper.rb +2 -0
- data/webrat.gemspec +305 -313
- metadata +21 -25
- data/VERSION +0 -1
- data/lib/webrat/core/xml/hpricot.rb +0 -19
- data/lib/webrat/core/xml/nokogiri.rb +0 -76
- data/lib/webrat/core/xml/rexml.rb +0 -24
- data/lib/webrat/merb_adapter.rb +0 -82
- data/lib/webrat/merb_multipart_support.rb +0 -27
- data/spec/private/core/logging_spec.rb +0 -10
- data/spec/private/merb/attaches_file_spec.rb +0 -93
- data/spec/private/merb/merb_adapter_spec.rb +0 -61
@@ -20,24 +20,24 @@ module Webrat
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def matches_id?(element)
|
23
|
-
(@value.is_a?(Regexp) &&
|
24
|
-
(!@value.is_a?(Regexp) &&
|
23
|
+
(@value.is_a?(Regexp) && element["id"] =~ @value) ||
|
24
|
+
(!@value.is_a?(Regexp) && element["id"] == @value.to_s)
|
25
25
|
end
|
26
26
|
|
27
27
|
def matches_value?(element)
|
28
|
-
|
28
|
+
element["value"] =~ /^\W*#{Regexp.escape(@value.to_s)}/i
|
29
29
|
end
|
30
30
|
|
31
31
|
def matches_html?(element)
|
32
|
-
|
32
|
+
element.inner_html =~ /#{Regexp.escape(@value.to_s)}/i
|
33
33
|
end
|
34
34
|
|
35
35
|
def matches_alt?(element)
|
36
|
-
|
36
|
+
element["alt"] =~ /^\W*#{Regexp.escape(@value.to_s)}/i
|
37
37
|
end
|
38
38
|
|
39
39
|
def button_elements
|
40
|
-
|
40
|
+
@dom.xpath(*ButtonField.xpath_search)
|
41
41
|
end
|
42
42
|
|
43
43
|
def error_message
|
@@ -12,15 +12,15 @@ module Webrat
|
|
12
12
|
def field_element
|
13
13
|
field_elements.detect do |field_element|
|
14
14
|
if @value.is_a?(Regexp)
|
15
|
-
|
15
|
+
field_element["id"] =~ @value
|
16
16
|
else
|
17
|
-
|
17
|
+
field_element["id"] == @value.to_s
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def field_elements
|
23
|
-
|
23
|
+
@dom.xpath(*Field.xpath_search)
|
24
24
|
end
|
25
25
|
|
26
26
|
def error_message
|
@@ -25,7 +25,7 @@ module Webrat
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def label_elements
|
28
|
-
|
28
|
+
@dom.xpath(*Label.xpath_search)
|
29
29
|
end
|
30
30
|
|
31
31
|
def error_message
|
@@ -33,7 +33,7 @@ module Webrat
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def text(element)
|
36
|
-
str =
|
36
|
+
str = element.inner_text
|
37
37
|
str.gsub!("\n","")
|
38
38
|
str.strip!
|
39
39
|
str.squeeze!(" ")
|
@@ -11,19 +11,19 @@ module Webrat
|
|
11
11
|
|
12
12
|
def field_element
|
13
13
|
field_elements.detect do |field_element|
|
14
|
-
|
14
|
+
field_element["name"] == @value.to_s
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
def field_elements
|
19
|
-
|
19
|
+
@dom.xpath(*xpath_searches)
|
20
20
|
end
|
21
21
|
|
22
22
|
def xpath_searches
|
23
23
|
if @field_types.any?
|
24
24
|
@field_types.map { |field_type| field_type.xpath_search }.flatten
|
25
25
|
else
|
26
|
-
|
26
|
+
Field.xpath_search
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -17,11 +17,11 @@ module Webrat
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def label_elements
|
20
|
-
|
20
|
+
@dom.xpath(*Label.xpath_search)
|
21
21
|
end
|
22
22
|
|
23
23
|
def text(label_element)
|
24
|
-
str =
|
24
|
+
str = label_element.inner_text
|
25
25
|
str.gsub!("\n","")
|
26
26
|
str.strip!
|
27
27
|
str.squeeze!(" ")
|
@@ -10,7 +10,7 @@ module Webrat
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def link_element
|
13
|
-
matching_links.min { |a, b|
|
13
|
+
matching_links.min { |a, b| a.inner_text.length <=> b.inner_text.length }
|
14
14
|
end
|
15
15
|
|
16
16
|
def matching_links
|
@@ -27,21 +27,21 @@ module Webrat
|
|
27
27
|
matcher = /#{Regexp.escape(@value.to_s)}/i
|
28
28
|
end
|
29
29
|
|
30
|
-
replace_nbsp(
|
31
|
-
replace_nbsp_ref(
|
32
|
-
|
30
|
+
replace_nbsp(link.inner_text) =~ matcher ||
|
31
|
+
replace_nbsp_ref(link.inner_html) =~ matcher ||
|
32
|
+
link["title"] =~ matcher
|
33
33
|
end
|
34
34
|
|
35
35
|
def matches_id?(link)
|
36
36
|
if @value.is_a?(Regexp)
|
37
|
-
|
37
|
+
link["id"] =~ @value ? true : false
|
38
38
|
else
|
39
|
-
|
39
|
+
link["id"] == @value ? true : false
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
def link_elements
|
44
|
-
|
44
|
+
@dom.xpath(*Link.xpath_search)
|
45
45
|
end
|
46
46
|
|
47
47
|
def replace_nbsp(str)
|
@@ -19,17 +19,17 @@ module Webrat
|
|
19
19
|
|
20
20
|
field.options.detect do |o|
|
21
21
|
if @option_text.is_a?(Regexp)
|
22
|
-
|
22
|
+
o.element.inner_text =~ @option_text
|
23
23
|
else
|
24
|
-
|
24
|
+
o.inner_text == @option_text.to_s
|
25
25
|
end
|
26
26
|
end
|
27
27
|
else
|
28
28
|
option_element = option_elements.detect do |o|
|
29
29
|
if @option_text.is_a?(Regexp)
|
30
|
-
|
30
|
+
o.inner_text =~ @option_text
|
31
31
|
else
|
32
|
-
|
32
|
+
o.inner_text == @option_text.to_s
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -38,7 +38,7 @@ module Webrat
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def option_elements
|
41
|
-
|
41
|
+
@dom.xpath(*SelectOption.xpath_search)
|
42
42
|
end
|
43
43
|
|
44
44
|
def error_message
|
data/lib/webrat/core/logging.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "logger"
|
2
|
+
|
1
3
|
module Webrat
|
2
4
|
module Logging #:nodoc:
|
3
5
|
|
@@ -11,12 +13,9 @@ module Webrat
|
|
11
13
|
when :rails
|
12
14
|
defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : nil
|
13
15
|
when :merb
|
14
|
-
Merb.logger
|
16
|
+
::Merb.logger
|
15
17
|
else
|
16
|
-
@logger ||=
|
17
|
-
require "logger"
|
18
|
-
::Logger.new("webrat.log")
|
19
|
-
end
|
18
|
+
@logger ||= ::Logger.new("webrat.log")
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
@@ -7,13 +7,8 @@ module Webrat
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def matches?(stringlike)
|
10
|
-
|
11
|
-
|
12
|
-
else
|
13
|
-
@document = Webrat.hpricot_document(stringlike)
|
14
|
-
end
|
15
|
-
|
16
|
-
@element = Webrat::XML.inner_text(@document)
|
10
|
+
@document = Webrat::XML.document(stringlike)
|
11
|
+
@element = @document.inner_text
|
17
12
|
|
18
13
|
case @content
|
19
14
|
when String
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require "webrat/core/xml
|
2
|
-
require "webrat/core/xml/rexml"
|
1
|
+
require "webrat/core/xml"
|
3
2
|
|
4
3
|
module Webrat
|
5
4
|
module Matchers
|
@@ -16,38 +15,14 @@ module Webrat
|
|
16
15
|
matched = matches(stringlike)
|
17
16
|
|
18
17
|
if @options[:count]
|
19
|
-
matched.size == @options[:count] && (!@block || @block.call(matched))
|
18
|
+
matched.size == @options[:count].to_i && (!@block || @block.call(matched))
|
20
19
|
else
|
21
20
|
matched.any? && (!@block || @block.call(matched))
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
25
24
|
def matches(stringlike)
|
26
|
-
|
27
|
-
nokogiri_matches(stringlike)
|
28
|
-
else
|
29
|
-
rexml_matches(stringlike)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def rexml_matches(stringlike)
|
34
|
-
if REXML::Node === stringlike || Array === stringlike
|
35
|
-
@query = query.map { |q| q.gsub(%r'^//', './/') }
|
36
|
-
else
|
37
|
-
@query = query
|
38
|
-
end
|
39
|
-
|
40
|
-
add_options_conditions_to(@query)
|
41
|
-
|
42
|
-
@document = Webrat.rexml_document(stringlike)
|
43
|
-
|
44
|
-
@query.map do |q|
|
45
|
-
if @document.is_a?(Array)
|
46
|
-
@document.map { |d| REXML::XPath.match(d, q) }
|
47
|
-
else
|
48
|
-
REXML::XPath.match(@document, q)
|
49
|
-
end
|
50
|
-
end.flatten.compact
|
25
|
+
nokogiri_matches(stringlike)
|
51
26
|
end
|
52
27
|
|
53
28
|
def nokogiri_matches(stringlike)
|
data/lib/webrat/core/methods.rb
CHANGED
data/lib/webrat/core/scope.rb
CHANGED
@@ -112,6 +112,21 @@ module Webrat
|
|
112
112
|
|
113
113
|
webrat_deprecate :selects, :select
|
114
114
|
|
115
|
+
# Verifies that a an option element exists on the current page with the specified
|
116
|
+
# text. You can optionally restrict the search to a specific select list by
|
117
|
+
# assigning <tt>options[:from]</tt> the value of the select list's name or
|
118
|
+
# a label. Remove the option's value before the form is submitted.
|
119
|
+
#
|
120
|
+
# Examples:
|
121
|
+
# unselect "January"
|
122
|
+
# unselect "February", :from => "event_month"
|
123
|
+
# unselect "February", :from => "Event Month"
|
124
|
+
def unselect(option_text, options={})
|
125
|
+
select_option(option_text, options[:from]).unchoose
|
126
|
+
end
|
127
|
+
|
128
|
+
webrat_deprecate :unselects, :unselect
|
129
|
+
|
115
130
|
DATE_TIME_SUFFIXES = {
|
116
131
|
:year => '1i',
|
117
132
|
:month => '2i',
|
@@ -312,12 +327,12 @@ module Webrat
|
|
312
327
|
dom = Webrat::XML.html_document(@response_body)
|
313
328
|
end
|
314
329
|
|
315
|
-
Webrat.define_dom_method(@response, dom)
|
330
|
+
Webrat::XML.define_dom_method(@response, dom)
|
316
331
|
return dom
|
317
332
|
end
|
318
333
|
|
319
334
|
def scoped_dom
|
320
|
-
|
335
|
+
@scope.dom.css(@selector).first
|
321
336
|
end
|
322
337
|
|
323
338
|
def locate_field(field_locator, *field_types) #:nodoc:
|
data/lib/webrat/core/session.rb
CHANGED
@@ -105,7 +105,7 @@ For example:
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def basic_auth(user, pass)
|
108
|
-
encoded_login = ["#{user}:#{pass}"].pack("m*")
|
108
|
+
encoded_login = ["#{user}:#{pass}"].pack("m*").gsub(/\n/, '')
|
109
109
|
header('HTTP_AUTHORIZATION', "Basic #{encoded_login}")
|
110
110
|
end
|
111
111
|
|
@@ -260,6 +260,7 @@ For example:
|
|
260
260
|
def_delegators :current_scope, :uncheck, :unchecks
|
261
261
|
def_delegators :current_scope, :choose, :chooses
|
262
262
|
def_delegators :current_scope, :select, :selects
|
263
|
+
def_delegators :current_scope, :unselect, :unselects
|
263
264
|
def_delegators :current_scope, :select_datetime, :selects_datetime
|
264
265
|
def_delegators :current_scope, :select_date, :selects_date
|
265
266
|
def_delegators :current_scope, :select_time, :selects_time
|
data/lib/webrat/core/xml.rb
CHANGED
@@ -1,115 +1,72 @@
|
|
1
|
-
require "webrat/
|
2
|
-
require "webrat/core/xml/hpricot"
|
3
|
-
require "webrat/core/xml/rexml"
|
1
|
+
require "webrat/core_extensions/meta_class"
|
4
2
|
|
5
3
|
module Webrat #:nodoc:
|
6
4
|
module XML #:nodoc:
|
7
5
|
|
8
6
|
def self.document(stringlike) #:nodoc:
|
9
|
-
if
|
10
|
-
|
7
|
+
return stringlike.dom if stringlike.respond_to?(:dom)
|
8
|
+
|
9
|
+
if Nokogiri::HTML::Document === stringlike
|
10
|
+
stringlike
|
11
|
+
elsif Nokogiri::XML::NodeSet === stringlike
|
12
|
+
stringlike
|
13
|
+
elsif stringlike.respond_to?(:body)
|
14
|
+
Nokogiri::HTML(stringlike.body.to_s)
|
11
15
|
else
|
12
|
-
|
16
|
+
Nokogiri::HTML(stringlike.to_s)
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
16
20
|
def self.html_document(stringlike) #:nodoc:
|
17
|
-
if
|
18
|
-
|
21
|
+
return stringlike.dom if stringlike.respond_to?(:dom)
|
22
|
+
|
23
|
+
if Nokogiri::HTML::Document === stringlike
|
24
|
+
stringlike
|
25
|
+
elsif Nokogiri::XML::NodeSet === stringlike
|
26
|
+
stringlike
|
27
|
+
elsif stringlike.respond_to?(:body)
|
28
|
+
Nokogiri::HTML(stringlike.body.to_s)
|
19
29
|
else
|
20
|
-
|
30
|
+
Nokogiri::HTML(stringlike.to_s)
|
21
31
|
end
|
22
32
|
end
|
23
33
|
|
24
34
|
def self.xml_document(stringlike) #:nodoc:
|
25
|
-
if
|
26
|
-
|
35
|
+
return stringlike.dom if stringlike.respond_to?(:dom)
|
36
|
+
|
37
|
+
if Nokogiri::HTML::Document === stringlike
|
38
|
+
stringlike
|
39
|
+
elsif Nokogiri::XML::NodeSet === stringlike
|
40
|
+
stringlike
|
41
|
+
elsif stringlike.respond_to?(:body)
|
42
|
+
Nokogiri::XML(stringlike.body.to_s)
|
27
43
|
else
|
28
|
-
|
44
|
+
Nokogiri::XML(stringlike.to_s)
|
29
45
|
end
|
30
46
|
end
|
31
47
|
|
32
|
-
def self.
|
33
|
-
|
34
|
-
|
35
|
-
else
|
36
|
-
element.to_s
|
48
|
+
def self.define_dom_method(object, dom) #:nodoc:
|
49
|
+
object.meta_class.send(:define_method, :dom) do
|
50
|
+
dom
|
37
51
|
end
|
38
52
|
end
|
39
53
|
|
40
|
-
|
41
|
-
|
42
|
-
element.inner_html
|
43
|
-
else
|
44
|
-
element.text
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.all_inner_text(element)
|
49
|
-
if Webrat.configuration.parse_with_nokogiri?
|
50
|
-
element.inner_text
|
51
|
-
else
|
52
|
-
Hpricot(element.to_s).children.first.inner_text
|
53
|
-
end
|
54
|
-
end
|
54
|
+
end
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
else
|
60
|
-
if defined?(Hpricot::Doc) && element.is_a?(Hpricot::Doc)
|
61
|
-
element.inner_text
|
62
|
-
else
|
63
|
-
element.text
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
57
|
+
module Nokogiri #:nodoc:
|
58
|
+
module CSS #:nodoc:
|
59
|
+
class XPathVisitor #:nodoc:
|
67
60
|
|
68
|
-
|
69
|
-
|
70
|
-
element.path
|
71
|
-
else
|
72
|
-
element.xpath
|
61
|
+
def visit_pseudo_class_text(node) #:nodoc:
|
62
|
+
"@type='text'"
|
73
63
|
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.attribute(element, attribute_name)
|
77
|
-
return element[attribute_name] if element.is_a?(Hash)
|
78
64
|
|
79
|
-
|
80
|
-
|
81
|
-
else
|
82
|
-
element.attributes[attribute_name]
|
65
|
+
def visit_pseudo_class_password(node) #:nodoc:
|
66
|
+
"@type='password'"
|
83
67
|
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.xpath_at(*args)
|
87
|
-
xpath_search(*args).first
|
88
|
-
end
|
89
|
-
|
90
|
-
def self.css_at(*args)
|
91
|
-
css_search(*args).first
|
92
|
-
end
|
93
|
-
|
94
|
-
def self.xpath_search(element, *searches)
|
95
|
-
searches.flatten.map do |search|
|
96
|
-
if Webrat.configuration.parse_with_nokogiri?
|
97
|
-
element.xpath(search)
|
98
|
-
else
|
99
|
-
REXML::XPath.match(element, search)
|
100
|
-
end
|
101
|
-
end.flatten.compact
|
102
|
-
end
|
103
68
|
|
104
|
-
def self.css_search(element, *searches) #:nodoc:
|
105
|
-
xpath_search(element, css_to_xpath(*searches))
|
106
69
|
end
|
107
|
-
|
108
|
-
def self.css_to_xpath(*selectors)
|
109
|
-
selectors.map do |rule|
|
110
|
-
Nokogiri::CSS.xpath_for(rule, :prefix => ".//")
|
111
|
-
end.flatten.uniq
|
112
|
-
end
|
113
|
-
|
114
70
|
end
|
115
71
|
end
|
72
|
+
|