celerity 0.0.1
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 +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,20 @@
|
|
|
1
|
+
module Celerity
|
|
2
|
+
module DisabledElement
|
|
3
|
+
def enabled?
|
|
4
|
+
!disabled?
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def disabled?
|
|
8
|
+
assert_exists
|
|
9
|
+
@object.isDisabled
|
|
10
|
+
end
|
|
11
|
+
alias_method :disabled, :disabled?
|
|
12
|
+
|
|
13
|
+
def assert_enabled
|
|
14
|
+
if disabled?
|
|
15
|
+
raise ObjectDisabledException, "Object #{@how.inspect} and #{@what.inspect} is disabled"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
module Celerity
|
|
2
|
+
class Element
|
|
3
|
+
include Exception
|
|
4
|
+
include Container
|
|
5
|
+
attr_accessor :container, :object
|
|
6
|
+
|
|
7
|
+
# HTML 4.01 Transitional DTD
|
|
8
|
+
CELLHALIGN_ATTRIBUTES = [:align, :char, :charoff]
|
|
9
|
+
CELLVALIGN_ATTRIBUTES = [:valign]
|
|
10
|
+
CORE_ATTRIBUTES = [:class, :id, :style, :title] # Not valid in base, head, html, meta, param, script, style, and title elements.
|
|
11
|
+
I18N_ATTRIBUTES = [:dir, :lang] # Not valid in base, br, frame, frameset, hr, iframe, param, and script elements.
|
|
12
|
+
EVENT_ATTRIBUTES = [:onclick, :ondblclick, :onmousedown, :onmouseup, :onmouseover, :onmousemove, :onmouseout, :onkeypress, :onkeydown, :onkeyup]
|
|
13
|
+
SLOPPY_ATTRIBUTES = [:name, :value]
|
|
14
|
+
BASE_ATTRIBUTES = CORE_ATTRIBUTES | I18N_ATTRIBUTES | EVENT_ATTRIBUTES | SLOPPY_ATTRIBUTES
|
|
15
|
+
ATTRIBUTES = BASE_ATTRIBUTES
|
|
16
|
+
|
|
17
|
+
class Identifier < Struct.new(:tag, :attributes)
|
|
18
|
+
def initialize(t, a={}); super(t, a); end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def initialize(container, *args)
|
|
22
|
+
set_container container
|
|
23
|
+
process_arguments(*args)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def process_arguments(*args)
|
|
27
|
+
if args.size == 1 #&& !args.first.kind_of?(Hash) #(support multiple attributes)
|
|
28
|
+
raise ArgumentError, "wrong number of arguments (1 for 2), DEFAULT_HOW not defined" unless defined? self.class::DEFAULT_HOW
|
|
29
|
+
raise NotImplementedError if args[0].class == Hash
|
|
30
|
+
@how = self.class::DEFAULT_HOW
|
|
31
|
+
@what = args.shift
|
|
32
|
+
else
|
|
33
|
+
@how, @what = *args
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def locate
|
|
38
|
+
@object = @container.locate_tagged_element(self, @how, @what)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def to_s
|
|
42
|
+
assert_exists
|
|
43
|
+
create_string(@object)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# number of spaces that separate the property from the value in the create_string method
|
|
47
|
+
TO_S_SIZE = 14
|
|
48
|
+
|
|
49
|
+
def create_string(element)
|
|
50
|
+
n = []
|
|
51
|
+
n << "tag:".ljust(TO_S_SIZE) + element.getTagName if element.getTagName.length > 0
|
|
52
|
+
iterator = element.getAttributeEntriesIterator
|
|
53
|
+
while (iterator.hasNext)
|
|
54
|
+
attribute = iterator.next
|
|
55
|
+
n << " #{attribute.getName}:".ljust(TO_S_SIZE+2) + attribute.getHtmlValue.to_s
|
|
56
|
+
end
|
|
57
|
+
n << " text:".ljust(TO_S_SIZE+2) + element.asText if element.asText.length > 0
|
|
58
|
+
return n.join("\n")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def attribute_value(attribute)
|
|
62
|
+
assert_exists
|
|
63
|
+
@object.getAttribute(attribute)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def assert_exists
|
|
67
|
+
locate if defined?(locate)
|
|
68
|
+
unless @object
|
|
69
|
+
raise UnknownObjectException, "Unable to locate object, using #{@how.inspect} and #{@what.inspect}"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def exists?
|
|
74
|
+
begin
|
|
75
|
+
assert_exists
|
|
76
|
+
true
|
|
77
|
+
rescue UnknownObjectException
|
|
78
|
+
false
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
alias_method :exist?, :exists?
|
|
82
|
+
alias_method :exists, :exists?
|
|
83
|
+
|
|
84
|
+
def text
|
|
85
|
+
assert_exists
|
|
86
|
+
@object.asText.strip
|
|
87
|
+
end
|
|
88
|
+
alias_method :innerText, :text
|
|
89
|
+
alias_method :inner_text, :text
|
|
90
|
+
|
|
91
|
+
def to_xml
|
|
92
|
+
assert_exists
|
|
93
|
+
@object.asXml
|
|
94
|
+
end
|
|
95
|
+
alias_method :asXml, :to_xml
|
|
96
|
+
alias_method :as_xml, :to_xml
|
|
97
|
+
alias_method :html, :to_xml
|
|
98
|
+
|
|
99
|
+
# used to get attributes
|
|
100
|
+
def method_missing(meth, *args, &blk)
|
|
101
|
+
assert_exists
|
|
102
|
+
meth = :class if meth == :class_name
|
|
103
|
+
meth = :value if meth == :caption
|
|
104
|
+
|
|
105
|
+
if self.class::ATTRIBUTES.include?(meth)
|
|
106
|
+
@object.getAttributeValue(meth.to_s)
|
|
107
|
+
else
|
|
108
|
+
Log.info "Element\#method_missing calling super with #{meth.inspect}"
|
|
109
|
+
super
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
end # Element
|
|
114
|
+
end # Celerity
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module Celerity
|
|
2
|
+
# this class is the super class for the iterator classes (buttons, links, spans etc
|
|
3
|
+
# it would normally only be accessed by the iterator methods (spans, links etc) of IE
|
|
4
|
+
class ElementCollections
|
|
5
|
+
include Enumerable
|
|
6
|
+
|
|
7
|
+
def element_tags
|
|
8
|
+
element_class::TAGS
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def length
|
|
12
|
+
if @object
|
|
13
|
+
@object.length
|
|
14
|
+
elsif Element::Identifier === element_tags.first
|
|
15
|
+
idents = element_tags
|
|
16
|
+
tags = idents.map { |e| e.tag }
|
|
17
|
+
tags.map! { |t| t.downcase }
|
|
18
|
+
elements = @container.object.getAllHtmlChildElements.iterator.to_a.select do |elem|
|
|
19
|
+
tags.include?(elem.getTagName)
|
|
20
|
+
end
|
|
21
|
+
elements = elements.select do |e|
|
|
22
|
+
idents.any? do |ident|
|
|
23
|
+
next unless ident.tag == e.getTagName
|
|
24
|
+
if ident.attributes.empty?
|
|
25
|
+
true
|
|
26
|
+
else
|
|
27
|
+
ident.attributes.any? { |key, value| value.include?(e.getAttributeValue(key.to_s)) }
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
return elements.length
|
|
32
|
+
else
|
|
33
|
+
length = 0
|
|
34
|
+
element_tags.each { |element_tag| length += @container.object.getHtmlElementsByTagName(element_tag).toArray.size }
|
|
35
|
+
return length
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
alias_method :size, :length
|
|
39
|
+
|
|
40
|
+
def initialize(container, how = nil, what = nil)
|
|
41
|
+
@container = container
|
|
42
|
+
if how == :object
|
|
43
|
+
@object = what
|
|
44
|
+
end
|
|
45
|
+
@length = length # defined by subclasses
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def each
|
|
49
|
+
0.upto(@length-1) { |i| yield iterator_object(i) }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def [](n)
|
|
53
|
+
return iterator_object(n-1)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def to_s
|
|
57
|
+
return self.collect { |i| i.to_s }.join("\n")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# this method creates an object of the correct type that the iterators use
|
|
61
|
+
private
|
|
62
|
+
def iterator_object(i)
|
|
63
|
+
element_class.new(@container, :index, i+1)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end # ElementCollections
|
|
67
|
+
end # Celerity
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Celerity
|
|
2
|
+
#
|
|
3
|
+
# Input: Button
|
|
4
|
+
#
|
|
5
|
+
# Class representing button elements
|
|
6
|
+
#
|
|
7
|
+
class Button < InputElement
|
|
8
|
+
TAGS = [ Identifier.new('button'),
|
|
9
|
+
Identifier.new('input', :type => %w(submit reset image button)) ]
|
|
10
|
+
DEFAULT_HOW = :value
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Celerity
|
|
2
|
+
class Form < Element
|
|
3
|
+
include Container
|
|
4
|
+
TAGS = ['form']
|
|
5
|
+
# HTML 4.01 Transitional DTD
|
|
6
|
+
ATTRIBUTES = BASE_ATTRIBUTES | [:action, :method, :enctype, :accept, :name, :onsubmit, :onreset, :target, :'accept-charset']
|
|
7
|
+
DEFAULT_HOW = :name
|
|
8
|
+
|
|
9
|
+
def submit
|
|
10
|
+
assert_exists
|
|
11
|
+
raise NotImplementedError
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Celerity
|
|
2
|
+
class Frame < Element
|
|
3
|
+
include Container
|
|
4
|
+
attr_accessor :page
|
|
5
|
+
TAGS = {'frame' => nil, 'iframe' => nil}
|
|
6
|
+
ATTRIBUTES = BASE_ATTRIBUTES | [:longdesc, :name, :src, :frameborder, :marginwidth, :marginheight, :noresize, :scrolling]
|
|
7
|
+
DEFAULT_HOW = :name
|
|
8
|
+
|
|
9
|
+
def locate
|
|
10
|
+
# Log.debug(@container.object.inspect)
|
|
11
|
+
frame_elements = @container.object.getByXPath(".//iframe | .//frame").collect { |frame| frame.getEnclosedWindow.getFrameElement }
|
|
12
|
+
unless frame_elements.empty?
|
|
13
|
+
case @how
|
|
14
|
+
when :id, :name, :src, :class
|
|
15
|
+
matching_frame_elements = frame_elements.select { |frame_element| matches?(frame_element.getAttribute(@how.to_s), @what) }
|
|
16
|
+
if @frame_element = matching_frame_elements.first
|
|
17
|
+
@object = @frame_element.getEnclosedPage.getDocumentElement
|
|
18
|
+
end
|
|
19
|
+
when :index
|
|
20
|
+
if @frame_element = frame_elements[@what-1]
|
|
21
|
+
@object = @frame_element.getEnclosedPage.getDocumentElement
|
|
22
|
+
end
|
|
23
|
+
when :xpath
|
|
24
|
+
raise NotImplementedError
|
|
25
|
+
else
|
|
26
|
+
raise MissingWayOfFindingObjectException
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
raise UnknownFrameException unless @object
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def update_page(value)
|
|
33
|
+
# Log.debug(value.asXml)
|
|
34
|
+
@page_container.set_page(value.getEnclosingWindow.getTopWindow.getEnclosedPage)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def to_s
|
|
38
|
+
assert_exists
|
|
39
|
+
create_string(@frame_element)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module Celerity
|
|
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
|
+
class Image < Element
|
|
9
|
+
include ClickableElement
|
|
10
|
+
include DisabledElement
|
|
11
|
+
|
|
12
|
+
TAGS = ['img']
|
|
13
|
+
ATTRIBUTES = BASE_ATTRIBUTES | [:src, :alt, :longdesc, :name, :height, :width, :usemap, :ismap, :align, :border, :hspace, :vspace]
|
|
14
|
+
|
|
15
|
+
# this method returns the file created date of the image
|
|
16
|
+
def file_created_date
|
|
17
|
+
assert_exists
|
|
18
|
+
web_response = @object.getWebResponse(true)
|
|
19
|
+
return Time.parse(web_response.getResponseHeaderValue("Last-Modified").to_s)
|
|
20
|
+
end
|
|
21
|
+
alias_method :fileCreatedDate, :file_created_date
|
|
22
|
+
|
|
23
|
+
# this method returns the filesize of the image
|
|
24
|
+
def file_size
|
|
25
|
+
assert_exists
|
|
26
|
+
web_response = @object.getWebResponse(true)
|
|
27
|
+
return web_response.getResponseBody().length
|
|
28
|
+
end
|
|
29
|
+
alias_method :fileSize, :file_size
|
|
30
|
+
|
|
31
|
+
# returns the width in pixels of the image, as a string
|
|
32
|
+
def width
|
|
33
|
+
assert_exists
|
|
34
|
+
@object.getWidth
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# returns the height in pixels of the image, as a string
|
|
38
|
+
def height
|
|
39
|
+
assert_exists
|
|
40
|
+
@object.getHeight
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def disabled?
|
|
44
|
+
assert_exists
|
|
45
|
+
raise NotImplementedError
|
|
46
|
+
end
|
|
47
|
+
alias_method :disabled, :disabled?
|
|
48
|
+
|
|
49
|
+
def loaded?
|
|
50
|
+
assert_exists
|
|
51
|
+
begin
|
|
52
|
+
@object.getImageReader
|
|
53
|
+
return true
|
|
54
|
+
rescue
|
|
55
|
+
return false
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
alias_method :hasLoaded?, :loaded?
|
|
59
|
+
alias_method :has_loaded?, :loaded?
|
|
60
|
+
|
|
61
|
+
def save(filename)
|
|
62
|
+
assert_exists
|
|
63
|
+
image_reader = @object.getImageReader
|
|
64
|
+
file = java.io.File.new(filename)
|
|
65
|
+
buffered_image = image_reader.read(0);
|
|
66
|
+
return javax.imageio.ImageIO.write(buffered_image, image_reader.getFormatName(), file);
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Celerity
|
|
2
|
+
class Link < Element
|
|
3
|
+
TAGS = ['a']
|
|
4
|
+
ATTRIBUTES = BASE_ATTRIBUTES | [:charset, :type, :name, :href, :hreflang, :target, :rel, :rev, :accesskey, :shape, :coords, :tabindex, :onfocus, :onblur]
|
|
5
|
+
|
|
6
|
+
def click
|
|
7
|
+
assert_exists
|
|
8
|
+
@container.update_page @object.click
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Celerity
|
|
2
|
+
# This class is the class for radio buttons and check boxes.
|
|
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
|
+
#
|
|
8
|
+
class RadioCheckCommon < InputElement
|
|
9
|
+
def locate
|
|
10
|
+
@object = @container.locate_input_element(self, @how, @what, @value)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def initialize(container, how, what, type, value = nil)
|
|
14
|
+
@type = type
|
|
15
|
+
@value = value
|
|
16
|
+
super(container, how, what)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def set?
|
|
20
|
+
assert_exists
|
|
21
|
+
@object.isChecked
|
|
22
|
+
end
|
|
23
|
+
alias_method :is_set?, :set?
|
|
24
|
+
alias_method :isSet?, :set?
|
|
25
|
+
alias_method :get_state, :set?
|
|
26
|
+
alias_method :getState, :set?
|
|
27
|
+
alias_method :checked?, :set?
|
|
28
|
+
|
|
29
|
+
def clear
|
|
30
|
+
set(false)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# This class is the celerity representation of a radio button.
|
|
35
|
+
class Radio < RadioCheckCommon
|
|
36
|
+
TAGS = [Identifier.new('input', :type => %w(radio))]
|
|
37
|
+
|
|
38
|
+
def set(value = true)
|
|
39
|
+
assert_exists
|
|
40
|
+
assert_enabled
|
|
41
|
+
@container.update_page(value ? @object.click : @object.setChecked(value))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# This class is the celerity representation of a check box.
|
|
47
|
+
class CheckBox < RadioCheckCommon
|
|
48
|
+
TAGS = [Identifier.new('input', :type => %w(checkbox))]
|
|
49
|
+
|
|
50
|
+
def set(value = true)
|
|
51
|
+
assert_exists
|
|
52
|
+
assert_enabled
|
|
53
|
+
if (value && !set?) || (!value && set?)
|
|
54
|
+
@container.update_page(@object.click)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|