celerity_thingista 0.9.2
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/.document +5 -0
- data/.gitignore +9 -0
- data/.gitmodules +3 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/LICENSE +278 -0
- data/README.rdoc +84 -0
- data/Rakefile +15 -0
- data/benchmark/bm_2000_spans.rb +48 -0
- data/benchmark/bm_digg.rb +26 -0
- data/benchmark/bm_google_images.rb +36 -0
- data/benchmark/bm_input_locator.rb +69 -0
- data/benchmark/bm_text_input.rb +19 -0
- data/benchmark/loader.rb +14 -0
- data/celerity.gemspec +26 -0
- data/lib/celerity.rb +75 -0
- data/lib/celerity/browser.rb +924 -0
- data/lib/celerity/clickable_element.rb +73 -0
- data/lib/celerity/collections.rb +164 -0
- data/lib/celerity/container.rb +802 -0
- data/lib/celerity/default_viewer.rb +14 -0
- data/lib/celerity/disabled_element.rb +40 -0
- data/lib/celerity/element.rb +314 -0
- data/lib/celerity/element_collection.rb +115 -0
- data/lib/celerity/element_locator.rb +164 -0
- data/lib/celerity/elements/button.rb +54 -0
- data/lib/celerity/elements/file_field.rb +29 -0
- data/lib/celerity/elements/form.rb +22 -0
- data/lib/celerity/elements/frame.rb +86 -0
- data/lib/celerity/elements/image.rb +89 -0
- data/lib/celerity/elements/label.rb +16 -0
- data/lib/celerity/elements/link.rb +43 -0
- data/lib/celerity/elements/meta.rb +14 -0
- data/lib/celerity/elements/non_control_elements.rb +124 -0
- data/lib/celerity/elements/option.rb +38 -0
- data/lib/celerity/elements/radio_check.rb +114 -0
- data/lib/celerity/elements/select_list.rb +146 -0
- data/lib/celerity/elements/table.rb +154 -0
- data/lib/celerity/elements/table_cell.rb +36 -0
- data/lib/celerity/elements/table_elements.rb +42 -0
- data/lib/celerity/elements/table_row.rb +54 -0
- data/lib/celerity/elements/text_field.rb +168 -0
- data/lib/celerity/exception.rb +83 -0
- data/lib/celerity/htmlunit.rb +64 -0
- data/lib/celerity/htmlunit/commons-codec-1.7.jar +0 -0
- data/lib/celerity/htmlunit/commons-collections-3.2.1.jar +0 -0
- data/lib/celerity/htmlunit/commons-io-2.4.jar +0 -0
- data/lib/celerity/htmlunit/commons-lang3-3.1.jar +0 -0
- data/lib/celerity/htmlunit/commons-logging-1.1.1.jar +0 -0
- data/lib/celerity/htmlunit/cssparser-0.9.9.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-2.12.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-core-js-2.12.jar +0 -0
- data/lib/celerity/htmlunit/httpclient-4.2.3.jar +0 -0
- data/lib/celerity/htmlunit/httpcore-4.2.2.jar +0 -0
- data/lib/celerity/htmlunit/httpmime-4.2.3.jar +0 -0
- data/lib/celerity/htmlunit/jetty-http-8.1.9.v20130131.jar +0 -0
- data/lib/celerity/htmlunit/jetty-io-8.1.9.v20130131.jar +0 -0
- data/lib/celerity/htmlunit/jetty-util-8.1.9.v20130131.jar +0 -0
- data/lib/celerity/htmlunit/jetty-websocket-8.1.9.v20130131.jar +0 -0
- data/lib/celerity/htmlunit/nekohtml-1.9.18.jar +0 -0
- data/lib/celerity/htmlunit/sac-1.3.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/xercesImpl-2.10.0.jar +0 -0
- data/lib/celerity/htmlunit/xml-apis-1.4.01.jar +0 -0
- data/lib/celerity/identifier.rb +28 -0
- data/lib/celerity/ignoring_web_connection.rb +15 -0
- data/lib/celerity/input_element.rb +25 -0
- data/lib/celerity/javascript_debugger.rb +32 -0
- data/lib/celerity/listener.rb +143 -0
- data/lib/celerity/resources/no_viewer.png +0 -0
- data/lib/celerity/short_inspect.rb +29 -0
- data/lib/celerity/util.rb +129 -0
- data/lib/celerity/version.rb +3 -0
- data/lib/celerity/viewer_connection.rb +89 -0
- data/lib/celerity/watir_compatibility.rb +70 -0
- data/lib/celerity/xpath_support.rb +50 -0
- data/spec/browser_authentication_spec.rb +16 -0
- data/spec/browser_spec.rb +439 -0
- data/spec/button_spec.rb +24 -0
- data/spec/clickable_element_spec.rb +39 -0
- data/spec/default_viewer_spec.rb +23 -0
- data/spec/element_spec.rb +77 -0
- data/spec/filefield_spec.rb +18 -0
- data/spec/htmlunit_spec.rb +63 -0
- data/spec/implementation.rb +7 -0
- data/spec/index_offset_spec.rb +24 -0
- data/spec/link_spec.rb +16 -0
- data/spec/listener_spec.rb +142 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/table_spec.rb +41 -0
- data/spec/watir_compatibility_spec.rb +32 -0
- data/tasks/benchmark.rake +4 -0
- data/tasks/check.rake +24 -0
- data/tasks/clean.rake +3 -0
- data/tasks/fix.rake +25 -0
- data/tasks/jar.rake +55 -0
- data/tasks/rdoc.rake +4 -0
- data/tasks/snapshot.rake +25 -0
- data/tasks/spec.rake +27 -0
- data/tasks/website.rake +10 -0
- data/tasks/yard.rake +16 -0
- data/website/benchmarks.html +237 -0
- data/website/css/color.css +153 -0
- data/website/css/hacks.css +3 -0
- data/website/css/layout.css +179 -0
- data/website/css/screen.css +5 -0
- data/website/css/textmate.css +226 -0
- data/website/css/typography.css +72 -0
- data/website/gfx/body_bg.gif +0 -0
- data/website/gfx/button_bg.jpg +0 -0
- data/website/gfx/header_bg.jpg +0 -0
- data/website/gfx/header_left.jpg +0 -0
- data/website/gfx/header_right.jpg +0 -0
- data/website/gfx/nav_bg.jpg +0 -0
- data/website/index.html +125 -0
- data/website/yard/index.html +1 -0
- metadata +246 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Celerity
|
|
2
|
+
class Link < Element
|
|
3
|
+
include ClickableElement
|
|
4
|
+
|
|
5
|
+
TAGS = [ Identifier.new('a') ]
|
|
6
|
+
ATTRIBUTES = BASE_ATTRIBUTES | [
|
|
7
|
+
:accesskey,
|
|
8
|
+
:charset,
|
|
9
|
+
:coords,
|
|
10
|
+
:href,
|
|
11
|
+
:hreflang,
|
|
12
|
+
:name,
|
|
13
|
+
:onblur,
|
|
14
|
+
:onfocus,
|
|
15
|
+
:rel,
|
|
16
|
+
:rev,
|
|
17
|
+
:shape,
|
|
18
|
+
:tabindex,
|
|
19
|
+
:target,
|
|
20
|
+
:type,
|
|
21
|
+
]
|
|
22
|
+
DEFAULT_HOW = :href
|
|
23
|
+
|
|
24
|
+
#
|
|
25
|
+
# Returns the absolute URL for this link (Celerity-specific)
|
|
26
|
+
#
|
|
27
|
+
# (Watir/IE does this for href(), but we don't want that.)
|
|
28
|
+
#
|
|
29
|
+
|
|
30
|
+
def absolute_url
|
|
31
|
+
assert_exists
|
|
32
|
+
href = @object.getAttribute('href')
|
|
33
|
+
|
|
34
|
+
unless href.empty? || URI.parse(href).absolute?
|
|
35
|
+
href = URI.join(browser.url, href).to_s
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
href
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
end # Link
|
|
43
|
+
end # Celerity
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
module Celerity
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# Superclass for for Span, Pre, Div, H1, ...
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
class NonControlElement < Element
|
|
8
|
+
include Exception
|
|
9
|
+
include ClickableElement
|
|
10
|
+
|
|
11
|
+
ATTRIBUTES = BASE_ATTRIBUTES
|
|
12
|
+
DEFAULT_HOW = :id
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
#
|
|
16
|
+
#--
|
|
17
|
+
# classes ordered alphabetically
|
|
18
|
+
#++
|
|
19
|
+
#
|
|
20
|
+
|
|
21
|
+
class Area < NonControlElement
|
|
22
|
+
ATTRIBUTES = ATTRIBUTES | [
|
|
23
|
+
:accesskey,
|
|
24
|
+
:alt,
|
|
25
|
+
:coords,
|
|
26
|
+
:href,
|
|
27
|
+
:nohref,
|
|
28
|
+
:onblur,
|
|
29
|
+
:onfocus,
|
|
30
|
+
:shape,
|
|
31
|
+
:tabindex,
|
|
32
|
+
]
|
|
33
|
+
TAGS = [ Identifier.new('area') ]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class Dd < NonControlElement
|
|
37
|
+
TAGS = [ Identifier.new('dd')]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class Del < NonControlElement
|
|
41
|
+
TAGS = [ Identifier.new('del')]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
class Div < NonControlElement
|
|
45
|
+
TAGS = [ Identifier.new('div')]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
class Dl < NonControlElement
|
|
49
|
+
TAGS = [ Identifier.new('dl')]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class Dt < NonControlElement
|
|
53
|
+
TAGS = [ Identifier.new('dt')]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
class Em < NonControlElement
|
|
57
|
+
TAGS = [ Identifier.new('em')]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
class H1 < NonControlElement
|
|
61
|
+
TAGS = [ Identifier.new('h1') ]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
class H2 < NonControlElement
|
|
65
|
+
TAGS = [ Identifier.new('h2') ]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
class H3 < NonControlElement
|
|
69
|
+
TAGS = [ Identifier.new('h3') ]
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
class H4 < NonControlElement
|
|
73
|
+
TAGS = [ Identifier.new('h4') ]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
class H5 < NonControlElement
|
|
77
|
+
TAGS = [ Identifier.new('h5') ]
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
class H6 < NonControlElement
|
|
81
|
+
TAGS = [ Identifier.new('h6') ]
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
class Ins < NonControlElement
|
|
85
|
+
TAGS = [ Identifier.new('ins') ]
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
class Li < NonControlElement
|
|
89
|
+
TAGS = [ Identifier.new('li') ]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
class Map < NonControlElement
|
|
93
|
+
TAGS = [ Identifier.new('map') ]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
class Ol < NonControlElement
|
|
97
|
+
TAGS = [ Identifier.new('ol') ]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
class P < NonControlElement
|
|
101
|
+
TAGS = [ Identifier.new('p') ]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
class Pre < NonControlElement
|
|
105
|
+
TAGS = [ Identifier.new('pre')]
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
class Span < NonControlElement
|
|
109
|
+
TAGS = [ Identifier.new('span') ]
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
class Strong < NonControlElement
|
|
113
|
+
TAGS = [ Identifier.new('strong') ]
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# class Title < NonControlElement
|
|
117
|
+
# TAGS = [ Identifier.new('title') ]
|
|
118
|
+
# end
|
|
119
|
+
|
|
120
|
+
class Ul < NonControlElement
|
|
121
|
+
TAGS = [ Identifier.new('ul') ]
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Celerity
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# Represents an option in a select list.
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
class Option < Element
|
|
8
|
+
include ClickableElement
|
|
9
|
+
include DisabledElement
|
|
10
|
+
|
|
11
|
+
TAGS = [ Identifier.new('option') ]
|
|
12
|
+
ATTRIBUTES = BASE_ATTRIBUTES | [
|
|
13
|
+
:disabled,
|
|
14
|
+
:label,
|
|
15
|
+
:selected,
|
|
16
|
+
:value,
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
DEFAULT_HOW = :text
|
|
20
|
+
|
|
21
|
+
alias_method :select, :click
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
# Is this option selected?
|
|
25
|
+
#
|
|
26
|
+
|
|
27
|
+
def selected?
|
|
28
|
+
assert_exists
|
|
29
|
+
@object.isSelected
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def label
|
|
33
|
+
# overrides Container#label
|
|
34
|
+
assert_exists
|
|
35
|
+
@object.getLabelAttribute
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
module Celerity
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# Common superclass for radios and check boxes.
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
class RadioCheckCommon < InputElement
|
|
8
|
+
DEFAULT_HOW = :name
|
|
9
|
+
|
|
10
|
+
#
|
|
11
|
+
# Can optionally take a value parameter as a third arg, so we override initialize
|
|
12
|
+
#
|
|
13
|
+
|
|
14
|
+
def initialize(container, type, *args)
|
|
15
|
+
@type = type
|
|
16
|
+
case args.size
|
|
17
|
+
when 2
|
|
18
|
+
super(container, args[0] => args[1])
|
|
19
|
+
when 3
|
|
20
|
+
super(container, args[0] => args[1], :value => args[2])
|
|
21
|
+
else
|
|
22
|
+
super(container, *args)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#
|
|
27
|
+
# returns true if the element is checked
|
|
28
|
+
# @return [true, false]
|
|
29
|
+
#
|
|
30
|
+
|
|
31
|
+
def set?
|
|
32
|
+
assert_exists
|
|
33
|
+
@object.isChecked
|
|
34
|
+
end
|
|
35
|
+
alias_method :checked?, :set?
|
|
36
|
+
|
|
37
|
+
#
|
|
38
|
+
# Unset this element.
|
|
39
|
+
#
|
|
40
|
+
|
|
41
|
+
def clear
|
|
42
|
+
set(false)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
#
|
|
47
|
+
# This class is the representation of a radio button.
|
|
48
|
+
#
|
|
49
|
+
|
|
50
|
+
class Radio < RadioCheckCommon
|
|
51
|
+
TAGS = [Identifier.new('input', :type => %w[radio])]
|
|
52
|
+
|
|
53
|
+
#
|
|
54
|
+
# @api private
|
|
55
|
+
#
|
|
56
|
+
|
|
57
|
+
def initialize(container, *args)
|
|
58
|
+
super(container, %w[radio], *args)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
#
|
|
62
|
+
# Set the radio button to the given value.
|
|
63
|
+
#
|
|
64
|
+
# radio.set? #=> false
|
|
65
|
+
# radio.set
|
|
66
|
+
# radio.set? #=> true
|
|
67
|
+
# radio.set(false)
|
|
68
|
+
# radio.set? #=> false
|
|
69
|
+
#
|
|
70
|
+
|
|
71
|
+
def set(value = true)
|
|
72
|
+
assert_exists
|
|
73
|
+
assert_enabled
|
|
74
|
+
value ? @object.click : @object.setChecked(value)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
#
|
|
80
|
+
# This class is the representation of a check box.
|
|
81
|
+
#
|
|
82
|
+
|
|
83
|
+
class CheckBox < RadioCheckCommon
|
|
84
|
+
TAGS = [Identifier.new('input', :type => %w[checkbox])]
|
|
85
|
+
|
|
86
|
+
#
|
|
87
|
+
# @api private
|
|
88
|
+
#
|
|
89
|
+
|
|
90
|
+
def initialize(container, *args)
|
|
91
|
+
super(container, %w[checkbox], *args)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
#
|
|
95
|
+
# Set the checkbox to the given value.
|
|
96
|
+
#
|
|
97
|
+
# checkbox.set? #=> false
|
|
98
|
+
# checkbox.set
|
|
99
|
+
# checkbox.set? #=> true
|
|
100
|
+
# checkbox.set(false)
|
|
101
|
+
# checkbox.set? #=> false
|
|
102
|
+
#
|
|
103
|
+
|
|
104
|
+
def set(value = true)
|
|
105
|
+
assert_exists
|
|
106
|
+
assert_enabled
|
|
107
|
+
|
|
108
|
+
if (value && !set?) || (!value && set?)
|
|
109
|
+
@object.click
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
end
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
module Celerity
|
|
2
|
+
class SelectList < InputElement
|
|
3
|
+
TAGS = [ Identifier.new('select') ]
|
|
4
|
+
DEFAULT_HOW = :name
|
|
5
|
+
|
|
6
|
+
#
|
|
7
|
+
# @return [Array<String>] An array of strings representing the text value of the select list's options.
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
def options
|
|
11
|
+
assert_exists
|
|
12
|
+
@object.getOptions.map { |e| e.asText.empty? ? e.getLabelAttribute : e.asText }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
#
|
|
16
|
+
# @return [Array<String>] An array of strings representing the text value of the currently selected options.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
def selected_options
|
|
20
|
+
assert_exists
|
|
21
|
+
@object.getSelectedOptions.map { |e| e.asText.empty? ? e.getLabelAttribute : e.asText }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#
|
|
25
|
+
# Clear all selected options
|
|
26
|
+
#
|
|
27
|
+
|
|
28
|
+
def clear
|
|
29
|
+
@object.getSelectedOptions.each { |e| e.setSelected(false) } if multiple?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
#
|
|
33
|
+
# Select the option(s) whose text or label matches the given string.
|
|
34
|
+
# If several options match the value given, all will be selected.
|
|
35
|
+
#
|
|
36
|
+
# @param [String, Regexp] value A value.
|
|
37
|
+
# @raise [Celerity::Exception::NoValueFoundException] if the value does not exist.
|
|
38
|
+
# @return [String] The option selected. If multiple options match, returns the first match
|
|
39
|
+
#
|
|
40
|
+
#
|
|
41
|
+
|
|
42
|
+
def select(value)
|
|
43
|
+
assert_exists
|
|
44
|
+
|
|
45
|
+
selected = nil
|
|
46
|
+
@object.getOptions.select do |option|
|
|
47
|
+
next unless matches_option?(option, value)
|
|
48
|
+
|
|
49
|
+
selected ||= option.asText
|
|
50
|
+
option.click unless option.isSelected
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
unless selected
|
|
54
|
+
raise NoValueFoundException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
selected
|
|
58
|
+
end
|
|
59
|
+
alias_method :set, :select
|
|
60
|
+
|
|
61
|
+
#
|
|
62
|
+
# Selects the option(s) whose value attribute matches the given string.
|
|
63
|
+
# @param [String, Regexp] value A value.
|
|
64
|
+
# @raise [Celerity::Exception::NoValueFoundException] if the value does not exist.
|
|
65
|
+
# @return [String] The option selected. If multiple options match, returns the first match
|
|
66
|
+
#
|
|
67
|
+
|
|
68
|
+
def select_value(value)
|
|
69
|
+
assert_exists
|
|
70
|
+
selected = @object.getOptions.map { |e| e.click if Util.matches?(e.getValueAttribute, value) }.compact.first
|
|
71
|
+
|
|
72
|
+
unless selected
|
|
73
|
+
raise NoValueFoundException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
selected.asText
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
#
|
|
80
|
+
# Returns true if the select list has one or more options matching the given value.
|
|
81
|
+
#
|
|
82
|
+
# @param [String, Regexp] value A value.
|
|
83
|
+
# @return [true, false]
|
|
84
|
+
#
|
|
85
|
+
|
|
86
|
+
def include?(value)
|
|
87
|
+
assert_exists
|
|
88
|
+
!!@object.getOptions.find { |e| matches_option?(e, value) }
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
#
|
|
92
|
+
# Returns true if any of the selected options match the given value.
|
|
93
|
+
#
|
|
94
|
+
# @param [String, Regexp] value A value.
|
|
95
|
+
# @raise [Celerity::Exception::UnknownObjectException] if the value does not exist.
|
|
96
|
+
# @return [true, false]
|
|
97
|
+
#
|
|
98
|
+
|
|
99
|
+
def selected?(value)
|
|
100
|
+
assert_exists
|
|
101
|
+
raise UnknownObjectException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}" unless include?(value)
|
|
102
|
+
!!@object.getOptions.find { |e| matches_option?(e, value) && e.isSelected }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
#
|
|
106
|
+
# Returns 'select-multiple' if the select list has the 'multiple' attribute,
|
|
107
|
+
# defined, otherwise 'select-one'.
|
|
108
|
+
#
|
|
109
|
+
# @return [String]
|
|
110
|
+
#
|
|
111
|
+
|
|
112
|
+
def type
|
|
113
|
+
assert_exists
|
|
114
|
+
'select-' + (@object.hasAttribute('multiple') ? 'multiple' : 'one')
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
#
|
|
118
|
+
# Returns true if the select list supports multiple selections
|
|
119
|
+
#
|
|
120
|
+
|
|
121
|
+
def multiple?
|
|
122
|
+
type == "select-multiple"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
#
|
|
126
|
+
# Returns the value of the first selected option in the select list.
|
|
127
|
+
# Returns nil if no option is selected.
|
|
128
|
+
#
|
|
129
|
+
# @return [String, nil]
|
|
130
|
+
#
|
|
131
|
+
|
|
132
|
+
def value
|
|
133
|
+
assert_exists
|
|
134
|
+
if (option = @object.getSelectedOptions.to_a.first)
|
|
135
|
+
option.getValueAttribute
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
private
|
|
140
|
+
|
|
141
|
+
def matches_option?(option, value)
|
|
142
|
+
Util.matches?(option.asText, value) || (option.hasAttribute("label") && Util.matches?(option.getLabelAttribute, value))
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
end # SelectList
|
|
146
|
+
end # Celerity
|