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
data/Rakefile
CHANGED
@@ -9,23 +9,4 @@ task :default => :test
|
|
9
9
|
desc 'Run all tests.'
|
10
10
|
Rake::TestTask.new(:test) do |t|
|
11
11
|
load 'test/all.rb'
|
12
|
-
end
|
13
|
-
|
14
|
-
begin
|
15
|
-
require 'jeweler'
|
16
|
-
Jeweler::Tasks.new do |s|
|
17
|
-
require File.expand_path("../lib/locator/version", __FILE__)
|
18
|
-
|
19
|
-
s.name = "locator"
|
20
|
-
s.version = Locator::VERSION
|
21
|
-
s.summary = "Generic html element locators for integration testing"
|
22
|
-
s.email = "svenfuchs@artweb-design.de"
|
23
|
-
s.homepage = "http://github.com/svenfuchs/locator"
|
24
|
-
s.description = "Generic html element locators for integration testing"
|
25
|
-
s.authors = ['Sven Fuchs']
|
26
|
-
s.files = FileList["[A-Z]*", "{lib,test,vendor}/**/*"]
|
27
|
-
s.add_dependency 'htmlentities'
|
28
|
-
end
|
29
|
-
rescue LoadError
|
30
|
-
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
31
|
-
end
|
12
|
+
end
|
data/lib/locator/matcher.rb
CHANGED
@@ -1,70 +1,84 @@
|
|
1
1
|
module Locator
|
2
2
|
module Matcher
|
3
|
-
autoload :HaveTag,
|
3
|
+
autoload :HaveTag, 'locator/matcher/have_tag'
|
4
|
+
autoload :HaveCssClass, 'locator/matcher/have_css_class'
|
4
5
|
|
5
6
|
# Matches an HTML document with whatever string is given
|
6
7
|
def contain(*args)
|
7
8
|
HaveTag.new(*args)
|
8
9
|
end
|
9
10
|
|
11
|
+
def have_tag(*args, &block)
|
12
|
+
HaveTag.new(*args, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def have_xpath(xpath, options = {}, &block)
|
16
|
+
HaveTag.new(options.delete(:content), options.merge(:xpath => xpath), &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def have_css(css, options = {}, &block)
|
20
|
+
HaveTag.new(options.delete(:content), options.merge(:css => css), &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def have_css_class(css_class)
|
24
|
+
HaveCssClass.new(css_class)
|
25
|
+
end
|
26
|
+
|
10
27
|
# Asserts that the response body contains the given string or regexp
|
11
|
-
def
|
28
|
+
def assert_contains(*args)
|
12
29
|
matcher = contain(*args)
|
13
30
|
assert matcher.matches?(response.body), matcher.failure_message
|
14
31
|
end
|
15
32
|
|
16
33
|
# Asserts that the response body does not contain the given string or regexp
|
17
|
-
def
|
34
|
+
def assert_does_not_contain(*args)
|
18
35
|
matcher = contain(*args)
|
19
36
|
assert !matcher.matches?(response.body), matcher.negative_failure_message
|
20
37
|
end
|
21
38
|
|
22
|
-
def
|
23
|
-
HaveTag.new(*args, &block)
|
24
|
-
end
|
25
|
-
|
26
|
-
def assert_have_tag(html, *args, &block)
|
39
|
+
def assert_has_tag(html, *args, &block)
|
27
40
|
matcher = have_tag(*args, &block)
|
28
41
|
assert matcher.matches?(response.body), matcher.failure_message
|
29
42
|
end
|
30
43
|
|
31
|
-
def
|
44
|
+
def assert_no_tag(html, *args, &block)
|
32
45
|
matcher = have_tag(*args, &block)
|
33
46
|
assert !matcher.matches?(response.body), matcher.negative_failure_message
|
34
47
|
end
|
35
48
|
|
36
|
-
# Matches HTML content against an XPath
|
37
|
-
def have_xpath(xpath, options = {}, &block)
|
38
|
-
HaveTag.new(options.delete(:content), options.merge(:xpath => xpath), &block)
|
39
|
-
end
|
40
|
-
|
41
49
|
# Asserts that the response body matches the given XPath
|
42
|
-
def
|
50
|
+
def assert_has_xpath(html, *args, &block)
|
43
51
|
matcher = have_xpath(*args, &block)
|
44
52
|
assert matcher.matches?(response.body), matcher.failure_message
|
45
53
|
end
|
46
54
|
|
47
55
|
# Asserts that the response body does not match the given XPath
|
48
|
-
def
|
56
|
+
def assert_no_xpath(html, *args, &block)
|
49
57
|
matcher = have_xpath(*args, &block)
|
50
58
|
assert !matcher.matches?(response.body), matcher.negative_failure_message
|
51
59
|
end
|
52
60
|
|
53
|
-
# Matches HTML content against a CSS selector.
|
54
|
-
def have_css(css, options = {}, &block)
|
55
|
-
HaveTag.new(options.delete(:content), options.merge(:css => css), &block)
|
56
|
-
end
|
57
|
-
|
58
61
|
# Asserts that the response body matches the given CSS selector
|
59
|
-
def
|
62
|
+
def assert_has_css(html, *args, &block)
|
60
63
|
matcher = have_css(*args, &block)
|
61
64
|
assert matcher.matches?(response.body), matcher.failure_message
|
62
65
|
end
|
63
66
|
|
64
67
|
# Asserts that the response body does not match the given CSS selector
|
65
|
-
def
|
68
|
+
def assert_no_css(html, *args, &block)
|
66
69
|
matcher = have_css(*args, &block)
|
67
70
|
assert !matcher.matches?(response.body), matcher.negative_failure_message
|
68
71
|
end
|
72
|
+
|
73
|
+
def assert_css_class(css_classes, css_class)
|
74
|
+
matcher = HaveCssClass.new(css_class)
|
75
|
+
assert matcher.matches?(css_classes.body), matcher.failure_message
|
76
|
+
end
|
77
|
+
|
78
|
+
def assert_no_css_class(css_classes, css_class)
|
79
|
+
matcher = HaveCssClass.new(css_class)
|
80
|
+
assert matcher.matches?(css_classes.body), matcher.negative_failure_message
|
81
|
+
end
|
82
|
+
|
69
83
|
end
|
70
84
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Locator
|
2
|
+
module Matcher
|
3
|
+
class HaveCssClass
|
4
|
+
attr_reader :target, :css_class
|
5
|
+
|
6
|
+
def initialize(css_class)
|
7
|
+
@css_class = css_class
|
8
|
+
end
|
9
|
+
|
10
|
+
def matches?(target = nil)
|
11
|
+
@target = target
|
12
|
+
" #{target} ".include?(" #{css_class} ")
|
13
|
+
end
|
14
|
+
|
15
|
+
def failure_message
|
16
|
+
"expected #{target.inspect} to include the css class #{css_class.inspect}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def negative_failure_message
|
20
|
+
"expected #{target.inspect} not to include the css class #{css_class.inspect}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/locator/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 7
|
9
|
+
version: 0.0.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sven Fuchs
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-14 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -25,37 +25,33 @@ dependencies:
|
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
segments:
|
28
|
+
- 4
|
29
|
+
- 2
|
28
30
|
- 0
|
29
|
-
version:
|
31
|
+
version: 4.2.0
|
30
32
|
type: :runtime
|
31
33
|
version_requirements: *id001
|
32
|
-
description: Generic html element locators for integration testing
|
34
|
+
description: Generic html element locators for integration testing.
|
33
35
|
email: svenfuchs@artweb-design.de
|
34
36
|
executables: []
|
35
37
|
|
36
38
|
extensions: []
|
37
39
|
|
38
|
-
extra_rdoc_files:
|
39
|
-
|
40
|
-
- TODO
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
41
42
|
files:
|
42
|
-
- README.textile
|
43
|
-
- Rakefile
|
44
|
-
- TODO
|
45
43
|
- lib/core_ext/hash/except.rb
|
46
44
|
- lib/core_ext/hash/slice.rb
|
47
45
|
- lib/core_ext/string/underscore.rb
|
48
|
-
- lib/locator.rb
|
49
46
|
- lib/locator/boolean.rb
|
50
47
|
- lib/locator/decoding.rb
|
51
|
-
- lib/locator/dom.rb
|
52
|
-
- lib/locator/dom/htmlunit.rb
|
53
48
|
- lib/locator/dom/htmlunit/element.rb
|
54
49
|
- lib/locator/dom/htmlunit/page.rb
|
55
|
-
- lib/locator/dom/
|
50
|
+
- lib/locator/dom/htmlunit.rb
|
56
51
|
- lib/locator/dom/nokogiri/element.rb
|
57
52
|
- lib/locator/dom/nokogiri/page.rb
|
58
|
-
- lib/locator/
|
53
|
+
- lib/locator/dom/nokogiri.rb
|
54
|
+
- lib/locator/dom.rb
|
59
55
|
- lib/locator/element/area.rb
|
60
56
|
- lib/locator/element/button.rb
|
61
57
|
- lib/locator/element/check_box.rb
|
@@ -74,38 +70,24 @@ files:
|
|
74
70
|
- lib/locator/element/select.rb
|
75
71
|
- lib/locator/element/select_option.rb
|
76
72
|
- lib/locator/element/text_area.rb
|
77
|
-
- lib/locator/
|
73
|
+
- lib/locator/element.rb
|
74
|
+
- lib/locator/matcher/have_css_class.rb
|
78
75
|
- lib/locator/matcher/have_tag.rb
|
76
|
+
- lib/locator/matcher.rb
|
79
77
|
- lib/locator/result.rb
|
80
78
|
- lib/locator/version.rb
|
81
79
|
- lib/locator/xpath.rb
|
82
|
-
-
|
83
|
-
-
|
84
|
-
-
|
85
|
-
-
|
86
|
-
- test/locator/element/button_test.rb
|
87
|
-
- test/locator/element/field_test.rb
|
88
|
-
- test/locator/element/form_test.rb
|
89
|
-
- test/locator/element/hidden_field_test.rb
|
90
|
-
- test/locator/element/label_test.rb
|
91
|
-
- test/locator/element/link_test.rb
|
92
|
-
- test/locator/element/select_option_test.rb
|
93
|
-
- test/locator/element/select_test.rb
|
94
|
-
- test/locator/element/text_area_test.rb
|
95
|
-
- test/locator/element_test.rb
|
96
|
-
- test/locator/matcher/have_content_test.rb
|
97
|
-
- test/locator/matcher/have_tag_test.rb
|
98
|
-
- test/locator/xpath_test.rb
|
99
|
-
- test/locator_test.rb
|
100
|
-
- test/test_helper.rb
|
101
|
-
- test/webrat.rb
|
80
|
+
- lib/locator.rb
|
81
|
+
- Rakefile
|
82
|
+
- README.textile
|
83
|
+
- TODO
|
102
84
|
has_rdoc: true
|
103
85
|
homepage: http://github.com/svenfuchs/locator
|
104
86
|
licenses: []
|
105
87
|
|
106
88
|
post_install_message:
|
107
|
-
rdoc_options:
|
108
|
-
|
89
|
+
rdoc_options: []
|
90
|
+
|
109
91
|
require_paths:
|
110
92
|
- lib
|
111
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -120,33 +102,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
102
|
- - ">="
|
121
103
|
- !ruby/object:Gem::Version
|
122
104
|
segments:
|
123
|
-
-
|
124
|
-
|
105
|
+
- 1
|
106
|
+
- 3
|
107
|
+
- 6
|
108
|
+
version: 1.3.6
|
125
109
|
requirements: []
|
126
110
|
|
127
|
-
rubyforge_project:
|
111
|
+
rubyforge_project: "[none]"
|
128
112
|
rubygems_version: 1.3.6
|
129
113
|
signing_key:
|
130
114
|
specification_version: 3
|
131
115
|
summary: Generic html element locators for integration testing
|
132
|
-
test_files:
|
133
|
-
|
134
|
-
- test/locator/boolean_test.rb
|
135
|
-
- test/locator/dom/htmlunit_test.rb
|
136
|
-
- test/locator/dom/nokogiri_test.rb
|
137
|
-
- test/locator/element/button_test.rb
|
138
|
-
- test/locator/element/field_test.rb
|
139
|
-
- test/locator/element/form_test.rb
|
140
|
-
- test/locator/element/hidden_field_test.rb
|
141
|
-
- test/locator/element/label_test.rb
|
142
|
-
- test/locator/element/link_test.rb
|
143
|
-
- test/locator/element/select_option_test.rb
|
144
|
-
- test/locator/element/select_test.rb
|
145
|
-
- test/locator/element/text_area_test.rb
|
146
|
-
- test/locator/element_test.rb
|
147
|
-
- test/locator/matcher/have_content_test.rb
|
148
|
-
- test/locator/matcher/have_tag_test.rb
|
149
|
-
- test/locator/xpath_test.rb
|
150
|
-
- test/locator_test.rb
|
151
|
-
- test/test_helper.rb
|
152
|
-
- test/webrat.rb
|
116
|
+
test_files: []
|
117
|
+
|
data/test/all.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'locator/xpath'
|
3
|
-
|
4
|
-
class XpathBooleanTest < Test::Unit::TestCase
|
5
|
-
Or, And = Locator::Boolean::Or, Locator::Boolean::And
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Or.operator, And.operator = ' | ', ' & '
|
9
|
-
end
|
10
|
-
|
11
|
-
test "a | b => a | b" do
|
12
|
-
path = Or.new('a', 'b').to_s
|
13
|
-
assert_equal "a | b", path
|
14
|
-
end
|
15
|
-
|
16
|
-
test "a & b => a & b" do
|
17
|
-
path = And.new('a', 'b').to_s
|
18
|
-
assert_equal "a & b", path
|
19
|
-
end
|
20
|
-
|
21
|
-
test "(a & b) | c => a & b | c" do
|
22
|
-
path = And.new('a', 'b').or('c').to_s
|
23
|
-
assert_equal "a & b | c", path
|
24
|
-
end
|
25
|
-
|
26
|
-
test "(a | b) & c => a & c | b & c" do
|
27
|
-
path = Or.new('a', 'b').and('c').to_s
|
28
|
-
assert_equal "a & c | b & c", path
|
29
|
-
end
|
30
|
-
|
31
|
-
test "(a & b | c) & d => a & b & d | c & d" do
|
32
|
-
path = And.new('a', 'b').or('c').and('d').to_s
|
33
|
-
assert_equal "a & b & d | c & d", path
|
34
|
-
end
|
35
|
-
|
36
|
-
test "(a & b | c) & (d | e) => a & b & d | a & b & e | c & d | c & e" do
|
37
|
-
path = And.new('a', 'b').or('c').and(Or.new('d', 'e')).to_s
|
38
|
-
assert_equal "a & b & d | a & b & e | c & d | c & e", path
|
39
|
-
end
|
40
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
$: << '~/Development/projects/steam/lib'
|
4
|
-
begin
|
5
|
-
require 'steam'
|
6
|
-
include Steam
|
7
|
-
|
8
|
-
Java.load(Dir["#{Steam.config[:html_unit][:java_path]}/*.jar"].join(':'))
|
9
|
-
Java.import 'com.gargoylesoftware.htmlunit.WebClient'
|
10
|
-
Java.import 'com.gargoylesoftware.htmlunit.BrowserVersion'
|
11
|
-
|
12
|
-
class HtmlunitElementTest < Test::Unit::TestCase
|
13
|
-
include Locator, Java::Com::Gargoylesoftware::Htmlunit
|
14
|
-
|
15
|
-
def setup
|
16
|
-
connection = Connection::Mock.new
|
17
|
-
client = WebClient.new(BrowserVersion.FIREFOX_3)
|
18
|
-
client.setWebConnection(Rjb::bind(Browser::HtmlUnit::Connection.new(connection), 'com.gargoylesoftware.htmlunit.WebConnection'))
|
19
|
-
|
20
|
-
connection.mock(:get, 'http://localhost:3000/', '<a href="#" class="foo">the link</a><div id="bar"></div>')
|
21
|
-
@dom = Dom::Htmlunit::Page.new(client.getPage('http://localhost:3000/'))
|
22
|
-
end
|
23
|
-
|
24
|
-
test "Element takes a Htmlunit::Page adapter" do
|
25
|
-
element = Element::Link.new.locate(@dom, 'the link', :class => 'foo')
|
26
|
-
assert element.name
|
27
|
-
end
|
28
|
-
|
29
|
-
test "responds to name" do
|
30
|
-
element = Element::Link.new.locate(@dom, 'the link')
|
31
|
-
assert_equal 'a', element.name
|
32
|
-
end
|
33
|
-
|
34
|
-
test "responds to xpath" do
|
35
|
-
element = Element::Link.new.locate(@dom, 'the link')
|
36
|
-
assert_equal '/html/body/a', element.xpath
|
37
|
-
end
|
38
|
-
|
39
|
-
test "responds to to_s" do
|
40
|
-
element = Element::Link.new.locate(@dom, 'the link')
|
41
|
-
assert_equal "<a href=\"#\" class=\"foo\">\n the link\n</a>\n", element.to_s
|
42
|
-
end
|
43
|
-
|
44
|
-
test "responds to content" do
|
45
|
-
element = Element::Link.new.locate(@dom, 'the link')
|
46
|
-
assert_equal "the link", element.content
|
47
|
-
end
|
48
|
-
|
49
|
-
test "responds to attribute" do
|
50
|
-
element = Element::Link.new.locate(@dom, 'the link')
|
51
|
-
assert_equal 'foo', element.attribute('class')
|
52
|
-
end
|
53
|
-
|
54
|
-
test "responds to element_by_id" do
|
55
|
-
element = Element.new(:html).locate(@dom)
|
56
|
-
assert_equal 'bar', element.element_by_id('bar').attribute('id')
|
57
|
-
end
|
58
|
-
|
59
|
-
test "responds to element_by_xpath" do
|
60
|
-
element = Element.new(:html).locate(@dom)
|
61
|
-
assert_equal 'bar', element.element_by_xpath('//html/body/div[@id="bar"]').attribute('id')
|
62
|
-
end
|
63
|
-
|
64
|
-
test "responds to elements_by_xpath" do
|
65
|
-
element = Element::Link.new.locate(@dom, 'the link')
|
66
|
-
assert_equal 'foo', element.attribute('class')
|
67
|
-
end
|
68
|
-
|
69
|
-
test "responds to ancestors" do
|
70
|
-
element = Element.new(:a).locate(@dom)
|
71
|
-
assert_equal %w(html body), element.ancestors.map { |e| e.name }
|
72
|
-
end
|
73
|
-
|
74
|
-
test "responds to ancestor_of?" do
|
75
|
-
element = Element.new(:a).locate(@dom)
|
76
|
-
assert_equal %w(html body), element.ancestors.map { |e| e.name }
|
77
|
-
end
|
78
|
-
end
|
79
|
-
rescue LoadError
|
80
|
-
puts "skipping HtmlUnit tests because Steam is not available"
|
81
|
-
end
|