celerity 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +14 -0
- data/Manifest.txt +127 -151
- data/README.txt +15 -20
- data/lib/celerity.rb +13 -5
- data/lib/celerity/browser.rb +296 -0
- data/lib/celerity/clickable_element.rb +1 -0
- data/lib/celerity/collections.rb +4 -0
- data/lib/celerity/container.rb +69 -2
- data/lib/celerity/disabled_element.rb +1 -0
- data/lib/celerity/element.rb +103 -38
- data/lib/celerity/element_collections.rb +14 -8
- data/lib/celerity/element_locator.rb +61 -50
- data/lib/celerity/element_map.rb +51 -0
- data/lib/celerity/elements/button.rb +1 -0
- data/lib/celerity/elements/file_field.rb +3 -2
- data/lib/celerity/elements/form.rb +1 -0
- data/lib/celerity/elements/frame.rb +16 -1
- data/lib/celerity/elements/image.rb +15 -13
- data/lib/celerity/elements/link.rb +4 -1
- data/lib/celerity/elements/option.rb +1 -0
- data/lib/celerity/elements/radio_check.rb +19 -7
- data/lib/celerity/elements/select_list.rb +17 -2
- data/lib/celerity/elements/table.rb +34 -20
- data/lib/celerity/elements/table_body.rb +2 -2
- data/lib/celerity/elements/table_cell.rb +3 -1
- data/lib/celerity/elements/table_footer.rb +2 -2
- data/lib/celerity/elements/table_header.rb +2 -2
- data/lib/celerity/elements/table_row.rb +4 -2
- data/lib/celerity/elements/text_field.rb +20 -9
- data/lib/celerity/exception.rb +11 -18
- data/lib/celerity/extra/method_generator.rb +13 -8
- data/lib/celerity/htmlunit/download.sh +23 -0
- 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.7.jar → nekohtml-1.9.8.jar} +0 -0
- data/lib/celerity/input_element.rb +1 -1
- data/lib/celerity/version.rb +1 -1
- data/lib/celerity/watir_compatibility.rb +37 -23
- data/spec/area_spec.rb +19 -4
- data/spec/areas_spec.rb +2 -3
- data/spec/{ie_spec.rb → browser_spec.rb} +66 -15
- data/spec/button_spec.rb +36 -3
- data/spec/buttons_spec.rb +2 -3
- data/spec/checkbox_spec.rb +43 -8
- data/spec/checkboxes_spec.rb +2 -3
- data/spec/div_spec.rb +31 -4
- data/spec/divs_spec.rb +2 -3
- data/spec/element_spec.rb +36 -6
- data/spec/filefield_spec.rb +28 -13
- data/spec/filefields_spec.rb +2 -3
- data/spec/form_spec.rb +6 -3
- data/spec/forms_spec.rb +2 -3
- data/spec/frame_spec.rb +14 -5
- data/spec/frames_spec.rb +71 -0
- data/spec/hidden_spec.rb +21 -3
- data/spec/hiddens_spec.rb +2 -3
- data/spec/hn_spec.rb +30 -12
- data/spec/hns_spec.rb +14 -10
- data/spec/html/form_js_bug.html +11 -0
- data/spec/html/forms_with_input_elements.html +2 -1
- data/spec/html/invalid_js.html +11 -0
- data/spec/html/latin1_text.html +1 -0
- data/spec/html/non_control_elements.html +8 -4
- data/spec/html/simple_ajax.html +22 -0
- data/spec/htmlunit_spec.rb +4 -5
- data/spec/image_spec.rb +33 -3
- data/spec/images_spec.rb +2 -3
- data/spec/label_spec.rb +16 -3
- data/spec/labels_spec.rb +2 -3
- data/spec/li_spec.rb +25 -3
- data/spec/link_spec.rb +35 -3
- data/spec/links_spec.rb +2 -3
- data/spec/lis_spec.rb +2 -3
- data/spec/map_spec.rb +19 -3
- data/spec/maps_spec.rb +2 -3
- data/spec/meta_spec.rb +3 -1
- data/spec/ol_spec.rb +17 -3
- data/spec/ols_spec.rb +2 -3
- data/spec/option_spec.rb +28 -3
- data/spec/p_spec.rb +30 -2
- data/spec/pre_spec.rb +25 -3
- data/spec/pres_spec.rb +2 -3
- data/spec/ps_spec.rb +2 -3
- data/spec/radio_spec.rb +47 -3
- data/spec/radios_spec.rb +2 -3
- data/spec/select_list_spec.rb +42 -3
- data/spec/select_lists_spec.rb +2 -3
- data/spec/span_spec.rb +32 -7
- data/spec/spans_spec.rb +2 -4
- data/spec/spec_helper.rb +5 -25
- data/spec/table_bodies_spec.rb +7 -5
- data/spec/table_body_spec.rb +11 -4
- data/spec/table_cell_spec.rb +15 -4
- data/spec/table_cells_spec.rb +3 -4
- data/spec/table_footer_spec.rb +11 -4
- data/spec/table_footers_spec.rb +7 -5
- data/spec/table_header_spec.rb +11 -4
- data/spec/table_headers_spec.rb +7 -5
- data/spec/table_row_spec.rb +31 -7
- data/spec/table_rows_spec.rb +5 -4
- data/spec/table_spec.rb +36 -7
- data/spec/tables_spec.rb +2 -3
- data/spec/text_field_spec.rb +51 -13
- data/spec/text_fields_spec.rb +2 -3
- data/spec/ul_spec.rb +18 -3
- data/spec/uls_spec.rb +2 -3
- data/spec/{watir_compatability_spec.rb → watir_compatibility_spec.rb} +42 -35
- data/support/spec_server.rb +9 -0
- metadata +167 -161
- metadata.gz.sig +0 -0
- data/benchmark/bm_2000_spans.rb +0 -48
- data/benchmark/bm_digg.rb +0 -26
- data/benchmark/bm_google_images.rb +0 -36
- data/benchmark/bm_input_locator.rb +0 -69
- data/benchmark/loader.rb +0 -9
- data/config/hoe.rb +0 -68
- data/config/requirements.rb +0 -15
- data/lib/celerity/htmlunit/htmlunit-2.2-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/js-1.7R1.jar +0 -0
- data/lib/celerity/ie.rb +0 -195
- data/setup.rb +0 -1583
- data/support/celerity_viewer/rubycocoa/CelerityViewer.icns +0 -0
- data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/classes.nib +0 -37
- data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/info.nib +0 -19
- data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/keyedobjects.nib +0 -0
- data/support/celerity_viewer/rubycocoa/Info.plist.erb +0 -28
- data/support/celerity_viewer/rubycocoa/MainController.rb +0 -23
- data/support/celerity_viewer/rubycocoa/README +0 -94
- data/support/celerity_viewer/rubycocoa/Rakefile +0 -100
- data/support/celerity_viewer/rubycocoa/distributed_viewer.rb +0 -86
- data/support/celerity_viewer/rubycocoa/main.m +0 -7
- data/support/celerity_viewer/rubycocoa/main.rb +0 -27
- data/tasks/benchmark.rake +0 -4
- data/tasks/environment.rake +0 -7
- data/tasks/simple_ci.rake +0 -94
@@ -1,25 +1,28 @@
|
|
1
1
|
module Celerity
|
2
|
-
#
|
3
|
-
#
|
2
|
+
# This class is the superclass for the iterator classes (Buttons, Links, Spans etc.)
|
3
|
+
# It would normally only be accessed by the iterator methods (Browser#spans, Browser#links, ...).
|
4
4
|
class ElementCollections
|
5
5
|
include Enumerable
|
6
6
|
|
7
|
+
# @api internal
|
7
8
|
def initialize(container, how = nil, what = nil)
|
8
9
|
@container = container
|
9
10
|
@object = (how == :object ? what : nil)
|
10
11
|
@length = length
|
11
12
|
end
|
12
|
-
|
13
|
+
|
14
|
+
# @return [Fixnum] The number of elements in this collection.
|
13
15
|
def length
|
14
16
|
if @object
|
15
17
|
@object.length
|
16
18
|
else
|
17
|
-
@elements
|
19
|
+
@elements ||= ElementLocator.new(@container.object, element_class).elements_by_idents
|
18
20
|
@elements.size
|
19
21
|
end
|
20
22
|
end
|
21
23
|
alias_method :size, :length
|
22
24
|
|
25
|
+
# @yield [element] Iterate through the elements in this collection.
|
23
26
|
def each
|
24
27
|
if @elements
|
25
28
|
@elements.each { |e| yield(element_class.new(@container, :object, e)) }
|
@@ -29,19 +32,22 @@ module Celerity
|
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
35
|
+
# Get the element at the given index.
|
36
|
+
# NB! This is 1-indexed to keep compatibility with Watir. Subject to change.
|
37
|
+
#
|
38
|
+
# @return [Celerity::Element]
|
32
39
|
def [](n)
|
33
|
-
@elements ? element_class.new(@container, :object, @elements[n
|
40
|
+
@elements ? element_class.new(@container, :object, @elements[n-1]) : iterator_object(n-1)
|
34
41
|
end
|
35
42
|
|
36
43
|
def to_s
|
37
|
-
|
44
|
+
map { |e| e.to_s }.join("\n")
|
38
45
|
end
|
39
46
|
|
40
47
|
private
|
41
48
|
|
42
|
-
# this method creates an object of the correct type that the iterators use
|
43
49
|
def iterator_object(i)
|
44
|
-
element_class.new(@container, :index, i
|
50
|
+
element_class.new(@container, :index, i+1)
|
45
51
|
end
|
46
52
|
|
47
53
|
end # ElementCollections
|
@@ -1,9 +1,6 @@
|
|
1
1
|
module Celerity
|
2
2
|
|
3
|
-
#
|
4
|
-
# Instead of iterating twice through a lot of elements, we could modify the Identifier objects to contain
|
5
|
-
# everything in our 'query'.
|
6
|
-
# Jari - 2008-05-11
|
3
|
+
# Used internally to locate elements on the page.
|
7
4
|
class ElementLocator
|
8
5
|
include Celerity::Exception
|
9
6
|
attr_accessor :idents
|
@@ -23,55 +20,53 @@ module Celerity
|
|
23
20
|
index = 0 # by default, return the first matching element
|
24
21
|
text = nil
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
how = :text
|
41
|
-
end
|
42
|
-
|
43
|
-
if @attributes.include?(how)
|
44
|
-
attributes[how] << what
|
45
|
-
elsif how == :index
|
46
|
-
index = what.to_i - 1
|
47
|
-
elsif how == :text
|
48
|
-
text = what
|
49
|
-
else
|
50
|
-
raise MissingWayOfFindingObjectException, "No how #{how.inspect}"
|
51
|
-
end
|
52
|
-
|
23
|
+
conditions.each do |how, what|
|
24
|
+
case how
|
25
|
+
when :object
|
26
|
+
return what
|
27
|
+
when :id
|
28
|
+
return find_by_id(what)
|
29
|
+
when :xpath
|
30
|
+
return find_by_xpath(what)
|
31
|
+
when :class_name
|
32
|
+
how = :class
|
33
|
+
when :url
|
34
|
+
how = :href
|
35
|
+
when :caption
|
36
|
+
how = :text
|
53
37
|
end
|
54
|
-
|
55
|
-
@
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
# «original» identifier takes precedence for :text
|
62
|
-
id.text = ident.text || text
|
63
|
-
@condition_idents << id
|
64
|
-
end
|
65
|
-
|
66
|
-
if index == 0
|
67
|
-
element_by_idents(@condition_idents)
|
38
|
+
|
39
|
+
if @attributes.include?(how)
|
40
|
+
attributes[how] << what
|
41
|
+
elsif how == :index
|
42
|
+
index = what.to_i - 1
|
43
|
+
elsif how == :text
|
44
|
+
text = what
|
68
45
|
else
|
69
|
-
|
46
|
+
raise MissingWayOfFindingObjectException, "No how #{how.inspect}"
|
70
47
|
end
|
71
48
|
|
72
|
-
rescue HtmlUnit::ElementNotFoundException
|
73
|
-
nil # for rcov
|
74
49
|
end
|
50
|
+
|
51
|
+
@idents.each do |ident|
|
52
|
+
merged = attributes.merge(ident.attributes) do |key, v1, v2|
|
53
|
+
v1 | v2
|
54
|
+
end
|
55
|
+
|
56
|
+
id = Identifier.new(ident.tag, merged)
|
57
|
+
# «original» identifier takes precedence for :text
|
58
|
+
id.text = ident.text || text
|
59
|
+
@condition_idents << id
|
60
|
+
end
|
61
|
+
|
62
|
+
if index == 0
|
63
|
+
element_by_idents(@condition_idents)
|
64
|
+
else
|
65
|
+
elements_by_idents(@condition_idents)[index]
|
66
|
+
end
|
67
|
+
|
68
|
+
rescue HtmlUnit::ElementNotFoundException
|
69
|
+
nil # for rcov
|
75
70
|
end
|
76
71
|
|
77
72
|
def find_by_id(what)
|
@@ -79,7 +74,13 @@ module Celerity
|
|
79
74
|
when Regexp
|
80
75
|
elements_by_tag_names.find { |elem| elem.getIdAttribute =~ what }
|
81
76
|
when String
|
82
|
-
@object.getHtmlElementById(what)
|
77
|
+
obj = @object.getHtmlElementById(what)
|
78
|
+
if @tags.include?(obj.getTagName)
|
79
|
+
obj
|
80
|
+
else
|
81
|
+
$stderr.puts "warning: multiple elements with identical id (#{what.inspect})? " if $VERBOSE
|
82
|
+
elements_by_tag_names.find { |elem| elem.getIdAttribute == what }
|
83
|
+
end
|
83
84
|
else
|
84
85
|
raise ArgumentError, "Argument #{what.inspect} should be a String or Regexp"
|
85
86
|
end
|
@@ -105,6 +106,7 @@ module Celerity
|
|
105
106
|
if @tags.include?(e.getTagName)
|
106
107
|
idents.any? do |ident|
|
107
108
|
next unless ident.tag == e.getTagName
|
109
|
+
|
108
110
|
attr_result = ident.attributes.all? do |key, value|
|
109
111
|
value.any? { |val| matches?(e.getAttributeValue(key.to_s), val) }
|
110
112
|
end
|
@@ -114,7 +116,6 @@ module Celerity
|
|
114
116
|
else
|
115
117
|
attr_result
|
116
118
|
end
|
117
|
-
|
118
119
|
end
|
119
120
|
end
|
120
121
|
end
|
@@ -125,10 +126,20 @@ module Celerity
|
|
125
126
|
end
|
126
127
|
|
127
128
|
def elements_by_tag_names
|
129
|
+
tries = 0
|
128
130
|
# HtmlUnit's getHtmlElementsByTagNames won't get elements in the correct order, making :index fail
|
129
131
|
@object.getAllHtmlChildElements.iterator.to_a.select do |elem|
|
130
132
|
@tags.include?(elem.getTagName)
|
131
133
|
end
|
134
|
+
# workaround for HtmlUnit bug?
|
135
|
+
rescue java.lang.NullPointerException => e
|
136
|
+
$stderr.puts "warning: celerity caught #{e}"
|
137
|
+
if tries < 2
|
138
|
+
tries += 1
|
139
|
+
retry
|
140
|
+
else
|
141
|
+
raise e
|
142
|
+
end
|
132
143
|
end
|
133
144
|
|
134
145
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Celerity
|
2
|
+
module ElementMap
|
3
|
+
# Some HtmlUnit classes are missing equivalents in Celerity. Shouldn't be too hard to fix.
|
4
|
+
# This is mostly used to implement Element#parent easily.
|
5
|
+
HtmlUnit2CelerityElement = {
|
6
|
+
HtmlUnit::Html::HtmlAnchor => Celerity::Link,
|
7
|
+
HtmlUnit::Html::HtmlArea => Celerity::Area,
|
8
|
+
HtmlUnit::Html::HtmlButton => Celerity::Button,
|
9
|
+
HtmlUnit::Html::HtmlButtonInput => Celerity::Button,
|
10
|
+
HtmlUnit::Html::HtmlCaption => Celerity::Button, # ?
|
11
|
+
HtmlUnit::Html::HtmlCheckBoxInput => Celerity::CheckBox,
|
12
|
+
HtmlUnit::Html::HtmlDivision => Celerity::Div,
|
13
|
+
HtmlUnit::Html::HtmlFileInput => Celerity::FileField,
|
14
|
+
HtmlUnit::Html::HtmlForm => Celerity::Form,
|
15
|
+
HtmlUnit::Html::HtmlFrame => Celerity::Frame,
|
16
|
+
HtmlUnit::Html::HtmlHeading1 => Celerity::H1,
|
17
|
+
HtmlUnit::Html::HtmlHeading2 => Celerity::H2,
|
18
|
+
HtmlUnit::Html::HtmlHeading3 => Celerity::H3,
|
19
|
+
HtmlUnit::Html::HtmlHeading4 => Celerity::H4,
|
20
|
+
HtmlUnit::Html::HtmlHeading5 => Celerity::H5,
|
21
|
+
HtmlUnit::Html::HtmlHeading6 => Celerity::H6,
|
22
|
+
HtmlUnit::Html::HtmlHiddenInput => Celerity::Hidden,
|
23
|
+
HtmlUnit::Html::HtmlImage => Celerity::Image,
|
24
|
+
HtmlUnit::Html::HtmlLabel => Celerity::Label,
|
25
|
+
HtmlUnit::Html::HtmlLink => Celerity::Link,
|
26
|
+
HtmlUnit::Html::HtmlListItem => Celerity::Li,
|
27
|
+
HtmlUnit::Html::HtmlMap => Celerity::Map,
|
28
|
+
HtmlUnit::Html::HtmlOption => Celerity::Option,
|
29
|
+
HtmlUnit::Html::HtmlOrderedList => Celerity::Ol,
|
30
|
+
HtmlUnit::Html::HtmlParagraph => Celerity::P,
|
31
|
+
HtmlUnit::Html::HtmlPasswordInput => Celerity::TextField,
|
32
|
+
HtmlUnit::Html::HtmlPreformattedText => Celerity::Pre,
|
33
|
+
HtmlUnit::Html::HtmlRadioButtonInput => Celerity::Radio,
|
34
|
+
HtmlUnit::Html::HtmlSelect => Celerity::SelectList,
|
35
|
+
HtmlUnit::Html::HtmlSpan => Celerity::Span,
|
36
|
+
HtmlUnit::Html::HtmlTable => Celerity::Table,
|
37
|
+
HtmlUnit::Html::HtmlTableBody => Celerity::TableBody,
|
38
|
+
HtmlUnit::Html::HtmlTableCell => Celerity::TableCell,
|
39
|
+
HtmlUnit::Html::HtmlTableFooter => Celerity::TableFooter,
|
40
|
+
HtmlUnit::Html::HtmlTableHeader => Celerity::TableHeader,
|
41
|
+
HtmlUnit::Html::HtmlTableRow => Celerity::TableRow,
|
42
|
+
HtmlUnit::Html::HtmlTextArea => Celerity::Area,
|
43
|
+
HtmlUnit::Html::HtmlTextInput => Celerity::TextField,
|
44
|
+
HtmlUnit::Html::HtmlUnorderedList => Celerity::Ul
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Celerity::Element
|
50
|
+
include Celerity::ElementMap
|
51
|
+
end
|
@@ -4,9 +4,10 @@ module Celerity
|
|
4
4
|
TAGS = [ Identifier.new('input', :type => %w(file)) ]
|
5
5
|
DEFAULT_HOW = :name
|
6
6
|
|
7
|
-
|
7
|
+
# Set the file field to the given path
|
8
|
+
def set(path)
|
8
9
|
assert_exists
|
9
|
-
@object.setValueAttribute(
|
10
|
+
@object.setValueAttribute(path.to_s)
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -7,6 +7,8 @@ module Celerity
|
|
7
7
|
ATTRIBUTES = BASE_ATTRIBUTES | [:longdesc, :name, :src, :frameborder, :marginwidth, :marginheight, :noresize, :scrolling]
|
8
8
|
DEFAULT_HOW = :name
|
9
9
|
|
10
|
+
# Override the default locate to handle frame and inline frames.
|
11
|
+
# @api internal
|
10
12
|
def locate
|
11
13
|
super
|
12
14
|
if @object
|
@@ -17,6 +19,8 @@ module Celerity
|
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
22
|
+
# Override assert_exists to raise UnknownFrameException (for Watir compatibility)
|
23
|
+
# @api internal
|
20
24
|
def assert_exists
|
21
25
|
locate unless @object
|
22
26
|
unless @object
|
@@ -25,7 +29,7 @@ module Celerity
|
|
25
29
|
end
|
26
30
|
|
27
31
|
def update_page(value)
|
28
|
-
@page_container.
|
32
|
+
@page_container.page = value.getEnclosingWindow.getTopWindow.getEnclosedPage
|
29
33
|
end
|
30
34
|
|
31
35
|
def to_s
|
@@ -33,6 +37,17 @@ module Celerity
|
|
33
37
|
create_string(@inline_frame_object)
|
34
38
|
end
|
35
39
|
|
40
|
+
def method_missing(meth, *args, &blk)
|
41
|
+
meth = selector_to_attribute(meth)
|
42
|
+
if self.class::ATTRIBUTES.include?(meth)
|
43
|
+
assert_exists
|
44
|
+
@inline_frame_object.getAttributeValue(meth.to_s)
|
45
|
+
else
|
46
|
+
Log.warn "Element\#method_missing calling super with #{meth.inspect}"
|
47
|
+
super
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
36
51
|
end
|
37
52
|
|
38
53
|
end
|
@@ -1,10 +1,5 @@
|
|
1
1
|
module Celerity
|
2
2
|
|
3
|
-
# This class is the means of accessing an image on a page.
|
4
|
-
# Normally a user would not need to create this object as it is returned by the Watir::Container#image method
|
5
|
-
#
|
6
|
-
# many of the methods available to this object are inherited from the Element class
|
7
|
-
#
|
8
3
|
class Image < Element
|
9
4
|
include ClickableElement
|
10
5
|
include DisabledElement
|
@@ -13,18 +8,18 @@ module Celerity
|
|
13
8
|
ATTRIBUTES = BASE_ATTRIBUTES | [:src, :alt, :longdesc, :name, :height, :width, :usemap, :ismap, :align, :border, :hspace, :vspace]
|
14
9
|
DEFAULT_HOW = :src
|
15
10
|
|
16
|
-
#
|
11
|
+
# returns the file created date of the image
|
17
12
|
def file_created_date
|
18
13
|
assert_exists
|
19
14
|
web_response = @object.getWebResponse(true)
|
20
|
-
|
15
|
+
Time.parse(web_response.getResponseHeaderValue("Last-Modified").to_s)
|
21
16
|
end
|
22
17
|
|
23
|
-
#
|
18
|
+
# returns the filesize of the image
|
24
19
|
def file_size
|
25
20
|
assert_exists
|
26
21
|
web_response = @object.getWebResponse(true)
|
27
|
-
|
22
|
+
web_response.getResponseBody.length
|
28
23
|
end
|
29
24
|
|
30
25
|
# returns the width in pixels of the image, as a string
|
@@ -38,23 +33,30 @@ module Celerity
|
|
38
33
|
assert_exists
|
39
34
|
@object.getHeight
|
40
35
|
end
|
41
|
-
|
36
|
+
|
37
|
+
# returns true if the image is loaded
|
42
38
|
def loaded?
|
43
39
|
assert_exists
|
44
40
|
begin
|
45
41
|
@object.getImageReader
|
46
|
-
|
42
|
+
true
|
47
43
|
rescue
|
48
|
-
|
44
|
+
false
|
49
45
|
end
|
50
46
|
end
|
51
47
|
|
48
|
+
def click
|
49
|
+
assert_exists
|
50
|
+
@container.update_page(@object.click)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Saves the image to the given file
|
52
54
|
def save(filename)
|
53
55
|
assert_exists
|
54
56
|
image_reader = @object.getImageReader
|
55
57
|
file = java.io.File.new(filename)
|
56
58
|
buffered_image = image_reader.read(0);
|
57
|
-
|
59
|
+
javax.imageio.ImageIO.write(buffered_image, image_reader.getFormatName(), file);
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
@@ -2,9 +2,12 @@ module Celerity
|
|
2
2
|
class Link < Element
|
3
3
|
|
4
4
|
TAGS = [ Identifier.new('a') ]
|
5
|
-
ATTRIBUTES = BASE_ATTRIBUTES | [:charset, :type, :name, :href, :hreflang,
|
5
|
+
ATTRIBUTES = BASE_ATTRIBUTES | [:charset, :type, :name, :href, :hreflang,
|
6
|
+
:target, :rel, :rev, :accesskey, :shape,
|
7
|
+
:coords, :tabindex, :onfocus, :onblur]
|
6
8
|
DEFAULT_HOW = :href
|
7
9
|
|
10
|
+
# clicks the link
|
8
11
|
def click
|
9
12
|
assert_exists
|
10
13
|
@container.update_page @object.click
|
@@ -1,13 +1,10 @@
|
|
1
1
|
module Celerity
|
2
|
-
#
|
3
|
-
# It contains methods common to both.
|
4
|
-
# Normally a user would not need to create this object as it is returned by the Watir::Container#checkbox or Watir::Container#radio methods
|
5
|
-
#
|
6
|
-
# most of the methods available to this element are inherited from the Element class
|
7
|
-
#
|
2
|
+
# Common superclass for radios and check boxes.
|
8
3
|
class RadioCheckCommon < InputElement
|
9
4
|
DEFAULT_HOW = :name
|
10
|
-
|
5
|
+
|
6
|
+
# these can optionally take a value parameter as a third arg, so needs
|
7
|
+
# to be special-handled.
|
11
8
|
def initialize(container, type, *args)
|
12
9
|
@type = type
|
13
10
|
case args.size
|
@@ -20,6 +17,7 @@ module Celerity
|
|
20
17
|
end
|
21
18
|
end
|
22
19
|
|
20
|
+
# returns true if the element is checked
|
23
21
|
def set?
|
24
22
|
assert_exists
|
25
23
|
@object.isChecked
|
@@ -39,6 +37,13 @@ module Celerity
|
|
39
37
|
super(container, ['radio'], *args)
|
40
38
|
end
|
41
39
|
|
40
|
+
# Sets the radio button.
|
41
|
+
#
|
42
|
+
# radio.set? # => false
|
43
|
+
# radio.set
|
44
|
+
# radio.set? # => true
|
45
|
+
# radio.set(false)
|
46
|
+
# radio.set? # => false
|
42
47
|
def set(value = true)
|
43
48
|
assert_exists
|
44
49
|
assert_enabled
|
@@ -55,6 +60,13 @@ module Celerity
|
|
55
60
|
super(container, ['checkbox'], *args)
|
56
61
|
end
|
57
62
|
|
63
|
+
# Sets the checkbox button.
|
64
|
+
#
|
65
|
+
# checkbox.set? # => false
|
66
|
+
# checkbox.set
|
67
|
+
# checkbox.set? # => true
|
68
|
+
# checkbox.set(false)
|
69
|
+
# checkbox.set? # => false
|
58
70
|
def set(value = true)
|
59
71
|
assert_exists
|
60
72
|
assert_enabled
|