aslakhellesoy-webrat 0.3.2.2 → 0.4.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +158 -19
- data/Rakefile +36 -11
- data/lib/webrat.rb +8 -11
- data/lib/webrat/core/configuration.rb +67 -25
- data/lib/webrat/core/elements/area.rb +7 -7
- data/lib/webrat/core/elements/element.rb +11 -11
- data/lib/webrat/core/elements/field.rb +70 -51
- data/lib/webrat/core/elements/form.rb +17 -17
- data/lib/webrat/core/elements/label.rb +8 -8
- data/lib/webrat/core/elements/link.rb +13 -11
- data/lib/webrat/core/elements/select_option.rb +9 -9
- data/lib/webrat/core/locators.rb +2 -2
- data/lib/webrat/core/locators/area_locator.rb +10 -10
- data/lib/webrat/core/locators/button_locator.rb +13 -13
- data/lib/webrat/core/locators/field_by_id_locator.rb +8 -8
- data/lib/webrat/core/locators/field_labeled_locator.rb +19 -13
- data/lib/webrat/core/locators/field_locator.rb +7 -7
- data/lib/webrat/core/locators/field_named_locator.rb +10 -10
- data/lib/webrat/core/locators/form_locator.rb +6 -6
- data/lib/webrat/core/locators/label_locator.rb +9 -9
- data/lib/webrat/core/locators/link_locator.rb +12 -12
- data/lib/webrat/core/locators/locator.rb +5 -5
- data/lib/webrat/core/locators/select_option_locator.rb +11 -11
- data/lib/webrat/core/logging.rb +7 -4
- data/lib/webrat/core/matchers/have_content.rb +19 -15
- data/lib/webrat/core/matchers/have_selector.rb +44 -22
- data/lib/webrat/core/matchers/have_tag.rb +11 -61
- data/lib/webrat/core/matchers/have_xpath.rb +89 -35
- data/lib/webrat/core/methods.rb +13 -11
- data/lib/webrat/core/mime.rb +3 -3
- data/lib/webrat/core/save_and_open_page.rb +9 -9
- data/lib/webrat/core/scope.rb +82 -62
- data/lib/webrat/core/session.rb +61 -18
- data/lib/webrat/core/xml.rb +16 -16
- data/lib/webrat/core/xml/hpricot.rb +3 -3
- data/lib/webrat/core/xml/nokogiri.rb +14 -14
- data/lib/webrat/core/xml/rexml.rb +3 -3
- data/lib/webrat/core_extensions/blank.rb +1 -1
- data/lib/webrat/core_extensions/deprecate.rb +1 -1
- data/lib/webrat/core_extensions/detect_mapped.rb +4 -4
- data/lib/webrat/core_extensions/meta_class.rb +1 -1
- data/lib/webrat/core_extensions/tcp_socket.rb +27 -0
- data/lib/webrat/mechanize.rb +9 -9
- data/lib/webrat/merb.rb +5 -61
- data/lib/webrat/merb_session.rb +67 -0
- data/lib/webrat/rack.rb +45 -14
- data/lib/webrat/rails.rb +31 -11
- data/lib/webrat/rspec-rails.rb +2 -2
- data/lib/webrat/selenium.rb +27 -39
- data/lib/webrat/selenium/application_server_factory.rb +40 -0
- data/lib/webrat/selenium/application_servers.rb +5 -0
- data/lib/webrat/selenium/application_servers/base.rb +44 -0
- data/lib/webrat/selenium/application_servers/external.rb +24 -0
- data/lib/webrat/selenium/application_servers/merb.rb +48 -0
- data/lib/webrat/selenium/application_servers/rails.rb +42 -0
- data/lib/webrat/selenium/application_servers/sinatra.rb +35 -0
- data/lib/webrat/selenium/location_strategy_javascript/button.js +14 -7
- data/lib/webrat/selenium/location_strategy_javascript/label.js +1 -2
- data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +4 -1
- data/lib/webrat/selenium/matchers.rb +4 -108
- data/lib/webrat/selenium/matchers/have_content.rb +66 -0
- data/lib/webrat/selenium/matchers/have_selector.rb +49 -0
- data/lib/webrat/selenium/matchers/have_tag.rb +72 -0
- data/lib/webrat/selenium/matchers/have_xpath.rb +45 -0
- data/lib/webrat/selenium/selenium_rc_server.rb +84 -0
- data/lib/webrat/selenium/selenium_session.rb +86 -68
- data/lib/webrat/selenium/silence_stream.rb +18 -0
- metadata +21 -16
- data/lib/webrat/core_extensions/hash_with_indifferent_access.rb +0 -131
- data/lib/webrat/sinatra.rb +0 -29
@@ -2,18 +2,18 @@ require "webrat/core/locators/locator"
|
|
2
2
|
|
3
3
|
module Webrat
|
4
4
|
module Locators
|
5
|
-
|
5
|
+
|
6
6
|
class FormLocator < Locator # :nodoc:
|
7
|
-
|
7
|
+
|
8
8
|
def locate
|
9
9
|
Form.load(@session, form_element)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def form_element
|
13
13
|
Webrat::XML.css_at(@dom, "#" + @value)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
@@ -3,23 +3,23 @@ require "webrat/core/locators/locator"
|
|
3
3
|
|
4
4
|
module Webrat
|
5
5
|
module Locators
|
6
|
-
|
6
|
+
|
7
7
|
class LabelLocator < Locator # :nodoc:
|
8
|
-
|
8
|
+
|
9
9
|
def locate
|
10
10
|
Label.load(@session, label_element)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def label_element
|
14
14
|
label_elements.detect do |label_element|
|
15
|
-
text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
|
15
|
+
text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}(\b|\Z)/i
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def label_elements
|
20
20
|
Webrat::XML.xpath_search(@dom, Label.xpath_search)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def text(label_element)
|
24
24
|
str = Webrat::XML.all_inner_text(label_element)
|
25
25
|
str.gsub!("\n","")
|
@@ -27,8 +27,8 @@ module Webrat
|
|
27
27
|
str.squeeze!(" ")
|
28
28
|
str
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
end
|
34
|
-
end
|
34
|
+
end
|
@@ -2,24 +2,24 @@ require "webrat/core/locators/locator"
|
|
2
2
|
|
3
3
|
module Webrat
|
4
4
|
module Locators
|
5
|
-
|
5
|
+
|
6
6
|
class LinkLocator < Locator # :nodoc:
|
7
|
-
|
7
|
+
|
8
8
|
def locate
|
9
9
|
Link.load(@session, link_element)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def link_element
|
13
13
|
matching_links.min { |a, b| Webrat::XML.all_inner_text(a).length <=> Webrat::XML.all_inner_text(b).length }
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def matching_links
|
17
17
|
@matching_links ||= link_elements.select do |link_element|
|
18
18
|
matches_text?(link_element) ||
|
19
19
|
matches_id?(link_element)
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def matches_text?(link)
|
24
24
|
if @value.is_a?(Regexp)
|
25
25
|
matcher = @value
|
@@ -39,11 +39,11 @@ module Webrat
|
|
39
39
|
(Webrat::XML.attribute(link, "id") == @value) ? true : false
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def link_elements
|
44
44
|
Webrat::XML.xpath_search(@dom, *Link.xpath_search)
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def replace_nbsp(str)
|
48
48
|
str.gsub([0xA0].pack('U'), ' ')
|
49
49
|
end
|
@@ -51,16 +51,16 @@ module Webrat
|
|
51
51
|
def replace_nbsp_ref(str)
|
52
52
|
str.gsub(' ',' ').gsub(' ', ' ')
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def error_message
|
56
56
|
"Could not find link with text or title or id #{@value.inspect}"
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def find_link(text_or_title_or_id) #:nodoc:
|
62
62
|
LinkLocator.new(@session, dom, text_or_title_or_id).locate!
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
end
|
66
|
-
end
|
66
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Webrat
|
2
2
|
module Locators
|
3
|
-
|
3
|
+
|
4
4
|
class Locator # :nodoc:
|
5
5
|
|
6
6
|
def initialize(session, dom, value, *field_types)
|
@@ -9,12 +9,12 @@ module Webrat
|
|
9
9
|
@value = value
|
10
10
|
@field_types = field_types
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def locate!
|
14
14
|
locate || raise(NotFoundError.new(error_message))
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
@@ -3,20 +3,20 @@ require "webrat/core/locators/locator"
|
|
3
3
|
|
4
4
|
module Webrat
|
5
5
|
module Locators
|
6
|
-
|
6
|
+
|
7
7
|
class SelectOptionLocator < Locator # :nodoc:
|
8
|
-
|
8
|
+
|
9
9
|
def initialize(session, dom, option_text, id_or_name_or_label)
|
10
10
|
@session = session
|
11
11
|
@dom = dom
|
12
12
|
@option_text = option_text
|
13
13
|
@id_or_name_or_label = id_or_name_or_label
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def locate
|
17
17
|
if @id_or_name_or_label
|
18
18
|
field = FieldLocator.new(@session, @dom, @id_or_name_or_label, SelectField).locate!
|
19
|
-
|
19
|
+
|
20
20
|
field.options.detect do |o|
|
21
21
|
if @option_text.is_a?(Regexp)
|
22
22
|
Webrat::XML.inner_html(o.element) =~ @option_text
|
@@ -32,15 +32,15 @@ module Webrat
|
|
32
32
|
Webrat::XML.inner_html(o) == @option_text.to_s
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
SelectOption.load(@session, option_element)
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def option_elements
|
41
41
|
Webrat::XML.xpath_search(@dom, *SelectOption.xpath_search)
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def error_message
|
45
45
|
if @id_or_name_or_label
|
46
46
|
"The '#{@option_text}' option was not found in the #{@id_or_name_or_label.inspect} select box"
|
@@ -48,12 +48,12 @@ module Webrat
|
|
48
48
|
"Could not find option #{@option_text.inspect}"
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def select_option(option_text, id_or_name_or_label = nil) #:nodoc:
|
55
55
|
SelectOptionLocator.new(@session, dom, option_text, id_or_name_or_label).locate!
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
end
|
59
|
-
end
|
59
|
+
end
|
data/lib/webrat/core/logging.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Webrat
|
2
2
|
module Logging #:nodoc:
|
3
|
-
|
3
|
+
|
4
4
|
def debug_log(message) # :nodoc:
|
5
5
|
return unless logger
|
6
6
|
logger.debug message
|
@@ -13,9 +13,12 @@ module Webrat
|
|
13
13
|
when :merb
|
14
14
|
Merb.logger
|
15
15
|
else
|
16
|
-
|
16
|
+
@logger ||= begin
|
17
|
+
require "logger"
|
18
|
+
::Logger.new("webrat.log")
|
19
|
+
end
|
17
20
|
end
|
18
21
|
end
|
19
|
-
|
22
|
+
|
20
23
|
end
|
21
|
-
end
|
24
|
+
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
module Webrat
|
2
2
|
module Matchers
|
3
|
-
|
3
|
+
|
4
4
|
class HasContent #:nodoc:
|
5
5
|
def initialize(content)
|
6
6
|
@content = content
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def matches?(stringlike)
|
10
10
|
if Webrat.configuration.parse_with_nokogiri?
|
11
11
|
@document = Webrat.nokogiri_document(stringlike)
|
12
12
|
else
|
13
13
|
@document = Webrat.hpricot_document(stringlike)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
@element = Webrat::XML.inner_text(@document)
|
17
|
-
|
17
|
+
|
18
18
|
case @content
|
19
19
|
when String
|
20
20
|
@element.include?(@content)
|
@@ -22,19 +22,23 @@ module Webrat
|
|
22
22
|
@element.match(@content)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
# ==== Returns
|
27
27
|
# String:: The failure message.
|
28
28
|
def failure_message
|
29
|
-
"expected the following element's content to #{content_message}:\n#{@element}"
|
29
|
+
"expected the following element's content to #{content_message}:\n#{squeeze_space(@element)}"
|
30
30
|
end
|
31
31
|
|
32
32
|
# ==== Returns
|
33
33
|
# String:: The failure message to be displayed in negative matches.
|
34
34
|
def negative_failure_message
|
35
|
-
"expected the following element's content to not #{content_message}:\n#{@element}"
|
35
|
+
"expected the following element's content to not #{content_message}:\n#{squeeze_space(@element)}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def squeeze_space(inner_text)
|
39
|
+
inner_text.gsub(/^\s*$/, "").squeeze("\n")
|
36
40
|
end
|
37
|
-
|
41
|
+
|
38
42
|
def content_message
|
39
43
|
case @content
|
40
44
|
when String
|
@@ -44,26 +48,26 @@ module Webrat
|
|
44
48
|
end
|
45
49
|
end
|
46
50
|
end
|
47
|
-
|
51
|
+
|
48
52
|
# Matches the contents of an HTML document with
|
49
53
|
# whatever string is supplied
|
50
54
|
def contain(content)
|
51
55
|
HasContent.new(content)
|
52
56
|
end
|
53
|
-
|
57
|
+
|
54
58
|
# Asserts that the body of the response contain
|
55
59
|
# the supplied string or regexp
|
56
60
|
def assert_contain(content)
|
57
61
|
hc = HasContent.new(content)
|
58
|
-
|
62
|
+
assert hc.matches?(response_body), hc.failure_message
|
59
63
|
end
|
60
|
-
|
64
|
+
|
61
65
|
# Asserts that the body of the response
|
62
66
|
# does not contain the supplied string or regepx
|
63
67
|
def assert_not_contain(content)
|
64
68
|
hc = HasContent.new(content)
|
65
|
-
|
69
|
+
assert !hc.matches?(response_body), hc.negative_failure_message
|
66
70
|
end
|
67
|
-
|
71
|
+
|
68
72
|
end
|
69
|
-
end
|
73
|
+
end
|
@@ -1,26 +1,48 @@
|
|
1
|
+
require "webrat/core/matchers/have_xpath"
|
2
|
+
|
1
3
|
module Webrat
|
2
4
|
module Matchers
|
3
|
-
|
4
|
-
class HaveSelector < HaveXpath #:nodoc:
|
5
5
|
|
6
|
+
class HaveSelector < HaveXpath #:nodoc:
|
6
7
|
# ==== Returns
|
7
8
|
# String:: The failure message.
|
8
9
|
def failure_message
|
9
|
-
"expected following
|
10
|
+
"expected following output to contain a #{tag_inspect} tag:\n#{@document}"
|
10
11
|
end
|
11
|
-
|
12
|
+
|
12
13
|
# ==== Returns
|
13
14
|
# String:: The failure message to be displayed in negative matches.
|
14
15
|
def negative_failure_message
|
15
|
-
"expected following
|
16
|
+
"expected following output to omit a #{tag_inspect}:\n#{@document}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def tag_inspect
|
20
|
+
options = @options.dup
|
21
|
+
count = options.delete(:count)
|
22
|
+
content = options.delete(:content)
|
23
|
+
|
24
|
+
html = "<#{@expected}"
|
25
|
+
options.each do |k,v|
|
26
|
+
html << " #{k}='#{v}'"
|
27
|
+
end
|
28
|
+
|
29
|
+
if content
|
30
|
+
html << ">#{content}</#{@expected}>"
|
31
|
+
else
|
32
|
+
html << "/>"
|
33
|
+
end
|
34
|
+
|
35
|
+
html
|
16
36
|
end
|
17
|
-
|
37
|
+
|
18
38
|
def query
|
19
|
-
Nokogiri::CSS
|
39
|
+
Nokogiri::CSS.parse(@expected.to_s).map do |ast|
|
40
|
+
ast.to_xpath
|
41
|
+
end.first
|
20
42
|
end
|
21
|
-
|
43
|
+
|
22
44
|
end
|
23
|
-
|
45
|
+
|
24
46
|
# Matches HTML content against a CSS 3 selector.
|
25
47
|
#
|
26
48
|
# ==== Parameters
|
@@ -28,25 +50,25 @@ module Webrat
|
|
28
50
|
#
|
29
51
|
# ==== Returns
|
30
52
|
# HaveSelector:: A new have selector matcher.
|
31
|
-
def have_selector(
|
32
|
-
HaveSelector.new(
|
53
|
+
def have_selector(name, attributes = {}, &block)
|
54
|
+
HaveSelector.new(name, attributes, &block)
|
33
55
|
end
|
34
56
|
alias_method :match_selector, :have_selector
|
35
|
-
|
36
|
-
|
57
|
+
|
58
|
+
|
37
59
|
# Asserts that the body of the response contains
|
38
60
|
# the supplied selector
|
39
|
-
def assert_have_selector(
|
40
|
-
|
41
|
-
|
61
|
+
def assert_have_selector(name, attributes = {}, &block)
|
62
|
+
matcher = HaveSelector.new(name, attributes, &block)
|
63
|
+
assert matcher.matches?(response_body), matcher.failure_message
|
42
64
|
end
|
43
|
-
|
65
|
+
|
44
66
|
# Asserts that the body of the response
|
45
67
|
# does not contain the supplied string or regepx
|
46
|
-
def assert_have_no_selector(
|
47
|
-
|
48
|
-
|
68
|
+
def assert_have_no_selector(name, attributes = {}, &block)
|
69
|
+
matcher = HaveSelector.new(name, attributes, &block)
|
70
|
+
assert !matcher.matches?(response_body), matcher.negative_failure_message
|
49
71
|
end
|
50
|
-
|
72
|
+
|
51
73
|
end
|
52
|
-
end
|
74
|
+
end
|
@@ -1,71 +1,21 @@
|
|
1
|
+
require "webrat/core/matchers/have_selector"
|
2
|
+
|
1
3
|
module Webrat
|
2
|
-
|
3
4
|
module HaveTagMatcher
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
# String:: The failure message.
|
8
|
-
def failure_message
|
9
|
-
"expected following output to contain a #{tag_inspect} tag:\n#{@document}"
|
10
|
-
end
|
11
|
-
|
12
|
-
# ==== Returns
|
13
|
-
# String:: The failure message to be displayed in negative matches.
|
14
|
-
def negative_failure_message
|
15
|
-
"expected following output to omit a #{tag_inspect}:\n#{@document}"
|
16
|
-
end
|
17
|
-
|
18
|
-
def tag_inspect
|
19
|
-
options = @expected.last.dup
|
20
|
-
content = options.delete(:content)
|
21
|
-
|
22
|
-
html = "<#{@expected.first}"
|
23
|
-
options.each do |k,v|
|
24
|
-
html << " #{k}='#{v}'"
|
25
|
-
end
|
26
|
-
|
27
|
-
if content
|
28
|
-
html << ">#{content}</#{@expected.first}>"
|
29
|
-
else
|
30
|
-
html << "/>"
|
31
|
-
end
|
32
|
-
|
33
|
-
html
|
34
|
-
end
|
35
|
-
|
36
|
-
def query
|
37
|
-
options = @expected.last.dup
|
38
|
-
selector = @expected.first.to_s
|
39
|
-
|
40
|
-
selector << ":contains('#{options.delete(:content)}')" if options[:content]
|
41
|
-
|
42
|
-
options.each do |key, value|
|
43
|
-
selector << "[#{key}='#{value}']"
|
44
|
-
end
|
45
|
-
|
46
|
-
Nokogiri::CSS::Parser.parse(selector).map { |ast| ast.to_xpath }
|
47
|
-
end
|
6
|
+
def have_tag(*args, &block)
|
7
|
+
have_selector(*args, &block)
|
48
8
|
end
|
49
9
|
|
50
|
-
def have_tag(name, attributes = {}, &block)
|
51
|
-
HaveTag.new([name, attributes], &block)
|
52
|
-
end
|
53
|
-
|
54
10
|
alias_method :match_tag, :have_tag
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
def assert_have_tag(name, attributes = {})
|
59
|
-
ht = HaveTag.new([name, attributes])
|
60
|
-
raise Test::Unit::AssertionFailedError.new(ht.failure_message) unless ht.matches?(response_body)
|
11
|
+
|
12
|
+
def assert_have_tag(*args, &block)
|
13
|
+
assert_have_selector(*args, &block)
|
61
14
|
end
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
def assert_have_no_tag(name, attributes = {})
|
66
|
-
ht = HaveTag.new([name, attributes])
|
67
|
-
raise Test::Unit::AssertionFailedError.new(ht.negative_failure_message) if ht.matches?(response_body)
|
15
|
+
|
16
|
+
def assert_have_no_tag(*args, &block)
|
17
|
+
assert_have_no_selector(*args, &block)
|
68
18
|
end
|
69
19
|
|
70
20
|
end
|
71
|
-
end
|
21
|
+
end
|