locator 0.0.6 → 0.0.7
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/Rakefile +1 -20
- data/lib/locator/matcher.rb +37 -23
- data/lib/locator/matcher/have_css_class.rb +24 -0
- data/lib/locator/version.rb +1 -1
- metadata +28 -63
- data/test/all.rb +0 -6
- data/test/locator/boolean_test.rb +0 -40
- data/test/locator/dom/htmlunit_test.rb +0 -81
- data/test/locator/dom/nokogiri_test.rb +0 -42
- data/test/locator/element/button_test.rb +0 -31
- data/test/locator/element/field_test.rb +0 -71
- data/test/locator/element/form_test.rb +0 -36
- data/test/locator/element/hidden_field_test.rb +0 -36
- data/test/locator/element/label_test.rb +0 -30
- data/test/locator/element/link_test.rb +0 -36
- data/test/locator/element/select_option_test.rb +0 -41
- data/test/locator/element/select_test.rb +0 -30
- data/test/locator/element/text_area_test.rb +0 -31
- data/test/locator/element_test.rb +0 -136
- data/test/locator/matcher/have_content_test.rb +0 -29
- data/test/locator/matcher/have_tag_test.rb +0 -161
- data/test/locator/xpath_test.rb +0 -45
- data/test/locator_test.rb +0 -132
- data/test/test_helper.rb +0 -31
- data/test/webrat.rb +0 -27
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class LocatorMatcherHaveContentTest < Test::Unit::TestCase
|
4
|
-
include Locator::Matcher
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@html = '<p><a class="foo">The link</a></p>'
|
8
|
-
end
|
9
|
-
|
10
|
-
test 'target matches a given text' do
|
11
|
-
assert contain('The link').matches?(@html)
|
12
|
-
end
|
13
|
-
|
14
|
-
test 'target does not match a given text' do
|
15
|
-
assert !contain('No link').matches?(@html)
|
16
|
-
end
|
17
|
-
|
18
|
-
test 'target matches a given regex' do
|
19
|
-
assert contain(/The\slink/).matches?(@html)
|
20
|
-
end
|
21
|
-
|
22
|
-
test 'target does not match a given regex' do
|
23
|
-
assert !contain(/No\slink/).matches?(@html)
|
24
|
-
end
|
25
|
-
|
26
|
-
test 'treats newslines as spaces' do
|
27
|
-
assert contain('Some text').matches?("<p>Some\ntext</p>")
|
28
|
-
end
|
29
|
-
end
|
@@ -1,161 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class LocatorMatcherHaveTagTest < Test::Unit::TestCase
|
4
|
-
include Locator::Matcher
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@html = '<p><a class="foo">The link</a></p>'
|
8
|
-
end
|
9
|
-
|
10
|
-
# given a selector
|
11
|
-
|
12
|
-
test 'target matches a given selector' do
|
13
|
-
assert have_tag('The link').matches?(@html)
|
14
|
-
end
|
15
|
-
|
16
|
-
test 'target does not match a given selector' do
|
17
|
-
assert !have_tag('No link').matches?(@html)
|
18
|
-
end
|
19
|
-
|
20
|
-
# given an xpath
|
21
|
-
|
22
|
-
test 'target matches a given xpath' do
|
23
|
-
assert have_tag(:xpath => '//p/a[@class="foo"]').matches?(@html)
|
24
|
-
end
|
25
|
-
|
26
|
-
test 'target does not match a given xpath' do
|
27
|
-
assert !have_tag(:xpath => '//p/a[@id="foo"]').matches?(@html)
|
28
|
-
end
|
29
|
-
|
30
|
-
# given a css selector
|
31
|
-
|
32
|
-
test 'target matches a given css' do
|
33
|
-
assert have_tag(:css => 'p a.foo').matches?(@html)
|
34
|
-
end
|
35
|
-
|
36
|
-
test 'target does not match a given css' do
|
37
|
-
assert !have_tag(:css => 'p a#foo').matches?(@html)
|
38
|
-
end
|
39
|
-
|
40
|
-
# given a selector and xpath
|
41
|
-
|
42
|
-
test 'target matches a given selector and xpath' do
|
43
|
-
assert have_tag('The link', :xpath => '//p/a').matches?(@html)
|
44
|
-
end
|
45
|
-
|
46
|
-
test 'target does not match a given (wrong) selector and xpath' do
|
47
|
-
assert !have_tag('No link', :xpath => '//p/a').matches?(@html)
|
48
|
-
end
|
49
|
-
|
50
|
-
test 'target does not match a given selector and (wrong) xpath' do
|
51
|
-
assert !have_tag('The link', :xpath => '//p/div').matches?(@html)
|
52
|
-
end
|
53
|
-
|
54
|
-
# given a selector and css selector
|
55
|
-
|
56
|
-
test 'target matches a given selector and css selector' do
|
57
|
-
assert have_tag('The link', :css => 'p a').matches?(@html)
|
58
|
-
end
|
59
|
-
|
60
|
-
test 'target does not match a given (wrong) selector and css selector' do
|
61
|
-
assert !have_tag('No link', :css => 'p a').matches?(@html)
|
62
|
-
end
|
63
|
-
|
64
|
-
test 'target does not match a given selector and (wrong) css selector' do
|
65
|
-
assert !have_tag('The link', :css => 'p div').matches?(@html)
|
66
|
-
end
|
67
|
-
|
68
|
-
# given an xpath and attributes
|
69
|
-
|
70
|
-
test 'target matches a given xpath and attributes' do
|
71
|
-
assert have_tag(:xpath => '//p/a', :class => 'foo').matches?(@html)
|
72
|
-
end
|
73
|
-
|
74
|
-
test 'target does not match a given (wrong) xpath and attributes' do
|
75
|
-
assert !have_tag(:xpath => '//p/div', :class => 'foo').matches?(@html)
|
76
|
-
end
|
77
|
-
|
78
|
-
test 'target does not match a given xpath and (wrong) attributes' do
|
79
|
-
assert !have_tag(:xpath => '//p/a', :id => 'foo').matches?(@html)
|
80
|
-
end
|
81
|
-
|
82
|
-
# given selector, xpath and attributes
|
83
|
-
|
84
|
-
test 'target matches a given selector, xpath and attributes' do
|
85
|
-
assert have_tag('The link', :xpath => '//p/a', :class => 'foo').matches?(@html)
|
86
|
-
end
|
87
|
-
|
88
|
-
test 'target does not match a given (wrong) selector, xpath and attributes' do
|
89
|
-
assert !have_tag('The link', :xpath => '//p/div', :class => 'foo').matches?(@html)
|
90
|
-
end
|
91
|
-
|
92
|
-
test 'target does not match a given selector, (wrong) xpath and attributes' do
|
93
|
-
assert !have_tag('No link', :xpath => '//p/a', :class => 'foo').matches?(@html)
|
94
|
-
end
|
95
|
-
|
96
|
-
test 'target does not match a given selector, xpath and (wrong) attributes' do
|
97
|
-
assert !have_tag('The link', :xpath => '//p/a', :class => 'bar').matches?(@html)
|
98
|
-
end
|
99
|
-
|
100
|
-
# given a selector, css selector and attributes
|
101
|
-
|
102
|
-
test 'target matches a given selector, css selector and attributes' do
|
103
|
-
assert have_tag('The link', :css => 'p a', :class => 'foo').matches?(@html)
|
104
|
-
end
|
105
|
-
|
106
|
-
test 'target does not match a given (wrong) selector, css selector and attributes' do
|
107
|
-
assert !have_tag('The link', :css => 'p div', :class => 'foo').matches?(@html)
|
108
|
-
end
|
109
|
-
|
110
|
-
test 'target does not match a given selector, (wrong) css selector and attributes' do
|
111
|
-
assert !have_tag('No link', :css => 'p a', :class => 'foo').matches?(@html)
|
112
|
-
end
|
113
|
-
|
114
|
-
test 'target does not match a given selector, css selector and (wrong) attributes' do
|
115
|
-
assert !have_tag('The link', :css => 'p a', :class => 'bar').matches?(@html)
|
116
|
-
end
|
117
|
-
|
118
|
-
# using a block
|
119
|
-
|
120
|
-
# test 'given block selects from matched elements (block yields true)' do
|
121
|
-
# assert have_tag(:xpath => '//p') { true }.matches?(@html)
|
122
|
-
# end
|
123
|
-
#
|
124
|
-
# test 'given block selects from matched elements (block yields false)' do
|
125
|
-
# assert !have_tag(:xpath => '//p') { false }.matches?(@html)
|
126
|
-
# end
|
127
|
-
|
128
|
-
test 'can use have_path in the given block' do
|
129
|
-
assert have_tag(:xpath => '//p') { assert have_tag(:xpath => '//a').matches?(nil); true }.matches?(@html)
|
130
|
-
end
|
131
|
-
|
132
|
-
test 'uses a relative path when called in a block' do
|
133
|
-
assert have_tag(:xpath => '//p') { assert have_tag(:xpath => '//a').matches?(nil); true }.matches?(@html)
|
134
|
-
end
|
135
|
-
|
136
|
-
test 'does not match parent tags called in a block' do
|
137
|
-
assert have_tag(:xpath => '//a') { assert !have_tag(:xpath => '//p').matches?(nil); true }.matches?(@html)
|
138
|
-
end
|
139
|
-
|
140
|
-
# counting matches
|
141
|
-
|
142
|
-
test 'target contains the given number of elements' do
|
143
|
-
assert have_tag(:xpath => '//p/a', :count => 1).matches?(@html)
|
144
|
-
end
|
145
|
-
|
146
|
-
test 'target does not contain the given number of elements' do
|
147
|
-
assert !have_tag(:xpath => '//p/a', :count => 2).matches?(@html)
|
148
|
-
end
|
149
|
-
|
150
|
-
test 'target contains the given number of elements when used with a block' do
|
151
|
-
assert have_tag(:xpath => '//p/a', :count => 1) { |element| element.name == 'a' }.matches?(@html)
|
152
|
-
end
|
153
|
-
|
154
|
-
test 'target does not contain the given number of elements when used with a block (too few elements)' do
|
155
|
-
assert !have_tag(:xpath => '//p/a', :count => 2) { |element| element.name == 'a' }.matches?(@html)
|
156
|
-
end
|
157
|
-
|
158
|
-
test 'target does not contain the given number of elements when used with a block (block does not match)' do
|
159
|
-
assert !have_tag(:xpath => '//p/a', :count => 1) { |element| element.name == 'div' }.matches?(@html)
|
160
|
-
end
|
161
|
-
end
|
data/test/locator/xpath_test.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'locator/xpath'
|
3
|
-
|
4
|
-
class XpathTest < Test::Unit::TestCase
|
5
|
-
Xpath = Locator::Xpath
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Locator::Boolean::Or.operator, Locator::Boolean::And.operator = ' | ', ''
|
9
|
-
end
|
10
|
-
|
11
|
-
test "simple xpath" do
|
12
|
-
path = Xpath.new('input').to_s
|
13
|
-
assert_equal ".//input", path
|
14
|
-
end
|
15
|
-
|
16
|
-
test "xpath with alternate nodenames" do
|
17
|
-
path = Xpath.new(['input', 'button']).to_s
|
18
|
-
assert_equal ".//input | .//button", path
|
19
|
-
end
|
20
|
-
|
21
|
-
test "xpath with attributes" do
|
22
|
-
path = Xpath.new(['input', 'button'], :type => 'text', :id => 'foo')
|
23
|
-
assert_equal %(.//input[@type="text"][@id="foo"] | .//button[@type="text"][@id="foo"]), path.to_s
|
24
|
-
end
|
25
|
-
|
26
|
-
test "xpath with alternate nodenames and attributes" do
|
27
|
-
path = Xpath.new(['input', 'button']).to_s
|
28
|
-
assert_equal ".//input | .//button", path
|
29
|
-
end
|
30
|
-
|
31
|
-
test "attribute equals to one of multiple values" do
|
32
|
-
path = Xpath.new('input', :type => [:text, :password]).to_s
|
33
|
-
assert_equal %(.//input[@type="text" or @type="password"]), path
|
34
|
-
end
|
35
|
-
|
36
|
-
test "one of multiple attributes equals to value" do
|
37
|
-
path = Xpath.new('input', [:id, :name] => 'foo').to_s
|
38
|
-
assert_equal %(.//input[@id="foo" or @name="foo"]), path
|
39
|
-
end
|
40
|
-
|
41
|
-
test "one of multiple attributes equals to one of multiple values" do
|
42
|
-
path = Xpath.new('input', [:id, :name] => ['foo', 'bar']).to_s
|
43
|
-
assert_equal %(.//input[@id="foo" or @id="bar" or @name="foo" or @name="bar"]), path
|
44
|
-
end
|
45
|
-
end
|
data/test/locator_test.rb
DELETED
@@ -1,132 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.expand_path('../test_helper', __FILE__)
|
3
|
-
|
4
|
-
class LocatorTest < Test::Unit::TestCase
|
5
|
-
include Locator
|
6
|
-
|
7
|
-
# test "returns the element if given an element" do
|
8
|
-
# html = '<p></p>'
|
9
|
-
# element = locate(html, :p)
|
10
|
-
# assert_equal element, locate(html, element)
|
11
|
-
# end
|
12
|
-
|
13
|
-
test "looks up a locator/element class by type" do
|
14
|
-
assert_equal Locator::Element::Field, Locator[:field]
|
15
|
-
end
|
16
|
-
|
17
|
-
test "generates an xpath for type and given args" do
|
18
|
-
xpath = xpath(:form, :id => 'bar')
|
19
|
-
assert_equal './/form[@id="bar"]', xpath
|
20
|
-
end
|
21
|
-
|
22
|
-
# locate
|
23
|
-
|
24
|
-
test "locates the first element by node name" do
|
25
|
-
html = '<html><body><form id="foo"></form><form id="bar"></form></body></html>'
|
26
|
-
element = locate(html, :form)
|
27
|
-
assert_equal 'foo', element.attribute('id')
|
28
|
-
end
|
29
|
-
|
30
|
-
test "locates the first element by xpath" do
|
31
|
-
html = '<html><body><form id="foo"></form><form id="bar"></form></body></html>'
|
32
|
-
element = locate(html, :xpath => '//form')
|
33
|
-
assert_equal 'foo', element.attribute('id')
|
34
|
-
end
|
35
|
-
|
36
|
-
# within
|
37
|
-
|
38
|
-
test "within scopes to a locator" do
|
39
|
-
html = '<form></form><div id="bar"><form id="foo"></form></div>'
|
40
|
-
element = within(html, :div, :id => 'bar') { locate(:form) }
|
41
|
-
assert_equal 'foo', element.attribute('id')
|
42
|
-
end
|
43
|
-
|
44
|
-
test "within scopes to a css selector" do
|
45
|
-
html = '<form></form><div id="bar"><form id="foo"></form></div>'
|
46
|
-
element = within(html, '#bar') { locate(:form) }
|
47
|
-
assert_equal 'foo', element.attribute('id')
|
48
|
-
end
|
49
|
-
|
50
|
-
test "within scopes to an xpath" do
|
51
|
-
html = '<form></form><div id="bar"><form id="foo"></form></div>'
|
52
|
-
element = within(html, '//div[@id="bar"]') { locate(:form) }
|
53
|
-
assert_equal 'foo', element.attribute('id')
|
54
|
-
end
|
55
|
-
|
56
|
-
test "nested within blocks" do
|
57
|
-
html = '<form></form><div><form><p id="foo"><p></form></div>'
|
58
|
-
element = within(html, :div) { within(:form) { locate(:p) } }
|
59
|
-
assert_equal 'foo', element.attribute('id')
|
60
|
-
end
|
61
|
-
|
62
|
-
test "locates scopes to :within option (css selector)" do
|
63
|
-
html = '<form></form><div><form id="foo"></form></div>'
|
64
|
-
element = locate(html, :form, :within => 'div')
|
65
|
-
assert_equal 'foo', element.attribute('id')
|
66
|
-
end
|
67
|
-
|
68
|
-
test "locates scopes to :within option (xpath)" do
|
69
|
-
html = '<form></form><div><form id="foo"></form></div>'
|
70
|
-
element = locate(html, :form, :within => '//div')
|
71
|
-
assert_equal 'foo', element.attribute('id')
|
72
|
-
end
|
73
|
-
|
74
|
-
test "within/locate with module included" do
|
75
|
-
html = '<form></form><div><form id="foo"></form></div>'
|
76
|
-
element = within(html, :div) { locate(:form) }
|
77
|
-
assert_equal 'foo', element.attribute('id')
|
78
|
-
end
|
79
|
-
|
80
|
-
test "locate when given a block scopes the block to the located element" do
|
81
|
-
html = '<p id="foo"><p><form></form><div><form><p id="bar"><p></form></div>'
|
82
|
-
element = locate(html, :div) { locate(:form) { locate(:p) } }
|
83
|
-
assert_equal 'bar', element.attribute('id')
|
84
|
-
end
|
85
|
-
|
86
|
-
test "locate does not yield the block when no element was found (would otherwise locate in global scope)" do
|
87
|
-
html = '<form></form><div><form><p id="foo"><p></form></div>'
|
88
|
-
assert_nil locate(html, :div) { locate(html, :form, :class => 'bar') { locate(html, :p) } }
|
89
|
-
end
|
90
|
-
|
91
|
-
# locate with umlauts
|
92
|
-
|
93
|
-
test "locates an element by encoded selector from html containing an encoded umlaut" do
|
94
|
-
html = '<span>Berlin</span><span>München</span>'
|
95
|
-
assert_equal 'München', locate(html, 'München').content
|
96
|
-
end
|
97
|
-
|
98
|
-
test "locates an element by encoded selector from html containing an non-encoded umlaut" do
|
99
|
-
html = '<span>Berlin</span><span>München</span>'
|
100
|
-
assert_equal 'München', locate(html, 'München').content
|
101
|
-
end
|
102
|
-
|
103
|
-
test "locates an element by non-encoded selector from html containing an encoded umlaut" do
|
104
|
-
html = '<span>Berlin</span><span>München</span>'
|
105
|
-
assert_equal 'München', locate(html, 'München').content
|
106
|
-
end
|
107
|
-
|
108
|
-
test "locates an element by non-encoded selector from html containing a non-encoded umlaut" do
|
109
|
-
html = '<span>Berlin</span><span>München</span>'
|
110
|
-
assert_equal 'München', locate(html, 'München').content
|
111
|
-
end
|
112
|
-
|
113
|
-
test "locates an element by encoded attribute from html containing an encoded umlaut" do
|
114
|
-
html = '<input type="text" value="München">'
|
115
|
-
assert_equal 'München', locate(html, :value => 'München').value
|
116
|
-
end
|
117
|
-
|
118
|
-
test "locates an element by encoded attribute from html containing an non-encoded umlaut" do
|
119
|
-
html = '<input type="text" value="München">'
|
120
|
-
assert_equal 'München', locate(html, :value => 'München').value
|
121
|
-
end
|
122
|
-
|
123
|
-
test "locates an element by non-encoded attribute from html containing an encoded umlaut" do
|
124
|
-
html = '<input type="text" value="München">'
|
125
|
-
assert_equal 'München', locate(html, :value => 'München').value
|
126
|
-
end
|
127
|
-
|
128
|
-
test "locates an element by non-encoded attribute from html containing a non-encoded umlaut" do
|
129
|
-
html = '<input type="text" value="München">'
|
130
|
-
assert_equal 'München', locate(html, :value => 'München').value
|
131
|
-
end
|
132
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
$:.unshift File.expand_path("../lib", File.dirname(__FILE__))
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'locator'
|
5
|
-
|
6
|
-
module TestMethod
|
7
|
-
def self.included(base)
|
8
|
-
base.class_eval do
|
9
|
-
def self.test(name, &block)
|
10
|
-
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
11
|
-
defined = instance_method(test_name) rescue false
|
12
|
-
raise "#{test_name} is already defined in #{self}" if defined
|
13
|
-
if block_given?
|
14
|
-
define_method(test_name, &block)
|
15
|
-
else
|
16
|
-
define_method(test_name) do
|
17
|
-
flunk "No implementation provided for #{name}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class Module
|
26
|
-
include TestMethod
|
27
|
-
end
|
28
|
-
|
29
|
-
class Test::Unit::TestCase
|
30
|
-
include TestMethod
|
31
|
-
end
|
data/test/webrat.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.expand_path('../test_helper', __FILE__)
|
3
|
-
require 'action_pack'
|
4
|
-
require 'webrat'
|
5
|
-
require 'rack/test'
|
6
|
-
|
7
|
-
Webrat.configure do |config|
|
8
|
-
config.mode = :rack
|
9
|
-
end
|
10
|
-
|
11
|
-
class WebratBehaviorTest < Test::Unit::TestCase
|
12
|
-
include Webrat::Methods
|
13
|
-
|
14
|
-
def last_response
|
15
|
-
@last_response ||= Rack::Response.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def with_html(html)
|
19
|
-
last_response.body = html
|
20
|
-
end
|
21
|
-
|
22
|
-
test "foo" do
|
23
|
-
with_html '<span>München</span>'
|
24
|
-
field = field_by_xpath(".//span")
|
25
|
-
p field.element.to_s
|
26
|
-
end
|
27
|
-
end
|