celerity 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/History.txt +36 -0
- data/Manifest.txt +82 -0
- data/README.rdoc +78 -0
- data/Rakefile +25 -10
- data/celerity.gemspec +40 -0
- data/lib/celerity.rb +36 -20
- data/lib/celerity/browser.rb +396 -189
- data/lib/celerity/clickable_element.rb +25 -5
- data/lib/celerity/collections.rb +2 -2
- data/lib/celerity/container.rb +74 -61
- data/lib/celerity/default_viewer.rb +8 -4
- data/lib/celerity/disabled_element.rb +5 -5
- data/lib/celerity/element.rb +57 -35
- data/lib/celerity/element_collection.rb +22 -21
- data/lib/celerity/element_locator.rb +25 -18
- data/lib/celerity/elements/button.rb +13 -11
- data/lib/celerity/elements/file_field.rb +8 -4
- data/lib/celerity/elements/form.rb +7 -5
- data/lib/celerity/elements/frame.rb +6 -4
- data/lib/celerity/elements/image.rb +4 -4
- data/lib/celerity/elements/label.rb +1 -1
- data/lib/celerity/elements/link.rb +5 -5
- data/lib/celerity/elements/meta.rb +2 -1
- data/lib/celerity/elements/non_control_elements.rb +3 -3
- data/lib/celerity/elements/option.rb +7 -7
- data/lib/celerity/elements/radio_check.rb +18 -18
- data/lib/celerity/elements/select_list.rb +55 -25
- data/lib/celerity/elements/table.rb +21 -18
- data/lib/celerity/elements/table_cell.rb +1 -1
- data/lib/celerity/elements/table_elements.rb +1 -1
- data/lib/celerity/elements/table_row.rb +5 -5
- data/lib/celerity/elements/text_field.rb +33 -28
- data/lib/celerity/exception.rb +11 -5
- data/lib/celerity/htmlunit.rb +24 -8
- data/lib/celerity/htmlunit/commons-codec-1.4.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-2.6.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-core-js-2.6.jar +0 -0
- data/lib/celerity/htmlunit/nekohtml-1.9.13.jar +0 -0
- data/lib/celerity/htmlunit/{xercesImpl-2.8.1.jar → xercesImpl-2.9.1.jar} +0 -0
- data/lib/celerity/ignoring_web_connection.rb +15 -0
- data/lib/celerity/input_element.rb +1 -1
- data/lib/celerity/listener.rb +23 -17
- data/lib/celerity/short_inspect.rb +20 -0
- data/lib/celerity/util.rb +5 -2
- data/lib/celerity/version.rb +3 -10
- data/lib/celerity/viewer_connection.rb +89 -0
- data/lib/celerity/watir_compatibility.rb +2 -5
- data/lib/celerity/xpath_support.rb +48 -0
- data/spec/browser_authentication_spec.rb +16 -0
- data/spec/browser_spec.rb +300 -0
- data/spec/clickable_element_spec.rb +39 -0
- data/spec/default_viewer_spec.rb +23 -0
- data/spec/element_spec.rb +51 -0
- data/spec/filefield_spec.rb +18 -0
- data/spec/htmlunit_spec.rb +56 -0
- data/spec/index_offset_spec.rb +24 -0
- data/spec/listener_spec.rb +142 -0
- data/spec/spec_helper.rb +8 -0
- data/tasks/benchmark.rake +4 -0
- data/tasks/deployment.rake +43 -0
- data/tasks/environment.rake +7 -0
- data/tasks/fix.rake +25 -0
- data/tasks/jar.rake +4 -6
- data/tasks/rspec.rake +43 -0
- data/tasks/simple_ci.rake +94 -0
- data/tasks/snapshot.rake +22 -0
- data/tasks/website.rake +17 -0
- data/tasks/yard.rake +9 -0
- metadata +59 -26
- data/README.txt +0 -69
- data/lib/celerity/extra/method_generator.rb +0 -170
- data/lib/celerity/htmlunit/commons-codec-1.3.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-2.5-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-core-js-2.5-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/nekohtml-1.9.12-20090308.130127-11.jar +0 -0
@@ -21,31 +21,33 @@ module Celerity
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
@object
|
24
26
|
end
|
25
|
-
|
27
|
+
|
26
28
|
#
|
27
29
|
# @return [Celerity::TableRows]
|
28
30
|
#
|
29
|
-
|
31
|
+
|
30
32
|
def rows
|
31
33
|
assert_exists
|
32
34
|
TableRows.new(self, :object, @rows)
|
33
35
|
end
|
34
|
-
|
36
|
+
|
35
37
|
#
|
36
38
|
# @return [Celerity::TableCells]
|
37
39
|
#
|
38
|
-
|
40
|
+
|
39
41
|
def cells
|
40
42
|
assert_exists
|
41
43
|
TableCells.new(self, :object, @cells)
|
42
44
|
end
|
43
|
-
|
45
|
+
|
44
46
|
#
|
45
47
|
# Iterates through each row in the table.
|
46
48
|
# @yieldparam [Celerity::TableRow] row A row.
|
47
49
|
#
|
48
|
-
|
50
|
+
|
49
51
|
def each
|
50
52
|
assert_exists
|
51
53
|
@rows.each { |row| yield TableRow.new(self, :object, row) }
|
@@ -61,15 +63,15 @@ module Celerity
|
|
61
63
|
# @raise [Celerity::Exception::UnknownRowException]
|
62
64
|
# @return [Celerity::TableRow]
|
63
65
|
#
|
64
|
-
|
66
|
+
|
65
67
|
def child_row(index)
|
66
68
|
assert_exists
|
67
69
|
|
68
|
-
if (index -
|
70
|
+
if (index - Celerity.index_offset) >= @rows.length
|
69
71
|
raise UnknownRowException, "Unable to locate a row at index #{index}"
|
70
72
|
end
|
71
73
|
|
72
|
-
TableRow.new(self, :object, @rows[index -
|
74
|
+
TableRow.new(self, :object, @rows[index - Celerity.index_offset])
|
73
75
|
end
|
74
76
|
alias_method :[], :child_row
|
75
77
|
|
@@ -82,43 +84,44 @@ module Celerity
|
|
82
84
|
# @raise [Celerity::Exception::UnknownCellException]
|
83
85
|
# @return [Celerity::TableCell]
|
84
86
|
#
|
85
|
-
|
87
|
+
|
86
88
|
def child_cell(index)
|
87
89
|
assert_exists
|
88
90
|
|
89
|
-
if (index -
|
91
|
+
if (index - Celerity.index_offset) >= @cells.length
|
90
92
|
raise UnknownCellException, "Unable to locate a cell at index #{index}"
|
91
93
|
end
|
92
|
-
|
94
|
+
|
95
|
+
TableCell.new(self, :object, @cells[index - Celerity.index_offset])
|
93
96
|
end
|
94
97
|
|
95
98
|
#
|
96
99
|
# The number of rows in the table
|
97
100
|
# @return [Fixnum]
|
98
101
|
#
|
99
|
-
|
102
|
+
|
100
103
|
def row_count
|
101
104
|
assert_exists
|
102
105
|
@object.getRowCount
|
103
106
|
end
|
104
|
-
|
107
|
+
|
105
108
|
#
|
106
109
|
# Returns the number of columns on the row at the given index. (1-indexed)
|
107
110
|
# Default is the number of columns on the first row
|
108
111
|
# @param [Fixnum] index An index, 1-indexed (optional).
|
109
112
|
# @return [Fixnum]
|
110
113
|
#
|
111
|
-
|
112
|
-
def column_count(index =
|
114
|
+
|
115
|
+
def column_count(index = Celerity.index_offset)
|
113
116
|
assert_exists
|
114
|
-
@object.getRow(index -
|
117
|
+
@object.getRow(index - Celerity.index_offset).getCells.length
|
115
118
|
end
|
116
119
|
|
117
120
|
#
|
118
121
|
# Returns the text of each cell in the the table as a two-dimensional array.
|
119
122
|
# @return [Array<Array<String>>]
|
120
123
|
#
|
121
|
-
|
124
|
+
|
122
125
|
def to_a
|
123
126
|
assert_exists
|
124
127
|
# @object.getRows.map do |table_row|
|
@@ -14,7 +14,7 @@ module Celerity
|
|
14
14
|
#
|
15
15
|
# Yields each TableCell in this row to the given block.
|
16
16
|
#
|
17
|
-
|
17
|
+
|
18
18
|
def each
|
19
19
|
assert_exists
|
20
20
|
@cells.each { |cell| yield TableCell.new(self, :object, cell) }
|
@@ -23,22 +23,22 @@ module Celerity
|
|
23
23
|
#
|
24
24
|
# Get the child cell at the given index
|
25
25
|
#
|
26
|
-
|
26
|
+
|
27
27
|
def child_cell(index)
|
28
28
|
assert_exists
|
29
29
|
|
30
|
-
if (index -
|
30
|
+
if (index - Celerity.index_offset) >= @cells.length
|
31
31
|
raise UnknownCellException, "Unable to locate a cell at index #{index}"
|
32
32
|
end
|
33
33
|
|
34
|
-
TableCell.new(self, :object, @cells[index -
|
34
|
+
TableCell.new(self, :object, @cells[index - Celerity.index_offset])
|
35
35
|
end
|
36
36
|
alias_method :[], :child_cell
|
37
37
|
|
38
38
|
#
|
39
39
|
# Number of cells in this row.
|
40
40
|
#
|
41
|
-
|
41
|
+
|
42
42
|
def column_count
|
43
43
|
assert_exists
|
44
44
|
@cells.length
|
@@ -1,44 +1,51 @@
|
|
1
1
|
module Celerity
|
2
|
-
|
2
|
+
|
3
3
|
#
|
4
4
|
# Class representing text field elements
|
5
5
|
#
|
6
6
|
# This class is the main class for Text Fields
|
7
7
|
# Normally a user would not need to create this object as it is returned by the Watir::Container#text_field method
|
8
8
|
#
|
9
|
-
|
9
|
+
|
10
10
|
class TextField < InputElement
|
11
11
|
NON_TEXT_TYPES = %w[file radio checkbox submit reset image button hidden]
|
12
12
|
TAGS = [ Identifier.new('textarea'),
|
13
13
|
Identifier.new('input', :type => ["text", "password", /^(?!(#{ Regexp.union(*NON_TEXT_TYPES) })$)/]) ]
|
14
14
|
DEFAULT_HOW = :name
|
15
|
-
|
15
|
+
|
16
|
+
def visible?
|
17
|
+
assert_exists
|
18
|
+
type == 'hidden' ? false : super
|
19
|
+
end
|
20
|
+
|
16
21
|
#
|
17
22
|
# Clear the text field.
|
18
23
|
#
|
19
|
-
|
24
|
+
|
20
25
|
def clear
|
21
26
|
assert_exists
|
22
27
|
insert_string ''
|
23
28
|
end
|
24
|
-
|
29
|
+
|
25
30
|
#
|
26
31
|
# Set the text field to the given value.
|
27
32
|
# This ensures execution of JavaScript events (onkeypress etc.), but is slower than +value=+
|
28
33
|
#
|
29
|
-
|
34
|
+
|
30
35
|
def set(value)
|
31
36
|
assert_enabled
|
32
37
|
assert_not_readonly
|
33
38
|
clear
|
34
39
|
type_string(value.to_s)
|
40
|
+
|
41
|
+
value
|
35
42
|
end
|
36
|
-
|
43
|
+
|
37
44
|
#
|
38
45
|
# This directly sets the text field to the given value, skipping exectuion of JavaScript events.
|
39
46
|
# Use +set+ if you want to run events on text fields.
|
40
47
|
#
|
41
|
-
|
48
|
+
|
42
49
|
def value=(value)
|
43
50
|
assert_enabled
|
44
51
|
assert_not_readonly
|
@@ -48,11 +55,11 @@ module Celerity
|
|
48
55
|
|
49
56
|
value
|
50
57
|
end
|
51
|
-
|
58
|
+
|
52
59
|
#
|
53
60
|
# Returns the text in the text field.
|
54
61
|
#
|
55
|
-
|
62
|
+
|
56
63
|
def value
|
57
64
|
assert_exists
|
58
65
|
case @object.getTagName
|
@@ -63,34 +70,30 @@ module Celerity
|
|
63
70
|
end
|
64
71
|
end
|
65
72
|
alias_method :get_contents, :value
|
66
|
-
|
73
|
+
|
67
74
|
#
|
68
75
|
# Append the given value to the text in the text field.
|
69
76
|
#
|
70
|
-
|
77
|
+
|
71
78
|
def append(value)
|
72
79
|
assert_enabled
|
73
80
|
assert_not_readonly
|
74
|
-
type_string
|
81
|
+
type_string value
|
75
82
|
end
|
76
83
|
|
77
|
-
|
84
|
+
|
78
85
|
def type
|
79
86
|
assert_exists
|
80
|
-
type = @object.
|
87
|
+
type = @object.getAttribute 'type'
|
81
88
|
|
82
|
-
|
83
|
-
type
|
84
|
-
else
|
85
|
-
'text'
|
86
|
-
end
|
89
|
+
NON_TEXT_TYPES.include?(type) ? type : 'text'
|
87
90
|
end
|
88
91
|
|
89
92
|
#
|
90
93
|
# This bascially just moves the text to the other text field using TextField#append
|
91
94
|
# TODO: check if HtmlUnit supports some kind of dragging.
|
92
95
|
#
|
93
|
-
|
96
|
+
|
94
97
|
def drag_contents_to(how, what)
|
95
98
|
assert_exists # assert_enabled?
|
96
99
|
val = self.value
|
@@ -101,7 +104,7 @@ module Celerity
|
|
101
104
|
#
|
102
105
|
# Check if the given text fields contains the given String or Regexp.
|
103
106
|
#
|
104
|
-
|
107
|
+
|
105
108
|
def contains_text(expected_text)
|
106
109
|
assert_exists
|
107
110
|
|
@@ -117,10 +120,11 @@ module Celerity
|
|
117
120
|
|
118
121
|
#
|
119
122
|
# A boolean version of TextField#contains_text
|
123
|
+
#
|
120
124
|
# @param [String, Regexp] expected_text The text to look for.
|
121
125
|
# @return [boolean]
|
122
126
|
#
|
123
|
-
|
127
|
+
|
124
128
|
def verify_contains(expected)
|
125
129
|
# assert_exists called by contains_text
|
126
130
|
!!contains_text(expected)
|
@@ -129,8 +133,8 @@ module Celerity
|
|
129
133
|
private
|
130
134
|
|
131
135
|
def type_string(value)
|
132
|
-
java.lang.String.new(value.to_java_bytes, @
|
133
|
-
@
|
136
|
+
java.lang.String.new(value.to_java_bytes, @browser.page.getPageEncoding).toCharArray.each do |char|
|
137
|
+
@object.type(char)
|
134
138
|
end
|
135
139
|
end
|
136
140
|
|
@@ -144,19 +148,20 @@ module Celerity
|
|
144
148
|
raise "unknown tag name #{@object.getTagName.inspect} for #{self.class}"
|
145
149
|
end
|
146
150
|
end
|
147
|
-
|
151
|
+
|
148
152
|
end # TextField
|
149
153
|
|
150
154
|
#
|
151
155
|
# This class can be used to access hidden field objects
|
152
156
|
# Normally a user would not need to create this object as it is returned by the Celerity::Container#hidden method
|
153
157
|
#
|
154
|
-
|
158
|
+
|
155
159
|
class Hidden < TextField
|
156
160
|
TAGS = [ Identifier.new('input', :type => %w[hidden]) ]
|
157
161
|
DEFAULT_HOW = :name
|
158
|
-
|
162
|
+
|
159
163
|
def visible?
|
164
|
+
assert_exists
|
160
165
|
false
|
161
166
|
end
|
162
167
|
end
|
data/lib/celerity/exception.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Celerity
|
2
2
|
module Exception
|
3
|
-
|
3
|
+
|
4
4
|
#
|
5
5
|
# Superclass for all Celerity exceptions.
|
6
6
|
#
|
@@ -12,7 +12,7 @@ module Celerity
|
|
12
12
|
#
|
13
13
|
|
14
14
|
class UnknownObjectException < CelerityException; end
|
15
|
-
|
15
|
+
|
16
16
|
#
|
17
17
|
# This exception is thrown if an attempt is made to access an object that is in a disabled state
|
18
18
|
#
|
@@ -54,7 +54,7 @@ module Celerity
|
|
54
54
|
#
|
55
55
|
|
56
56
|
class UnknownRowException < CelerityException; end
|
57
|
-
|
57
|
+
|
58
58
|
#
|
59
59
|
# This exception is raised if an attempt is made to access a table cell that doesn't exist
|
60
60
|
#
|
@@ -66,12 +66,18 @@ module Celerity
|
|
66
66
|
#
|
67
67
|
|
68
68
|
class NavigationException < CelerityException; end
|
69
|
-
|
69
|
+
|
70
70
|
#
|
71
71
|
# This exception is thrown if an unexpected content type is returned by the server.
|
72
72
|
#
|
73
73
|
|
74
74
|
class UnexpectedPageException < CelerityException; end
|
75
|
-
|
75
|
+
|
76
|
+
#
|
77
|
+
# This exception is thrown if an unexpected content type is returned by the server.
|
78
|
+
#
|
79
|
+
|
80
|
+
class CookieNotFoundError < CelerityException; end
|
81
|
+
|
76
82
|
end # Exception
|
77
83
|
end # Celerity
|
data/lib/celerity/htmlunit.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
module Celerity
|
2
2
|
Jars = Dir[File.dirname(__FILE__) + '/htmlunit/*.jar']
|
3
3
|
Jars.each { |jar| require(jar) }
|
4
|
-
|
4
|
+
|
5
5
|
include_class org.apache.commons.httpclient.Cookie
|
6
|
+
|
7
|
+
module JsxHelper
|
8
|
+
def method_missing(meth, *args, &blk)
|
9
|
+
m = ["jsxGet_#{meth}", "jsx_get_#{meth}"].find { |m| respond_to?(m) }
|
10
|
+
m ? __send__(m) : super
|
11
|
+
end
|
12
|
+
end
|
6
13
|
end
|
7
14
|
|
8
|
-
|
9
|
-
|
10
15
|
module HtmlUnit
|
11
16
|
include_package 'com.gargoylesoftware.htmlunit'
|
12
17
|
|
13
18
|
module Html
|
14
19
|
include_package 'com.gargoylesoftware.htmlunit.html'
|
15
20
|
end
|
16
|
-
|
21
|
+
|
17
22
|
module Util
|
18
23
|
include_package 'com.gargoylesoftware.htmlunit.util'
|
19
24
|
end
|
20
|
-
|
21
25
|
end
|
22
26
|
|
23
27
|
module Java::OrgW3cDom::NamedNodeMap
|
@@ -38,12 +42,24 @@ module Java::JavaLang::Iterable
|
|
38
42
|
yield it.next while it.hasNext
|
39
43
|
end
|
40
44
|
|
41
|
-
end
|
42
|
-
|
45
|
+
end unless Java::JavaLang::Iterable < Enumerable # depends on JRuby version
|
43
46
|
|
44
47
|
class Java::ComGargoylesoftwareHtmlunitHtml::HtmlPage
|
45
48
|
def inspect
|
46
|
-
'#<HtmlPage:0x%s(%s)>' % [self.hash.to_s(16), getWebResponse.
|
49
|
+
'#<HtmlPage:0x%s(%s)>' % [self.hash.to_s(16), getWebResponse.getRequestUrl.toString]
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
53
|
+
class Java::ComGargoylesoftwareHtmlunitHtml::HtmlElement
|
54
|
+
def inspect
|
55
|
+
'#<%s:0x%s>' % [self.class.name.split("::").last, self.hash.to_s(16)]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class Java::ComGargoylesoftwareHtmlunitJavascriptHostHtml::HTMLElement
|
60
|
+
include Celerity::JsxHelper
|
61
|
+
end
|
62
|
+
|
63
|
+
class Java::ComGargoylesoftwareHtmlunitJavascriptHostCss::CSSStyleDeclaration
|
64
|
+
include Celerity::JsxHelper
|
65
|
+
end
|
Binary file
|