celerity 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +33 -0
- data/README.txt +19 -9
- data/Rakefile +9 -3
- data/lib/celerity.rb +39 -39
- data/lib/celerity/browser.rb +538 -153
- data/lib/celerity/clickable_element.rb +48 -7
- data/lib/celerity/collections.rb +155 -131
- data/lib/celerity/container.rb +766 -385
- data/lib/celerity/default_viewer.rb +10 -0
- data/lib/celerity/disabled_element.rb +19 -2
- data/lib/celerity/element.rb +152 -83
- data/lib/celerity/element_collection.rb +106 -0
- data/lib/celerity/element_locator.rb +89 -66
- data/lib/celerity/elements/button.rb +23 -13
- data/lib/celerity/elements/file_field.rb +17 -5
- data/lib/celerity/elements/form.rb +21 -16
- data/lib/celerity/elements/frame.rb +75 -53
- data/lib/celerity/elements/image.rb +76 -63
- data/lib/celerity/elements/label.rb +4 -2
- data/lib/celerity/elements/link.rb +30 -18
- data/lib/celerity/elements/meta.rb +6 -0
- data/lib/celerity/{non_control_elements.rb → elements/non_control_elements.rb} +106 -76
- data/lib/celerity/elements/option.rb +16 -2
- data/lib/celerity/elements/radio_check.rb +55 -20
- data/lib/celerity/elements/select_list.rb +65 -29
- data/lib/celerity/elements/table.rb +141 -94
- data/lib/celerity/elements/table_cell.rb +13 -6
- data/lib/celerity/elements/{table_body.rb → table_elements.rb} +20 -8
- data/lib/celerity/elements/table_row.rb +23 -7
- data/lib/celerity/elements/text_field.rb +89 -33
- data/lib/celerity/exception.rb +77 -41
- data/lib/celerity/extra/method_generator.rb +42 -24
- data/lib/celerity/htmlunit.rb +49 -0
- data/lib/celerity/htmlunit/commons-collections-3.2.1.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
- data/lib/celerity/htmlunit/serializer-2.7.1.jar +0 -0
- data/lib/celerity/htmlunit/xalan-2.7.1.jar +0 -0
- data/lib/celerity/htmlunit/xml-apis-1.3.04.jar +0 -0
- data/lib/celerity/identifier.rb +3 -2
- data/lib/celerity/input_element.rb +5 -5
- data/lib/celerity/listener.rb +135 -0
- data/lib/celerity/resources/no_viewer.png +0 -0
- data/lib/celerity/util.rb +88 -0
- data/lib/celerity/version.rb +4 -3
- data/lib/celerity/watir_compatibility.rb +35 -25
- data/tasks/jar.rake +57 -0
- metadata +35 -142
- data.tar.gz.sig +0 -0
- data/Manifest.txt +0 -150
- data/lib/celerity/element_collections.rb +0 -54
- data/lib/celerity/element_map.rb +0 -51
- data/lib/celerity/elements/table_footer.rb +0 -30
- data/lib/celerity/elements/table_header.rb +0 -30
- data/lib/celerity/htmlunit/commons-collections-3.2.jar +0 -0
- data/lib/celerity/htmlunit/download.sh +0 -23
- data/lib/celerity/htmlunit/htmlunit-2.2.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-core-js-2.2.jar +0 -0
- data/lib/celerity/htmlunit/nekohtml-1.9.8.jar +0 -0
- data/lib/celerity/htmlunit/xalan-2.7.0.jar +0 -0
- data/lib/celerity/htmlunit/xml-apis-1.0.b2.jar +0 -0
- data/spec/area_spec.rb +0 -97
- data/spec/areas_spec.rb +0 -40
- data/spec/browser_spec.rb +0 -266
- data/spec/button_spec.rb +0 -227
- data/spec/buttons_spec.rb +0 -39
- data/spec/checkbox_spec.rb +0 -302
- data/spec/checkboxes_spec.rb +0 -38
- data/spec/div_spec.rb +0 -207
- data/spec/divs_spec.rb +0 -39
- data/spec/element_spec.rb +0 -79
- data/spec/filefield_spec.rb +0 -123
- data/spec/filefields_spec.rb +0 -40
- data/spec/form_spec.rb +0 -59
- data/spec/forms_spec.rb +0 -41
- data/spec/frame_spec.rb +0 -121
- data/spec/frames_spec.rb +0 -71
- data/spec/hidden_spec.rb +0 -127
- data/spec/hiddens_spec.rb +0 -39
- data/spec/hn_spec.rb +0 -104
- data/spec/hns_spec.rb +0 -45
- data/spec/html/2000_spans.html +0 -2009
- data/spec/html/bug_duplicate_attributes.html +0 -14
- data/spec/html/bug_javascript_001.html +0 -11
- data/spec/html/form_js_bug.html +0 -11
- data/spec/html/forms_with_input_elements.html +0 -114
- data/spec/html/frame_1.html +0 -17
- data/spec/html/frame_2.html +0 -16
- data/spec/html/frames.html +0 -11
- data/spec/html/iframes.html +0 -12
- data/spec/html/images.html +0 -27
- 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/invalid_js.html +0 -11
- data/spec/html/latin1_text.html +0 -17
- data/spec/html/non_control_elements.html +0 -115
- data/spec/html/simple_ajax.html +0 -22
- data/spec/html/tables.html +0 -119
- data/spec/html/utf8_text.html +0 -15
- data/spec/htmlunit_spec.rb +0 -26
- data/spec/image_spec.rb +0 -220
- data/spec/images_spec.rb +0 -39
- data/spec/label_spec.rb +0 -79
- data/spec/labels_spec.rb +0 -40
- data/spec/li_spec.rb +0 -139
- data/spec/link_spec.rb +0 -189
- data/spec/links_spec.rb +0 -43
- data/spec/lis_spec.rb +0 -40
- data/spec/map_spec.rb +0 -102
- data/spec/maps_spec.rb +0 -40
- data/spec/meta_spec.rb +0 -8
- data/spec/ol_spec.rb +0 -87
- data/spec/ols_spec.rb +0 -40
- data/spec/option_spec.rb +0 -154
- data/spec/p_spec.rb +0 -171
- data/spec/pre_spec.rb +0 -135
- data/spec/pres_spec.rb +0 -40
- data/spec/ps_spec.rb +0 -40
- data/spec/radio_spec.rb +0 -299
- data/spec/radios_spec.rb +0 -42
- data/spec/select_list_spec.rb +0 -299
- data/spec/select_lists_spec.rb +0 -47
- data/spec/span_spec.rb +0 -184
- data/spec/spans_spec.rb +0 -64
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -55
- data/spec/table_bodies_spec.rb +0 -57
- data/spec/table_body_spec.rb +0 -111
- data/spec/table_cell_spec.rb +0 -74
- data/spec/table_cells_spec.rb +0 -59
- data/spec/table_footer_spec.rb +0 -101
- data/spec/table_footers_spec.rb +0 -55
- data/spec/table_header_spec.rb +0 -101
- data/spec/table_headers_spec.rb +0 -55
- data/spec/table_row_spec.rb +0 -104
- data/spec/table_rows_spec.rb +0 -58
- data/spec/table_spec.rb +0 -160
- data/spec/tables_spec.rb +0 -42
- data/spec/text_field_spec.rb +0 -323
- data/spec/text_fields_spec.rb +0 -44
- data/spec/ul_spec.rb +0 -88
- data/spec/uls_spec.rb +0 -40
- data/spec/watir_compatibility_spec.rb +0 -260
- data/support/spec_server.rb +0 -73
- data/tasks/rspec.rake +0 -30
- data/tasks/specserver.rake +0 -21
- metadata.gz.sig +0 -0
@@ -1,33 +1,46 @@
|
|
1
1
|
module Celerity
|
2
|
-
|
2
|
+
|
3
|
+
#
|
3
4
|
# Used internally to locate elements on the page.
|
5
|
+
#
|
6
|
+
|
4
7
|
class ElementLocator
|
5
8
|
include Celerity::Exception
|
6
9
|
attr_accessor :idents
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(
|
10
|
-
|
10
|
+
|
11
|
+
|
12
|
+
def initialize(container, element_class)
|
13
|
+
container.assert_exists
|
14
|
+
|
15
|
+
@container = container
|
16
|
+
@object = container.object
|
11
17
|
@element_class = element_class
|
12
|
-
@attributes
|
13
|
-
@idents
|
14
|
-
@tags
|
18
|
+
@attributes = @element_class::ATTRIBUTES # could check for 'strict' here?
|
19
|
+
@idents = @element_class::TAGS
|
20
|
+
@tags = @idents.map { |e| e.tag.downcase }
|
15
21
|
end
|
16
22
|
|
17
|
-
def find_by_conditions(conditions)
|
23
|
+
def find_by_conditions(conditions) # TODO: refactor without performance hit
|
24
|
+
return nil unless @object # probably means we're on a TextPage (content-type is "text/plain")
|
25
|
+
|
18
26
|
@condition_idents = []
|
19
27
|
attributes = Hash.new { |h, k| h[k] = [] }
|
20
28
|
index = 0 # by default, return the first matching element
|
21
|
-
text = nil
|
22
|
-
|
29
|
+
text = nil
|
30
|
+
|
23
31
|
conditions.each do |how, what|
|
24
32
|
case how
|
25
33
|
when :object
|
34
|
+
unless what.is_a?(HtmlUnit::Html::HtmlElement) || what.nil?
|
35
|
+
raise ArgumentError, "expected an HtmlUnit::Html::HtmlElement subclass, got #{what.inspect}:#{what.class}"
|
36
|
+
end
|
26
37
|
return what
|
27
38
|
when :id
|
28
39
|
return find_by_id(what)
|
29
40
|
when :xpath
|
30
41
|
return find_by_xpath(what)
|
42
|
+
when :label
|
43
|
+
return find_by_label(what) unless @attributes.include?(:label)
|
31
44
|
when :class_name
|
32
45
|
how = :class
|
33
46
|
when :url
|
@@ -35,30 +48,25 @@ module Celerity
|
|
35
48
|
when :caption
|
36
49
|
how = :text
|
37
50
|
end
|
38
|
-
|
39
|
-
if @attributes.include?(how)
|
40
|
-
attributes[how] << what
|
51
|
+
|
52
|
+
if @attributes.include?(how = how.to_sym)
|
53
|
+
attributes[how] << what
|
41
54
|
elsif how == :index
|
42
|
-
index = what.to_i -
|
55
|
+
index = what.to_i - INDEX_OFFSET
|
43
56
|
elsif how == :text
|
44
57
|
text = what
|
45
58
|
else
|
46
59
|
raise MissingWayOfFindingObjectException, "No how #{how.inspect}"
|
47
60
|
end
|
48
|
-
|
49
61
|
end
|
50
62
|
|
51
63
|
@idents.each do |ident|
|
52
|
-
merged = attributes.merge(ident.attributes)
|
53
|
-
v1 | v2
|
54
|
-
end
|
55
|
-
|
64
|
+
merged = attributes.merge(ident.attributes) { |key, v1, v2| v1 | v2 }
|
56
65
|
id = Identifier.new(ident.tag, merged)
|
57
|
-
# «original» identifier takes precedence for :text
|
58
|
-
id.text = ident.text || text
|
66
|
+
id.text = ident.text || text # «original» identifier takes precedence for :text
|
59
67
|
@condition_idents << id
|
60
68
|
end
|
61
|
-
|
69
|
+
|
62
70
|
if index == 0
|
63
71
|
element_by_idents(@condition_idents)
|
64
72
|
else
|
@@ -68,80 +76,95 @@ module Celerity
|
|
68
76
|
rescue HtmlUnit::ElementNotFoundException
|
69
77
|
nil # for rcov
|
70
78
|
end
|
71
|
-
|
79
|
+
|
72
80
|
def find_by_id(what)
|
73
81
|
case what
|
74
82
|
when Regexp
|
75
|
-
elements_by_tag_names.find { |elem| elem.
|
83
|
+
elements_by_tag_names.find { |elem| elem.getId =~ what }
|
76
84
|
when String
|
77
85
|
obj = @object.getHtmlElementById(what)
|
78
|
-
if @tags.include?(obj.getTagName)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
elements_by_tag_names.find { |elem| elem.getIdAttribute == what }
|
83
|
-
end
|
86
|
+
return obj if @tags.include?(obj.getTagName)
|
87
|
+
|
88
|
+
$stderr.puts "warning: multiple elements with identical id? (#{what.inspect})" if $VERBOSE
|
89
|
+
elements_by_tag_names.find { |elem| elem.getId == what }
|
84
90
|
else
|
85
|
-
raise
|
91
|
+
raise TypeError, "expected String or Regexp, got #{what.inspect}:#{what.class}"
|
86
92
|
end
|
87
93
|
end
|
88
|
-
|
94
|
+
|
89
95
|
def find_by_xpath(what)
|
90
|
-
what = ".#{what}" if what[0] ==
|
96
|
+
what = ".#{what}" if what[0].chr == "/"
|
91
97
|
@object.getByXPath(what).to_a.first
|
92
98
|
end
|
93
99
|
|
100
|
+
def find_by_label(what)
|
101
|
+
obj = elements_by_tag_names(%w[label]).find { |e| matches?(e.asText, what) }
|
102
|
+
|
103
|
+
return nil unless obj && (ref = obj.getReferencedElement)
|
104
|
+
return ref if @tags.include?(ref.getTagName)
|
105
|
+
|
106
|
+
find_by_id obj.getForAttribute
|
107
|
+
end
|
108
|
+
|
94
109
|
def elements_by_idents(idents = nil)
|
95
110
|
get_by_idents(:select, idents || @idents)
|
96
111
|
end
|
97
|
-
|
112
|
+
|
98
113
|
def element_by_idents(idents = nil)
|
99
114
|
get_by_idents(:find, idents || @idents)
|
100
115
|
end
|
101
116
|
|
102
|
-
private
|
117
|
+
private
|
103
118
|
|
104
119
|
def get_by_idents(meth, idents)
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
attr_result = ident.attributes.all? do |key, value|
|
111
|
-
value.any? { |val| matches?(e.getAttributeValue(key.to_s), val) }
|
112
|
-
end
|
113
|
-
|
114
|
-
if ident.text
|
115
|
-
attr_result && matches?(e.asText, ident.text)
|
116
|
-
else
|
117
|
-
attr_result
|
118
|
-
end
|
119
|
-
end
|
120
|
+
with_nullpointer_retry do
|
121
|
+
@object.getAllHtmlChildElements.send(meth) do |e|
|
122
|
+
next unless @tags.include?(e.getTagName)
|
123
|
+
idents.any? { |id| element_matches_ident?(e, id) }
|
120
124
|
end
|
121
125
|
end
|
122
126
|
end
|
123
127
|
|
124
|
-
def
|
125
|
-
|
126
|
-
end
|
128
|
+
def element_matches_ident?(element, ident)
|
129
|
+
return false unless ident.tag == element.getTagName
|
127
130
|
|
128
|
-
|
129
|
-
|
130
|
-
# HtmlUnit's getHtmlElementsByTagNames won't get elements in the correct order, making :index fail
|
131
|
-
@object.getAllHtmlChildElements.iterator.to_a.select do |elem|
|
132
|
-
@tags.include?(elem.getTagName)
|
131
|
+
attr_result = ident.attributes.all? do |key, values|
|
132
|
+
values.any? { |val| matches?(element.getAttributeValue(key.to_s), val) }
|
133
133
|
end
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
if tries < 2
|
138
|
-
tries += 1
|
139
|
-
retry
|
134
|
+
|
135
|
+
if ident.text
|
136
|
+
attr_result && matches?(element.asText.strip, ident.text)
|
140
137
|
else
|
141
|
-
|
138
|
+
attr_result
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def elements_by_tag_names(tags = @tags)
|
143
|
+
with_nullpointer_retry do
|
144
|
+
# HtmlUnit's getHtmlElementsByTagNames won't get elements in the correct
|
145
|
+
# order (making :index fail), so we're using getAllHtmlChildElements instead.
|
146
|
+
@object.getAllHtmlChildElements.select do |elem|
|
147
|
+
tags.include?(elem.getTagName)
|
148
|
+
end
|
142
149
|
end
|
143
150
|
end
|
144
151
|
|
152
|
+
# HtmlUnit throws NPEs sometimes when we're locating elements
|
153
|
+
# Retry seems to work fine.
|
154
|
+
def with_nullpointer_retry(max_retries = 3)
|
155
|
+
tries = 0
|
156
|
+
yield
|
157
|
+
rescue java.lang.NullPointerException => e
|
158
|
+
raise e if tries >= max_retries
|
159
|
+
|
160
|
+
tries += 1
|
161
|
+
$stderr.puts "warning: celerity caught #{e} - retry ##{tries}"
|
162
|
+
retry
|
163
|
+
end
|
164
|
+
|
165
|
+
def matches?(string, what)
|
166
|
+
Regexp === what ? string.strip =~ what : string == what.to_s
|
167
|
+
end
|
145
168
|
|
146
169
|
end # ElementLocator
|
147
170
|
end # Celerity
|
@@ -1,25 +1,36 @@
|
|
1
1
|
module Celerity
|
2
|
-
|
2
|
+
|
3
|
+
#
|
3
4
|
# Input: Button
|
4
5
|
#
|
5
6
|
# Class representing button elements
|
6
7
|
#
|
8
|
+
|
7
9
|
class Button < InputElement
|
8
|
-
TAGS = [ Identifier.new('button'),
|
9
|
-
Identifier.new('input', :type => %w
|
10
|
-
|
10
|
+
TAGS = [ Identifier.new('button'),
|
11
|
+
Identifier.new('input', :type => %w[submit reset image button]) ]
|
12
|
+
|
13
|
+
# Attribute list is a little weird due to this class covering both <button>
|
14
|
+
# and <input type="submit|reset|image|button" />
|
11
15
|
ATTRIBUTES = BASE_ATTRIBUTES | [:type, :disabled, :tabindex, :accesskey, :onfocus, :onblur] | [:src, :usemap, :ismap]
|
12
16
|
DEFAULT_HOW = :value
|
13
17
|
|
18
|
+
#
|
19
|
+
# @api private
|
20
|
+
#
|
21
|
+
|
14
22
|
def locate
|
15
|
-
#
|
16
|
-
#
|
23
|
+
# We want the :value attribute to point to the inner HTML for <button> elements,
|
24
|
+
# and to the value attribute for <input type="button"> elements.
|
25
|
+
|
17
26
|
if (val = @conditions[:value])
|
18
|
-
|
19
|
-
button_ident = Identifier.new('button')
|
27
|
+
button_ident = Identifier.new('button')
|
20
28
|
button_ident.text = val
|
21
|
-
input_ident
|
29
|
+
input_ident = Identifier.new('input', :type => %w[submit reset image button], :value => [val])
|
30
|
+
|
31
|
+
locator = ElementLocator.new(@container, self.class)
|
22
32
|
locator.idents = [button_ident, input_ident]
|
33
|
+
|
23
34
|
conditions = @conditions.dup
|
24
35
|
conditions.delete(:value)
|
25
36
|
@object = locator.find_by_conditions(conditions)
|
@@ -27,7 +38,6 @@ module Celerity
|
|
27
38
|
super
|
28
39
|
end
|
29
40
|
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
41
|
+
|
42
|
+
end # Button
|
43
|
+
end # Celerity
|
@@ -1,13 +1,25 @@
|
|
1
1
|
module Celerity
|
2
|
+
|
3
|
+
#
|
2
4
|
# For fields that accept file uploads
|
5
|
+
#
|
6
|
+
|
3
7
|
class FileField < InputElement
|
4
|
-
TAGS = [ Identifier.new('input', :type => %w
|
8
|
+
TAGS = [ Identifier.new('input', :type => %w[file]) ]
|
5
9
|
DEFAULT_HOW = :name
|
6
|
-
|
10
|
+
|
11
|
+
#
|
7
12
|
# Set the file field to the given path
|
13
|
+
#
|
14
|
+
|
8
15
|
def set(path)
|
9
16
|
assert_exists
|
10
|
-
|
17
|
+
path = path.to_s
|
18
|
+
@container.update_page @object.setValueAttribute(path)
|
19
|
+
unless @object.getContentType
|
20
|
+
@object.setContentType(Celerity::Util.content_type_for(path))
|
21
|
+
end
|
11
22
|
end
|
12
|
-
|
13
|
-
end
|
23
|
+
|
24
|
+
end # FileField
|
25
|
+
end # Celerity
|
@@ -1,16 +1,21 @@
|
|
1
|
-
module Celerity
|
2
|
-
class Form < Element
|
3
|
-
include Container
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
module Celerity
|
2
|
+
class Form < Element
|
3
|
+
include Container
|
4
|
+
|
5
|
+
TAGS = [Identifier.new('form')]
|
6
|
+
|
7
|
+
# HTML 4.01 Transitional DTD
|
8
|
+
ATTRIBUTES = BASE_ATTRIBUTES | [:action, :method, :enctype, :accept, :name, :onsubmit, :onreset, :target, :'accept-charset']
|
9
|
+
DEFAULT_HOW = :name
|
10
|
+
|
11
|
+
#
|
12
|
+
# Submits the form.
|
13
|
+
#
|
14
|
+
|
15
|
+
def submit
|
16
|
+
assert_exists
|
17
|
+
@container.update_page @object.submit(nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
end # Form
|
21
|
+
end # Celerity
|
@@ -1,53 +1,75 @@
|
|
1
|
-
module Celerity
|
2
|
-
class Frame < Element
|
3
|
-
include Container
|
4
|
-
attr_accessor :page
|
5
|
-
|
6
|
-
TAGS = [Identifier.new('frame'), Identifier.new('iframe')]
|
7
|
-
ATTRIBUTES = BASE_ATTRIBUTES | [:longdesc, :name, :src, :frameborder, :marginwidth, :marginheight, :noresize, :scrolling]
|
8
|
-
DEFAULT_HOW = :name
|
9
|
-
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
1
|
+
module Celerity
|
2
|
+
class Frame < Element
|
3
|
+
include Container
|
4
|
+
attr_accessor :page
|
5
|
+
|
6
|
+
TAGS = [Identifier.new('frame'), Identifier.new('iframe')]
|
7
|
+
ATTRIBUTES = BASE_ATTRIBUTES | [:longdesc, :name, :src, :frameborder, :marginwidth, :marginheight, :noresize, :scrolling]
|
8
|
+
DEFAULT_HOW = :name
|
9
|
+
|
10
|
+
#
|
11
|
+
# Override the default locate to handle frame and inline frames.
|
12
|
+
# @api private
|
13
|
+
#
|
14
|
+
|
15
|
+
def locate
|
16
|
+
super
|
17
|
+
if @object
|
18
|
+
@inline_frame_object = @object.getEnclosedWindow.getFrameElement
|
19
|
+
self.page = @object.getEnclosedPage
|
20
|
+
if (frame = self.page.getDocumentElement)
|
21
|
+
@object = frame
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Override assert_exists to raise UnknownFrameException (for Watir compatibility)
|
28
|
+
# @api private
|
29
|
+
#
|
30
|
+
|
31
|
+
def assert_exists
|
32
|
+
locate
|
33
|
+
unless @object
|
34
|
+
raise UnknownFrameException, "unable to locate frame, using #{identifier_string}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Executes the given JavaScript string in this frame. (Celerity only)
|
40
|
+
#
|
41
|
+
|
42
|
+
def execute_script(source)
|
43
|
+
assert_exists
|
44
|
+
@page.executeJavaScript(source.to_s).getJavaScriptResult
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Updates the brwoser page with the page from this frame's top window.
|
49
|
+
# Used internally.
|
50
|
+
#
|
51
|
+
# @api private
|
52
|
+
#
|
53
|
+
|
54
|
+
def update_page(value)
|
55
|
+
@browser.page = value.getEnclosingWindow.getTopWindow.getEnclosedPage
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_s
|
59
|
+
assert_exists
|
60
|
+
create_string(@inline_frame_object)
|
61
|
+
end
|
62
|
+
|
63
|
+
def method_missing(meth, *args, &blk)
|
64
|
+
meth = selector_to_attribute(meth)
|
65
|
+
if self.class::ATTRIBUTES.include?(meth)
|
66
|
+
assert_exists
|
67
|
+
@inline_frame_object.getAttributeValue(meth.to_s)
|
68
|
+
else
|
69
|
+
Log.warn "Element\#method_missing calling super with #{meth.inspect}"
|
70
|
+
super
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end # Frame
|
75
|
+
end # Celerity
|