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,42 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
class NokogiriTest < Test::Unit::TestCase
|
5
|
-
include Locator
|
6
|
-
|
7
|
-
# test "Element takes a Nokogiri dom" do
|
8
|
-
# dom = Nokogiri::HTML::Document.parse('<a href="#">the link</a>')
|
9
|
-
# assert Element.new.locate(dom, 'the link')
|
10
|
-
# end
|
11
|
-
|
12
|
-
test "Element takes a Nokogiri page adapter" do
|
13
|
-
dom = Locator::Dom::Nokogiri::Page.new('<a href="#">the link</a>')
|
14
|
-
assert Element.new.locate(dom, 'the link')
|
15
|
-
end
|
16
|
-
|
17
|
-
# test "Nokogiri and Umlauts" do
|
18
|
-
# encoded = '<p>ö</p>'
|
19
|
-
# unencoded = '<p>ö</p>'
|
20
|
-
#
|
21
|
-
# # this is ok
|
22
|
-
# fragment = Nokogiri::HTML.fragment(encoded)
|
23
|
-
# assert_equal encoded, fragment.to_s
|
24
|
-
#
|
25
|
-
# # this seems weird ... wtf experiences ahead
|
26
|
-
# fragment = Nokogiri::HTML.fragment(unencoded)
|
27
|
-
# assert_equal encoded, fragment.to_s
|
28
|
-
#
|
29
|
-
# options =
|
30
|
-
# Nokogiri::XML::ParseOptions::RECOVER |
|
31
|
-
# Nokogiri::XML::ParseOptions::NOERROR |
|
32
|
-
# Nokogiri::XML::ParseOptions::NOWARNING
|
33
|
-
#
|
34
|
-
# # this is ok
|
35
|
-
# node = Nokogiri::HTML.parse(encoded, nil, nil, options)
|
36
|
-
# assert_equal encoded, node.xpath('//p').first.to_s
|
37
|
-
#
|
38
|
-
# # this is ok
|
39
|
-
# node = Nokogiri::HTML.parse(unencoded, nil, 'utf-8', options)
|
40
|
-
# assert_equal unencoded, node.xpath('//p').first.to_s
|
41
|
-
# end
|
42
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
require 'locator/element'
|
3
|
-
|
4
|
-
class ElementButtonTest < Test::Unit::TestCase
|
5
|
-
Button = Locator::Element::Button
|
6
|
-
|
7
|
-
test "finds a button" do
|
8
|
-
html = '<button></button>'
|
9
|
-
assert_equal 'button', Button.new.locate(html).name
|
10
|
-
end
|
11
|
-
|
12
|
-
test "finds a submit input" do
|
13
|
-
html = '<input type="submit">'
|
14
|
-
assert_equal 'input', Button.new.locate(html).name
|
15
|
-
end
|
16
|
-
|
17
|
-
test "finds a button input" do
|
18
|
-
html = '<input type="button">'
|
19
|
-
assert_equal 'input', Button.new.locate(html).name
|
20
|
-
end
|
21
|
-
|
22
|
-
test "finds an image input" do
|
23
|
-
html = '<input type="image">'
|
24
|
-
assert_equal 'input', Button.new.locate(html).name
|
25
|
-
end
|
26
|
-
|
27
|
-
test "does not find a checkbox input" do
|
28
|
-
html = '<input type="checkbox">'
|
29
|
-
assert_nil Button.new.locate(html)
|
30
|
-
end
|
31
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
require 'locator/element'
|
3
|
-
|
4
|
-
class ElementFieldTest < Test::Unit::TestCase
|
5
|
-
Field = Locator::Element::Field
|
6
|
-
|
7
|
-
test "finds a textarea" do
|
8
|
-
html = '<textarea></textarea>'
|
9
|
-
assert_equal 'textarea', Field.new.locate(html).name
|
10
|
-
end
|
11
|
-
|
12
|
-
test "finds a text input" do
|
13
|
-
html = '<input type="text">'
|
14
|
-
assert_equal 'input', Field.new.locate(html).name
|
15
|
-
end
|
16
|
-
|
17
|
-
test "finds a password input" do
|
18
|
-
html = '<input type="password">'
|
19
|
-
assert_equal 'input', Field.new.locate(html).name
|
20
|
-
end
|
21
|
-
|
22
|
-
test "finds an email input" do
|
23
|
-
html = '<input type="email">'
|
24
|
-
assert_equal 'input', Field.new.locate(html).name
|
25
|
-
end
|
26
|
-
|
27
|
-
test "finds a url input" do
|
28
|
-
html = '<input type="url">'
|
29
|
-
assert_equal 'input', Field.new.locate(html).name
|
30
|
-
end
|
31
|
-
|
32
|
-
test "finds a search input" do
|
33
|
-
html = '<input type="search">'
|
34
|
-
assert_equal 'input', Field.new.locate(html).name
|
35
|
-
end
|
36
|
-
|
37
|
-
test "finds a tel input" do
|
38
|
-
html = '<input type="tel">'
|
39
|
-
assert_equal 'input', Field.new.locate(html).name
|
40
|
-
end
|
41
|
-
|
42
|
-
test "finds a color input" do
|
43
|
-
html = '<input type="color">'
|
44
|
-
assert_equal 'input', Field.new.locate(html).name
|
45
|
-
end
|
46
|
-
|
47
|
-
test "finds a text input by name" do
|
48
|
-
html = '<input type="text" name="foo">'
|
49
|
-
assert_equal 'input', Field.new.locate(html, 'foo').name
|
50
|
-
end
|
51
|
-
|
52
|
-
test "finds a text input by class attribute" do
|
53
|
-
html = '<input type="text" class="foo">'
|
54
|
-
assert_equal 'input', Field.new.locate(html, :class => 'foo').name
|
55
|
-
end
|
56
|
-
|
57
|
-
test "finds an input by label content" do
|
58
|
-
html = '<label for="bar">foo</label><input type="text" id="bar">'
|
59
|
-
assert_equal 'input', Field.new.locate(html, 'foo').name
|
60
|
-
end
|
61
|
-
|
62
|
-
test "finds an input by label content and input class" do
|
63
|
-
html = '<label for="bar">foo</label><input type="text" id="bar" class="baz">'
|
64
|
-
assert_equal 'input', Field.new.locate(html, 'foo', :class => 'baz').name
|
65
|
-
end
|
66
|
-
|
67
|
-
test "does not find a checkbox input" do
|
68
|
-
html = '<input type="checkbox">'
|
69
|
-
assert_nil Field.new.locate(html)
|
70
|
-
end
|
71
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
require 'locator/element'
|
3
|
-
|
4
|
-
class ElementFormTest < Test::Unit::TestCase
|
5
|
-
Form = Locator::Element::Form
|
6
|
-
|
7
|
-
test "finds a form" do
|
8
|
-
html = '<form></form>'
|
9
|
-
assert_equal 'form', Form.new.locate(html).name
|
10
|
-
end
|
11
|
-
|
12
|
-
test "finds a form by id" do
|
13
|
-
html = '<form id="foo"></form>'
|
14
|
-
assert_equal 'form', Form.new.locate(html, 'foo').name
|
15
|
-
end
|
16
|
-
|
17
|
-
test "finds a form by name" do
|
18
|
-
html = '<form name="foo"></form>'
|
19
|
-
assert_equal 'form', Form.new.locate(html, 'foo').name
|
20
|
-
end
|
21
|
-
|
22
|
-
test "finds a form by class" do
|
23
|
-
html = '<form class="foo"></form>'
|
24
|
-
assert_equal 'form', Form.new.locate(html, :class => 'foo').name
|
25
|
-
end
|
26
|
-
|
27
|
-
test "does not find a form when id does not match" do
|
28
|
-
html = '<form id="bar"></form>'
|
29
|
-
assert_nil Form.new.locate(html, :class => 'foo')
|
30
|
-
end
|
31
|
-
|
32
|
-
test "does not find a form when class does not match" do
|
33
|
-
html = '<form class="bar"></form>'
|
34
|
-
assert_nil Form.new.locate(html, :class => 'foo')
|
35
|
-
end
|
36
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
require 'locator/element'
|
3
|
-
|
4
|
-
class ElementHiddenFieldTest < Test::Unit::TestCase
|
5
|
-
HiddenField = Locator::Element::HiddenField
|
6
|
-
|
7
|
-
test "finds a hidden input" do
|
8
|
-
html = '<input type="hidden" />'
|
9
|
-
assert_equal 'input', HiddenField.new.locate(html).name
|
10
|
-
end
|
11
|
-
|
12
|
-
test "finds a hidden input by id" do
|
13
|
-
html = '<input type="hidden" id="foo" />'
|
14
|
-
assert_equal 'input', HiddenField.new.locate(html, 'foo').name
|
15
|
-
end
|
16
|
-
|
17
|
-
test "finds a hidden input by name" do
|
18
|
-
html = '<input type="hidden" name="foo" />'
|
19
|
-
assert_equal 'input', HiddenField.new.locate(html, 'foo').name
|
20
|
-
end
|
21
|
-
|
22
|
-
test "finds a hidden input by class" do
|
23
|
-
html = '<input type="hidden" class="foo" />'
|
24
|
-
assert_equal 'input', HiddenField.new.locate(html, :class => 'foo').name
|
25
|
-
end
|
26
|
-
|
27
|
-
test "does not find a hidden input when id does not match" do
|
28
|
-
html = '<input type="hidden" id="bar" />'
|
29
|
-
assert_nil HiddenField.new.locate(html, :class => 'foo')
|
30
|
-
end
|
31
|
-
|
32
|
-
test "does not find a hidden input when class does not match" do
|
33
|
-
html = '<input type="hidden" class="bar" />'
|
34
|
-
assert_nil HiddenField.new.locate(html, :class => 'foo')
|
35
|
-
end
|
36
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class ElementLabelTest < Test::Unit::TestCase
|
4
|
-
Label = Locator::Element::Label
|
5
|
-
|
6
|
-
test "finds a label" do
|
7
|
-
html = '<label></label>'
|
8
|
-
assert_equal 'label', Label.new.locate(html).name
|
9
|
-
end
|
10
|
-
|
11
|
-
test "finds a label by id" do
|
12
|
-
html = '<label id="foo"></label>'
|
13
|
-
assert_equal 'label', Label.new.locate(html, 'foo').name
|
14
|
-
end
|
15
|
-
|
16
|
-
test "finds a label by class" do
|
17
|
-
html = '<label class="foo"></label>'
|
18
|
-
assert_equal 'label', Label.new.locate(html, :class => 'foo').name
|
19
|
-
end
|
20
|
-
|
21
|
-
test "does not find a label when id does not match" do
|
22
|
-
html = '<label id="bar"></label>'
|
23
|
-
assert_nil Label.new.locate(html, :class => 'foo')
|
24
|
-
end
|
25
|
-
|
26
|
-
test "does not find a label when class does not match" do
|
27
|
-
html = '<label class="bar"></label>'
|
28
|
-
assert_nil Label.new.locate(html, :class => 'foo')
|
29
|
-
end
|
30
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class LocatorElementLinkTest < Test::Unit::TestCase
|
4
|
-
Link = Locator::Element::Link
|
5
|
-
|
6
|
-
test "finds a link" do
|
7
|
-
html = '<a class="foo"></a><a href="" class="bar"></a>'
|
8
|
-
assert_equal 'bar', Link.new.locate(html).attribute('class')
|
9
|
-
end
|
10
|
-
|
11
|
-
test "finds a link by id" do
|
12
|
-
html = '<a href="" id="foo"></a><a href="" id="bar"></a>'
|
13
|
-
assert_equal 'bar', Link.new.locate(html, :id => 'bar').attribute('id')
|
14
|
-
end
|
15
|
-
|
16
|
-
test "finds a link by class" do
|
17
|
-
html = '<a href="" class="foo"></a><a href="" class="bar"></a>'
|
18
|
-
assert_equal 'bar', Link.new.locate(html, :class => 'bar').attribute('class')
|
19
|
-
end
|
20
|
-
|
21
|
-
test "finds a link by content" do
|
22
|
-
html = '<a href="">foo</a><a href="">bar</a>'
|
23
|
-
assert_equal 'bar', Link.new.locate(html, 'bar').content
|
24
|
-
end
|
25
|
-
|
26
|
-
test "does not find an anchor" do
|
27
|
-
html =
|
28
|
-
assert_nil Link.new.locate('<a name="">foo</a>')
|
29
|
-
end
|
30
|
-
|
31
|
-
test "finds a link with a href starting with a slash" do
|
32
|
-
html = '<a href="/foo/bar" class="foo"></a><a href="" class="bar"></a>'
|
33
|
-
assert_equal '/foo/bar', Link.new.locate(html, :href => '/foo/bar').attribute('href')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
require 'locator/element'
|
3
|
-
|
4
|
-
class ElementSelectOptionOptionTest < Test::Unit::TestCase
|
5
|
-
SelectOption = Locator::Element::SelectOption
|
6
|
-
|
7
|
-
test "finds an option" do
|
8
|
-
html = '<option></option>'
|
9
|
-
assert_equal 'option', SelectOption.new.locate(html).name
|
10
|
-
end
|
11
|
-
|
12
|
-
test "finds an option by id" do
|
13
|
-
html = '<option id="foo"></option>'
|
14
|
-
assert_equal 'option', SelectOption.new.locate(html, 'foo').name
|
15
|
-
end
|
16
|
-
|
17
|
-
test "finds an option by value" do
|
18
|
-
html = '<option value="foo"></option>'
|
19
|
-
assert_equal 'option', SelectOption.new.locate(html, 'foo').name
|
20
|
-
end
|
21
|
-
|
22
|
-
test "finds an option by content" do
|
23
|
-
html = '<option>foo</option>'
|
24
|
-
assert_equal 'option', SelectOption.new.locate(html, 'foo').name
|
25
|
-
end
|
26
|
-
|
27
|
-
test "finds an option by class attribute" do
|
28
|
-
html = '<option class="foo"></option>'
|
29
|
-
assert_equal 'option', SelectOption.new.locate(html, :class => 'foo').name
|
30
|
-
end
|
31
|
-
|
32
|
-
test "does not find an option when id does not match" do
|
33
|
-
html = '<option id="bar"></option>'
|
34
|
-
assert_nil SelectOption.new.locate(html, :class => 'foo')
|
35
|
-
end
|
36
|
-
|
37
|
-
test "does not find an option when class does not match" do
|
38
|
-
html = '<option class="bar"></option>'
|
39
|
-
assert_nil SelectOption.new.locate(html, :class => 'foo')
|
40
|
-
end
|
41
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class ElementSelectTest < Test::Unit::TestCase
|
4
|
-
Select = Locator::Element::Select
|
5
|
-
|
6
|
-
test "finds a select" do
|
7
|
-
html = '<select id="foo" class="foo"></select><select id="bar" class="bar"></select>'
|
8
|
-
assert_equal 'select', Select.new.locate(html).name
|
9
|
-
end
|
10
|
-
|
11
|
-
test "finds a select by id" do
|
12
|
-
html = '<select id="foo"></select>'
|
13
|
-
assert_equal 'select', Select.new.locate(html, 'foo').name
|
14
|
-
end
|
15
|
-
|
16
|
-
test "finds a select by class" do
|
17
|
-
html = '<select class="foo"></select>'
|
18
|
-
assert_equal 'select', Select.new.locate(html, :class => 'foo').name
|
19
|
-
end
|
20
|
-
|
21
|
-
test "does not find a select when id does not match" do
|
22
|
-
html = '<select id="bar"></select>'
|
23
|
-
assert_nil Select.new.locate(html, :class => 'foo')
|
24
|
-
end
|
25
|
-
|
26
|
-
test "does not find a select when class does not match" do
|
27
|
-
html = '<select class="bar"></select>'
|
28
|
-
assert_nil Select.new.locate(html, :class => 'foo')
|
29
|
-
end
|
30
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
require 'locator/element'
|
3
|
-
|
4
|
-
class ElementTextAreaTest < Test::Unit::TestCase
|
5
|
-
TextArea = Locator::Element::TextArea
|
6
|
-
|
7
|
-
test "finds a textarea" do
|
8
|
-
html = '<textarea></textarea>'
|
9
|
-
assert_equal 'textarea', TextArea.new.locate(html).name
|
10
|
-
end
|
11
|
-
|
12
|
-
test "finds a textarea by id" do
|
13
|
-
html = '<textarea id="foo"></textarea>'
|
14
|
-
assert_equal 'textarea', TextArea.new.locate(html, 'foo').name
|
15
|
-
end
|
16
|
-
|
17
|
-
test "finds a textarea by class" do
|
18
|
-
html = '<textarea class="foo"></textarea>'
|
19
|
-
assert_equal 'textarea', TextArea.new.locate(html, :class => 'foo').name
|
20
|
-
end
|
21
|
-
|
22
|
-
test "does not find a textarea when id does not match" do
|
23
|
-
html = '<textarea id="bar"></textarea>'
|
24
|
-
assert_nil TextArea.new.locate(html, :class => 'foo')
|
25
|
-
end
|
26
|
-
|
27
|
-
test "does not find a textarea when class does not match" do
|
28
|
-
html = '<textarea class="bar"></textarea>'
|
29
|
-
assert_nil TextArea.new.locate(html, :class => 'foo')
|
30
|
-
end
|
31
|
-
end
|
@@ -1,136 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.expand_path('../../test_helper', __FILE__)
|
3
|
-
|
4
|
-
class LocatorElementTest < Test::Unit::TestCase
|
5
|
-
include Locator
|
6
|
-
|
7
|
-
# xpath
|
8
|
-
|
9
|
-
test "xpath without further arguments given" do
|
10
|
-
assert_equal './/*', Element.new.xpath
|
11
|
-
end
|
12
|
-
|
13
|
-
test "xpath of an element with a node name" do
|
14
|
-
xpath = Element.new(:div).xpath
|
15
|
-
assert_equal './/div', xpath
|
16
|
-
end
|
17
|
-
|
18
|
-
test "xpath of an element with attributes" do
|
19
|
-
xpath = Element.new(nil, :type => 'type', :class => 'class').xpath
|
20
|
-
assert_equal ".//*[@type=\"type\"][contains(concat(' ', @class, ' '), concat(' ', \"class\", ' '))]", xpath
|
21
|
-
end
|
22
|
-
|
23
|
-
test "xpath of an element with node name and attributes" do
|
24
|
-
xpath = Element.new(:div, :type => 'type', :class => 'class').xpath
|
25
|
-
assert_equal ".//div[@type=\"type\"][contains(concat(' ', @class, ' '), concat(' ', \"class\", ' '))]", xpath
|
26
|
-
end
|
27
|
-
|
28
|
-
test "xpath of an element with multiple node name and attributes" do
|
29
|
-
xpath = Element.new([:div, :p], :type => 'type').xpath
|
30
|
-
assert_equal ".//div[@type=\"type\"] | .//p[@type=\"type\"]", xpath
|
31
|
-
end
|
32
|
-
|
33
|
-
test "xpath merges given attributes with element attributes" do
|
34
|
-
xpath = Element.new(:div, :foo => 'foo').xpath(:bar => 'bar')
|
35
|
-
assert xpath.include?(".//div")
|
36
|
-
assert xpath.include?("[@foo=\"foo\"]") # humpf, unsorted hash
|
37
|
-
assert xpath.include?("[@bar=\"bar\"]")
|
38
|
-
end
|
39
|
-
|
40
|
-
test "xpath with given xpath and attributes" do
|
41
|
-
xpath = Element.new.xpath('.//div', :foo => 'foo')
|
42
|
-
assert_equal ".//div[@foo=\"foo\"]", xpath
|
43
|
-
end
|
44
|
-
|
45
|
-
# all
|
46
|
-
|
47
|
-
test "all selects all elements when given no attributes" do
|
48
|
-
html = '<a class="foo"></a><p class="bar"></p>'
|
49
|
-
elements = Element.new.all(html)
|
50
|
-
assert_equal %w(html body a p), elements.map { |element| element.name }
|
51
|
-
end
|
52
|
-
|
53
|
-
test "all selects all nodes with given node name" do
|
54
|
-
html = '<a class="foo"></a><p class="bar"></p>'
|
55
|
-
elements = Element.new('a').all(html)
|
56
|
-
assert_equal %w(a), elements.map { |element| element.name }
|
57
|
-
end
|
58
|
-
|
59
|
-
test "all selects all nodes with attribute given to initialize" do
|
60
|
-
html = '<a class="foo"></a><p class="bar"></p>'
|
61
|
-
elements = Element.new(:class => 'foo').all(html)
|
62
|
-
assert_equal %w(a), elements.map { |element| element.name }
|
63
|
-
end
|
64
|
-
|
65
|
-
test "all selects all nodes with attribute given to all" do
|
66
|
-
html = '<a class="foo"></a><p class="bar"></p>'
|
67
|
-
elements = Element.new.all(html, :class => 'foo')
|
68
|
-
assert_equal %w(a), elements.map { |element| element.name }
|
69
|
-
end
|
70
|
-
|
71
|
-
# locate
|
72
|
-
|
73
|
-
test "locate selects an element based on the length of the matching value" do
|
74
|
-
html = %(
|
75
|
-
<a href="#">the link with extra text</a>
|
76
|
-
<a href="http://www.some-very-long-url.com">the link ...</a>
|
77
|
-
)
|
78
|
-
element = Element.new.locate(html, 'the link')
|
79
|
-
assert_equal 'the link ...', element.content
|
80
|
-
end
|
81
|
-
|
82
|
-
test "locate selects an element containing whitespace" do
|
83
|
-
html = %(
|
84
|
-
<a href="#">
|
85
|
-
the
|
86
|
-
link
|
87
|
-
</a>
|
88
|
-
)
|
89
|
-
assert Element.new.locate(html, 'the link')
|
90
|
-
end
|
91
|
-
|
92
|
-
test "locate selects an element containing extra tags" do
|
93
|
-
html = '<a href="#">the <span>link</span></a>'
|
94
|
-
assert Element.new.locate(html, 'the link')
|
95
|
-
end
|
96
|
-
|
97
|
-
test "locate selects an element containing extra text (1)" do
|
98
|
-
html = '<a href="#">the link »</label>'
|
99
|
-
assert Element.new.locate(html, 'the link')
|
100
|
-
end
|
101
|
-
|
102
|
-
test "locate selects an element containing extra text (2)" do
|
103
|
-
html = '<a href="#">(the link)</label>'
|
104
|
-
assert Element.new.locate(html, 'the link')
|
105
|
-
end
|
106
|
-
|
107
|
-
test "does not find a link when id does not match" do
|
108
|
-
html = '<a href="" id="bar"></a>'
|
109
|
-
assert_nil Element.new.locate(html, :id => 'foo')
|
110
|
-
end
|
111
|
-
|
112
|
-
test "does not find a link when class does not match" do
|
113
|
-
html = '<a href="" class="bar"></a>'
|
114
|
-
assert_nil Element.new.locate(html, :class => 'foo')
|
115
|
-
end
|
116
|
-
|
117
|
-
test "locate using an xpath" do
|
118
|
-
html = '<a class="foo" href="#"></a><a class="bar" href="#"></a>'
|
119
|
-
assert_equal 'bar', Element::Link.new.locate(html, :xpath => '//a[@class="bar"]').attribute('class')
|
120
|
-
end
|
121
|
-
|
122
|
-
test "locate using a css selector" do
|
123
|
-
html = '<a class="foo" href="#"></a><a class="bar" href="#"></a>'
|
124
|
-
assert_equal 'bar', Element::Link.new.locate(html, :css => '.bar').attribute('class')
|
125
|
-
end
|
126
|
-
|
127
|
-
test "locate selects an element containing an umlaut" do
|
128
|
-
html = '<a href="#">the lünk</a>'
|
129
|
-
assert Element.new.locate(html, 'the lünk')
|
130
|
-
end
|
131
|
-
|
132
|
-
test "locate selects an element with an attribute containing an umlaut" do
|
133
|
-
html = '<input type="text" value="München" />'
|
134
|
-
assert Element.new.locate(html, :value => 'München')
|
135
|
-
end
|
136
|
-
end
|