celerity 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +621 -0
- data/README.txt +58 -0
- data/Rakefile +4 -0
- data/lib/celerity.rb +47 -0
- data/lib/celerity/clickable_element.rb +11 -0
- data/lib/celerity/collections.rb +99 -0
- data/lib/celerity/container.rb +369 -0
- data/lib/celerity/disabled_element.rb +20 -0
- data/lib/celerity/element.rb +114 -0
- data/lib/celerity/element_collections.rb +67 -0
- data/lib/celerity/elements/button.rb +13 -0
- data/lib/celerity/elements/file_field.rb +12 -0
- data/lib/celerity/elements/form.rb +15 -0
- data/lib/celerity/elements/frame.rb +44 -0
- data/lib/celerity/elements/image.rb +70 -0
- data/lib/celerity/elements/label.rb +10 -0
- data/lib/celerity/elements/link.rb +13 -0
- data/lib/celerity/elements/radio_check.rb +59 -0
- data/lib/celerity/elements/select_list.rb +84 -0
- data/lib/celerity/elements/table.rb +94 -0
- data/lib/celerity/elements/table_body.rb +38 -0
- data/lib/celerity/elements/table_cell.rb +30 -0
- data/lib/celerity/elements/table_row.rb +34 -0
- data/lib/celerity/elements/text_field.rb +80 -0
- data/lib/celerity/exception.rb +48 -0
- data/lib/celerity/htmlunit/commons-codec-1.3.jar +0 -0
- data/lib/celerity/htmlunit/commons-collections-3.2.jar +0 -0
- data/lib/celerity/htmlunit/commons-httpclient-3.1.jar +0 -0
- data/lib/celerity/htmlunit/commons-io-1.4.jar +0 -0
- data/lib/celerity/htmlunit/commons-lang-2.4.jar +0 -0
- data/lib/celerity/htmlunit/commons-logging-1.1.1.jar +0 -0
- data/lib/celerity/htmlunit/cssparser-0.9.5.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-2.2-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/js-1.7R1.jar +0 -0
- data/lib/celerity/htmlunit/nekohtml-1.9.7.jar +0 -0
- data/lib/celerity/htmlunit/sac-1.3.jar +0 -0
- data/lib/celerity/htmlunit/xalan-2.7.0.jar +0 -0
- data/lib/celerity/htmlunit/xercesImpl-2.8.1.jar +0 -0
- data/lib/celerity/htmlunit/xml-apis-1.0.b2.jar +0 -0
- data/lib/celerity/ie.rb +126 -0
- data/lib/celerity/input_element.rb +29 -0
- data/lib/celerity/non_control_elements.rb +50 -0
- data/lib/celerity/version.rb +9 -0
- data/setup.rb +1585 -0
- data/spec/area_spec.rb +79 -0
- data/spec/areas_spec.rb +41 -0
- data/spec/button_spec.rb +171 -0
- data/spec/buttons_spec.rb +40 -0
- data/spec/checkbox_spec.rb +259 -0
- data/spec/checkboxes_spec.rb +39 -0
- data/spec/div_spec.rb +174 -0
- data/spec/divs_spec.rb +40 -0
- data/spec/element_spec.rb +29 -0
- data/spec/filefield_spec.rb +110 -0
- data/spec/filefields_spec.rb +41 -0
- data/spec/form_spec.rb +53 -0
- data/spec/forms_spec.rb +42 -0
- data/spec/frame_spec.rb +103 -0
- data/spec/hidden_spec.rb +105 -0
- data/spec/hiddens_spec.rb +40 -0
- data/spec/html/forms_with_input_elements.html +107 -0
- data/spec/html/frame_1.html +17 -0
- data/spec/html/frame_2.html +16 -0
- data/spec/html/frames.html +11 -0
- data/spec/html/iframes.html +12 -0
- data/spec/html/images.html +24 -0
- data/spec/html/images/1.gif +0 -0
- data/spec/html/images/2.gif +0 -0
- data/spec/html/images/3.gif +0 -0
- data/spec/html/images/button.jpg +0 -0
- data/spec/html/images/circle.jpg +0 -0
- data/spec/html/images/map.gif +0 -0
- data/spec/html/images/map2.gif +0 -0
- data/spec/html/images/minus.gif +0 -0
- data/spec/html/images/originaltriangle.jpg +0 -0
- data/spec/html/images/plus.gif +0 -0
- data/spec/html/images/square.jpg +0 -0
- data/spec/html/images/triangle.jpg +0 -0
- data/spec/html/non_control_elements.html +85 -0
- data/spec/html/tables.html +119 -0
- data/spec/ie_spec.rb +146 -0
- data/spec/image_spec.rb +210 -0
- data/spec/images_spec.rb +39 -0
- data/spec/label_spec.rb +65 -0
- data/spec/labels_spec.rb +41 -0
- data/spec/li_spec.rb +114 -0
- data/spec/link_spec.rb +147 -0
- data/spec/links_spec.rb +43 -0
- data/spec/lis_spec.rb +40 -0
- data/spec/map_spec.rb +83 -0
- data/spec/maps_spec.rb +41 -0
- data/spec/p_spec.rb +140 -0
- data/spec/pre_spec.rb +110 -0
- data/spec/pres_spec.rb +41 -0
- data/spec/ps_spec.rb +40 -0
- data/spec/radio_spec.rb +260 -0
- data/spec/radios_spec.rb +43 -0
- data/spec/select_list_spec.rb +286 -0
- data/spec/select_lists_spec.rb +47 -0
- data/spec/span_spec.rb +156 -0
- data/spec/spans_spec.rb +65 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +90 -0
- data/spec/table_bodies.rb +40 -0
- data/spec/table_bodies_spec.rb +42 -0
- data/spec/table_body_spec.rb +72 -0
- data/spec/table_cell_spec.rb +61 -0
- data/spec/table_cells_spec.rb +60 -0
- data/spec/table_row_spec.rb +59 -0
- data/spec/table_rows_spec.rb +57 -0
- data/spec/table_spec.rb +111 -0
- data/spec/tables_spec.rb +42 -0
- data/spec/text_field_spec.rb +234 -0
- data/spec/text_fields_spec.rb +45 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +23 -0
- data/tasks/simple_ci.rake +94 -0
- data/tasks/testserver.rake +17 -0
- metadata +174 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
module Celerity
|
2
|
+
#
|
3
|
+
# Input: Select
|
4
|
+
#
|
5
|
+
# This class is the way in which select boxes are manipulated
|
6
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#select_list method
|
7
|
+
class SelectList < InputElement
|
8
|
+
TAGS = [ Identifier.new('select') ]
|
9
|
+
|
10
|
+
def get_all_contents
|
11
|
+
assert_exists
|
12
|
+
@object.getOptions.map { |e| e.asText }
|
13
|
+
end
|
14
|
+
alias_method :getAllContents, :get_all_contents
|
15
|
+
|
16
|
+
def get_selected_items
|
17
|
+
assert_exists
|
18
|
+
@object.getSelectedOptions.map { |e| e.asText }
|
19
|
+
end
|
20
|
+
alias_method :getSelectedItems, :get_selected_items
|
21
|
+
|
22
|
+
def clear_selection
|
23
|
+
# assert_exists called by SelectList#type here
|
24
|
+
@object.getSelectedOptions.each { |e| e.setSelected(false) } unless type() == 'select-one'
|
25
|
+
end
|
26
|
+
alias_method :clearSelection, :clear_selection
|
27
|
+
|
28
|
+
def select(value)
|
29
|
+
assert_exists
|
30
|
+
raise NoValueFoundException, "unknown option with value #{value.inspect}" unless include?(value)
|
31
|
+
@object.getOptions.select { |e| matches?(e.asText, value) }.each do |option|
|
32
|
+
@container.update_page(option.click)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
alias_method :select_value, :select
|
36
|
+
alias_method :set, :select
|
37
|
+
|
38
|
+
def include?(value)
|
39
|
+
assert_exists
|
40
|
+
!!@object.getOptions.find { |e| matches?(e.asText, value) }
|
41
|
+
end
|
42
|
+
alias_method :includes?, :include?
|
43
|
+
|
44
|
+
def selected?(value)
|
45
|
+
assert_exists
|
46
|
+
# This should probably raise NoValueFoundException as well?
|
47
|
+
raise UnknownObjectException, "unknown option with value #{value.inspect}" unless include?(value)
|
48
|
+
!!@object.getOptions.find { |e| matches?(e.asText, value) && e.isSelected }
|
49
|
+
end
|
50
|
+
|
51
|
+
def type
|
52
|
+
assert_exists
|
53
|
+
'select-' + (@object.isAttributeDefined('multiple') ? 'multiple' : 'one')
|
54
|
+
end
|
55
|
+
|
56
|
+
def value
|
57
|
+
assert_exists
|
58
|
+
if (optn = @object.getSelectedOptions.to_a.first)
|
59
|
+
optn.getValueAttribute
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def option(attribute, value)
|
64
|
+
assert_exists
|
65
|
+
Option.new(self, attribute, value)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Option < Element
|
70
|
+
TAGS = ['option']
|
71
|
+
ATTRIBUTES = BASE_ATTRIBUTES | [:selected, :disabled, :label, :value]
|
72
|
+
|
73
|
+
def select
|
74
|
+
assert_exists
|
75
|
+
# click?
|
76
|
+
@object.setSelected(true)
|
77
|
+
end
|
78
|
+
|
79
|
+
def selected?
|
80
|
+
assert_exists
|
81
|
+
@object.isSelected
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Celerity
|
2
|
+
|
3
|
+
class Table < Element
|
4
|
+
include Container
|
5
|
+
TAGS = ['table']
|
6
|
+
ATTRIBUTES = BASE_ATTRIBUTES | [:summary, :width, :border, :frame, :rules, :cellspacing, :cellpadding, :align, :bgcolor]
|
7
|
+
DEFAULT_HOW = :name
|
8
|
+
|
9
|
+
def locate
|
10
|
+
@object = @container.locate_tagged_element(self, @how, @what)
|
11
|
+
if @object # cant call the assert_exists here, as an exists? method call will fail
|
12
|
+
@rows = @object.getRows
|
13
|
+
@cells = []
|
14
|
+
@rows.each do |row|
|
15
|
+
row.getCells.each do |c|
|
16
|
+
@cells << c
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def rows
|
23
|
+
assert_exists
|
24
|
+
return TableRows.new(self, :object, @rows)
|
25
|
+
end
|
26
|
+
|
27
|
+
def cells
|
28
|
+
assert_exists
|
29
|
+
return TableCells.new(self, :object, @cells)
|
30
|
+
end
|
31
|
+
|
32
|
+
def each
|
33
|
+
assert_exists
|
34
|
+
0.upto(@object.getRowCount-1) { |index| yield TableRow.new(self, :object, @rows[index]) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def [](index)
|
38
|
+
assert_exists
|
39
|
+
return TableRow.new(self, :object, @rows[index-1])
|
40
|
+
end
|
41
|
+
|
42
|
+
def row_count
|
43
|
+
assert_exists
|
44
|
+
@object.getRowCount
|
45
|
+
end
|
46
|
+
|
47
|
+
def column_count(index = 1)
|
48
|
+
assert_exists
|
49
|
+
@object.getRow(index-1).getCells.length
|
50
|
+
end
|
51
|
+
|
52
|
+
# This method returns the table as a 2 dimensional array. Dont expect too much if there are nested tables, colspan etc.
|
53
|
+
# Raises an UnknownObjectException if the table doesn't exist.
|
54
|
+
# http://www.w3.org/TR/html4/struct/tables.html
|
55
|
+
def to_a
|
56
|
+
assert_exists
|
57
|
+
y = []
|
58
|
+
table_rows = @object.getRows
|
59
|
+
for table_row in table_rows
|
60
|
+
x = []
|
61
|
+
for td in table_row.getCells
|
62
|
+
x << td.asText
|
63
|
+
end
|
64
|
+
y << x
|
65
|
+
end
|
66
|
+
return y
|
67
|
+
end
|
68
|
+
|
69
|
+
def table_body(index = 1)
|
70
|
+
return @object.getBodies.get(index)
|
71
|
+
end
|
72
|
+
private :table_body
|
73
|
+
|
74
|
+
def body(how, what)
|
75
|
+
assert_exists
|
76
|
+
return TableBody.new(@container, how, what, self)
|
77
|
+
end
|
78
|
+
|
79
|
+
def bodies
|
80
|
+
assert_exists
|
81
|
+
return TableBodies.new(self)
|
82
|
+
end
|
83
|
+
|
84
|
+
def column_values(columnnumber)
|
85
|
+
return (1..row_count).collect { |index| self[index][columnnumber].text }
|
86
|
+
end
|
87
|
+
|
88
|
+
def row_values(rownumber)
|
89
|
+
return (1..column_count(rownumber)).collect { |index| self[rownumber][index].text }
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Celerity
|
2
|
+
|
3
|
+
class TableBody < Element
|
4
|
+
TAGS = ['tbody']
|
5
|
+
|
6
|
+
def locate
|
7
|
+
if @how == :object
|
8
|
+
@object = @what
|
9
|
+
else
|
10
|
+
@object = @container.locate_tagged_element(self, @how, @what)
|
11
|
+
end
|
12
|
+
if @object # cant call the assert_exists here, as an exists? method call will fail
|
13
|
+
@rows = @object.getRows
|
14
|
+
@cells = []
|
15
|
+
@rows.each do |row|
|
16
|
+
row.getCells.each do |c|
|
17
|
+
@cells << c
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](index)
|
24
|
+
assert_exists
|
25
|
+
return TableRow.new(self, :object, @rows[index-1])
|
26
|
+
end
|
27
|
+
|
28
|
+
def length
|
29
|
+
assert_exists
|
30
|
+
return @object.getRows.length
|
31
|
+
end
|
32
|
+
|
33
|
+
def each
|
34
|
+
0.upto(length-1) { |index| yield TableRow.new(self, :object, @rows[index]) }
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Celerity
|
2
|
+
|
3
|
+
class TableCell < Element
|
4
|
+
include Celerity::Exception
|
5
|
+
include Container
|
6
|
+
|
7
|
+
TAGS = ['td']
|
8
|
+
ATTRIBUTES = BASE_ATTRIBUTES | [:abbr, :axis, :headers, :scope, :rowspan, :colspan] | CELLHALIGN_ATTRIBUTES | CELLVALIGN_ATTRIBUTES
|
9
|
+
|
10
|
+
def locate
|
11
|
+
if @how == :object
|
12
|
+
@object = @what
|
13
|
+
else
|
14
|
+
@object = @container.locate_tagged_element(self, @how, @what)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def colspan
|
19
|
+
assert_exists
|
20
|
+
attribute_value = @object.getAttributeValue('colspan').to_i
|
21
|
+
if attribute_value > 0
|
22
|
+
attribute_value
|
23
|
+
else
|
24
|
+
1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
alias_method :to_s, :text
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Celerity
|
2
|
+
|
3
|
+
class TableRow < Element
|
4
|
+
TAGS = ['tr']
|
5
|
+
|
6
|
+
def locate
|
7
|
+
if @how == :object
|
8
|
+
@object = @what
|
9
|
+
else
|
10
|
+
@object = @container.locate_tagged_element(self, @how, @what)
|
11
|
+
end
|
12
|
+
if @object # cant call the assert_exists here, as an exists? method call will fail
|
13
|
+
@cells = @object.getCells
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def each
|
18
|
+
locate
|
19
|
+
0.upto(@cells.length-1) { |index| yield TableCell.new(self, :object, @cells[index]) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def [](index)
|
23
|
+
assert_exists
|
24
|
+
raise UnknownCellException, "Unable to locate a cell at index #{index}" if @cells.length < index
|
25
|
+
return TableCell.new(self, :object, @cells[index-1])
|
26
|
+
end
|
27
|
+
|
28
|
+
def column_count
|
29
|
+
locate
|
30
|
+
@cells.length
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Celerity
|
2
|
+
#
|
3
|
+
# Class representing text field elements
|
4
|
+
#
|
5
|
+
# This class is the main class for Text Fields
|
6
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#text_field method
|
7
|
+
class TextField < InputElement
|
8
|
+
TAGS = [ Identifier.new('textarea'),
|
9
|
+
Identifier.new('input', :type => %w(text password)) ]
|
10
|
+
|
11
|
+
def clear
|
12
|
+
assert_exists
|
13
|
+
case @object.getTagName
|
14
|
+
when 'textarea'
|
15
|
+
@object.setText('')
|
16
|
+
when 'input'
|
17
|
+
@object.setValueAttribute('')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def set(value)
|
22
|
+
assert_enabled
|
23
|
+
assert_not_readonly
|
24
|
+
clear
|
25
|
+
# not sure what else to do here
|
26
|
+
if @object.class == com.gargoylesoftware.htmlunit.html.HtmlPasswordInput
|
27
|
+
@object.setValueAttribute(value.to_s)
|
28
|
+
else
|
29
|
+
value.to_s.to_java_bytes.each do |char|
|
30
|
+
@container.update_page @object.type(char)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def value=(value)
|
36
|
+
assert_enabled
|
37
|
+
assert_not_readonly
|
38
|
+
clear
|
39
|
+
case @object.getTagName
|
40
|
+
when 'textarea'
|
41
|
+
@object.setText(value.to_s)
|
42
|
+
when 'input'
|
43
|
+
@object.setValueAttribute(value.to_s)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def append(value)
|
48
|
+
assert_enabled
|
49
|
+
assert_not_readonly
|
50
|
+
value.to_s.to_java_bytes.each { |char| @container.update_page @object.type(char) }
|
51
|
+
end
|
52
|
+
|
53
|
+
# This bascially just moves the text to the other text field using TextField#append
|
54
|
+
# Should check if the HtmlUnit API supports some kind of dragging.
|
55
|
+
def drag_contents_to(how, what)
|
56
|
+
assert_exists # assert_enabled?
|
57
|
+
val = self.value
|
58
|
+
self.value = ''
|
59
|
+
@container.text_field(how, what).append(val)
|
60
|
+
end
|
61
|
+
alias_method :dragContentsTo, :drag_contents_to
|
62
|
+
|
63
|
+
def get_contents
|
64
|
+
self.value
|
65
|
+
end
|
66
|
+
alias_method :getContents, :get_contents
|
67
|
+
|
68
|
+
def verify_contains(expected)
|
69
|
+
assert_exists
|
70
|
+
!!contains_text(expected)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# this class can be used to access hidden field objects
|
75
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#hidden method
|
76
|
+
class Hidden < TextField
|
77
|
+
TAGS = [ Identifier.new('input', :type => %w(hidden)) ]
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Celerity
|
2
|
+
module Exception
|
3
|
+
|
4
|
+
# Root class for all Celerity Exceptions
|
5
|
+
class CelerityException < RuntimeError
|
6
|
+
def initialize(message="")
|
7
|
+
super(message)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# This exception is thrown if an attempt is made to access an object that doesn't exist
|
12
|
+
class UnknownObjectException < CelerityException; end
|
13
|
+
|
14
|
+
# This exception is thrown if an attempt is made to access an object that is in a disabled state
|
15
|
+
class ObjectDisabledException < CelerityException; end
|
16
|
+
|
17
|
+
# This exception is thrown if an attempt is made to access a frame that cannot be found
|
18
|
+
class UnknownFrameException < CelerityException; end
|
19
|
+
|
20
|
+
# This exception is thrown if an attempt is made to access a form that cannot be found
|
21
|
+
class UnknownFormException < CelerityException; end
|
22
|
+
|
23
|
+
# This exception is thrown if an attempt is made to access an object that is in a read only state
|
24
|
+
class ObjectReadOnlyException < CelerityException; end
|
25
|
+
|
26
|
+
# This exception is thrown if an attempt is made to access an object when the specified value cannot be found
|
27
|
+
class NoValueFoundException < CelerityException; end
|
28
|
+
|
29
|
+
# This exception gets raised if part of finding an object is missing
|
30
|
+
class MissingWayOfFindingObjectException < CelerityException; end
|
31
|
+
|
32
|
+
# this exception is raised if an attempt is made to access a table cell that doesnt exist
|
33
|
+
class UnknownCellException < CelerityException; end
|
34
|
+
|
35
|
+
# This exception is thrown if an http error, such as a 404, 500 etc is encountered while navigating
|
36
|
+
class NavigationException < CelerityException; end
|
37
|
+
|
38
|
+
# This exception is raised if a timeout is exceeded
|
39
|
+
class TimeOutException < CelerityException
|
40
|
+
def initialize(duration, timeout)
|
41
|
+
@duration, @timeout = duration, timeout
|
42
|
+
super
|
43
|
+
end
|
44
|
+
attr_reader :duration, :timeout
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/celerity/ie.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
module Celerity
|
2
|
+
class IE
|
3
|
+
include Container
|
4
|
+
attr_accessor :page, :object
|
5
|
+
|
6
|
+
def self.start(uri)
|
7
|
+
browser = new
|
8
|
+
browser.goto(uri)
|
9
|
+
browser
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(opts = {})
|
13
|
+
browser = RUBY_PLATFORM =~ /java/ ? ::HtmlUnit::BrowserVersion::FIREFOX_2 : ::HtmlUnit::BrowserVersion.FIREFOX_2
|
14
|
+
@webclient = ::HtmlUnit::WebClient.new(browser)
|
15
|
+
@webclient.setThrowExceptionOnScriptError(false) unless $DEBUG || opts[:enable_javascript_exceptions]
|
16
|
+
@webclient.setCssEnabled(false) if opts[:disable_css]
|
17
|
+
@page_container = self
|
18
|
+
@error_checkers = []
|
19
|
+
end
|
20
|
+
|
21
|
+
def goto(uri)
|
22
|
+
uri = "http://#{uri}" unless uri =~ %r{^http://}
|
23
|
+
set_page @webclient.getPage(uri)
|
24
|
+
uri
|
25
|
+
end
|
26
|
+
|
27
|
+
def close
|
28
|
+
@page = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_page(value)
|
32
|
+
# Log.debug(value.pretty_inspect)
|
33
|
+
@page = value
|
34
|
+
@object = @page.getDocumentElement
|
35
|
+
run_error_checks
|
36
|
+
end
|
37
|
+
|
38
|
+
def url
|
39
|
+
assert_exists
|
40
|
+
@page.getWebResponse.getUrl.toString
|
41
|
+
end
|
42
|
+
|
43
|
+
def base_url
|
44
|
+
"http://" + URI.parse( url() ).host
|
45
|
+
end
|
46
|
+
|
47
|
+
def title
|
48
|
+
@page.getTitleText
|
49
|
+
end
|
50
|
+
|
51
|
+
def html
|
52
|
+
@page ? @page.getDocumentElement.asXml : ''
|
53
|
+
end
|
54
|
+
|
55
|
+
def text
|
56
|
+
# nicer way to do this?
|
57
|
+
assert_exists
|
58
|
+
@page.getFirstByXPath("//body").asText
|
59
|
+
end
|
60
|
+
|
61
|
+
def back
|
62
|
+
raise NotImplementedError
|
63
|
+
end
|
64
|
+
|
65
|
+
def refresh
|
66
|
+
raise NotImplementedError
|
67
|
+
end
|
68
|
+
|
69
|
+
def exist?
|
70
|
+
!!@page
|
71
|
+
end
|
72
|
+
alias_method :exists?, :exist?
|
73
|
+
|
74
|
+
# check that we have a @page object
|
75
|
+
# need to find a better way to handle this
|
76
|
+
def assert_exists
|
77
|
+
raise UnknownObjectException, "no page loaded" unless exist?
|
78
|
+
end
|
79
|
+
|
80
|
+
def contains_text(expected_text)
|
81
|
+
return "" unless exist?
|
82
|
+
case expected_text
|
83
|
+
when Regexp
|
84
|
+
text().match(expected_text)
|
85
|
+
when String
|
86
|
+
text().index(expected_text)
|
87
|
+
else
|
88
|
+
raise ArgumentError, "Argument #{expected_text.inspect} should be a String or Regexp."
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def run_error_checks
|
93
|
+
@error_checkers.each { |e| e.call(self) }
|
94
|
+
end
|
95
|
+
|
96
|
+
def add_checker(checker = nil, &block)
|
97
|
+
if block_given?
|
98
|
+
@error_checkers << block
|
99
|
+
elsif Proc === checker
|
100
|
+
@error_checkers << checker
|
101
|
+
else
|
102
|
+
raise ArgumentError, "argument must be a Proc or a block"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def disable_checker(checker)
|
107
|
+
@error_checkers.delete(checker)
|
108
|
+
end
|
109
|
+
|
110
|
+
# these are just for Watir compatability - should we keep them?
|
111
|
+
class << self
|
112
|
+
attr_accessor :speed, :attach_timeout, :visible
|
113
|
+
alias_method :start_window, :start
|
114
|
+
def reset_attach_timeout; @attach_timeout = 2.0; end
|
115
|
+
def each; end
|
116
|
+
def quit; end
|
117
|
+
def set_fast_speed; @speed = :fast; end
|
118
|
+
def set_slow_speed; @speed = :slow; end
|
119
|
+
end
|
120
|
+
|
121
|
+
attr_accessor :visible
|
122
|
+
def bring_to_front; true; end
|
123
|
+
def speed=(s); end
|
124
|
+
|
125
|
+
end # IE
|
126
|
+
end # Celerity
|