jarib-celerity 0.0.6.7 → 0.0.6.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +4 -0
- data/lib/celerity/browser.rb +36 -21
- data/lib/celerity/clickable_element.rb +16 -1
- data/lib/celerity/collections.rb +2 -2
- data/lib/celerity/default_viewer.rb +1 -1
- data/lib/celerity/disabled_element.rb +5 -5
- data/lib/celerity/element.rb +25 -21
- data/lib/celerity/element_collection.rb +14 -14
- data/lib/celerity/element_locator.rb +9 -9
- data/lib/celerity/elements/button.rb +9 -9
- data/lib/celerity/elements/file_field.rb +3 -3
- data/lib/celerity/elements/form.rb +5 -5
- data/lib/celerity/elements/frame.rb +2 -2
- data/lib/celerity/elements/image.rb +2 -2
- data/lib/celerity/elements/label.rb +1 -1
- data/lib/celerity/elements/link.rb +4 -4
- data/lib/celerity/elements/non_control_elements.rb +3 -3
- data/lib/celerity/elements/option.rb +5 -5
- data/lib/celerity/elements/radio_check.rb +16 -16
- data/lib/celerity/elements/select_list.rb +16 -16
- data/lib/celerity/elements/table.rb +15 -12
- data/lib/celerity/elements/table_row.rb +3 -3
- data/lib/celerity/elements/text_field.rb +22 -25
- data/lib/celerity/exception.rb +5 -5
- data/lib/celerity/htmlunit.rb +8 -2
- data/lib/celerity/htmlunit/htmlunit-2.6-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/{nekohtml-1.9.12.jar → nekohtml-1.9.13-20090507.082850-2.jar} +0 -0
- data/lib/celerity/listener.rb +17 -17
- data/lib/celerity/util.rb +1 -1
- data/lib/celerity/version.rb +2 -2
- data/lib/celerity/watir_compatibility.rb +2 -2
- metadata +7 -9
- data/lib/celerity/extra/method_generator.rb +0 -170
- data/lib/celerity/htmlunit/htmlunit-2.5.jar +0 -0
@@ -2,8 +2,8 @@ module Celerity
|
|
2
2
|
|
3
3
|
#
|
4
4
|
# Used internally to locate elements on the page.
|
5
|
-
#
|
6
|
-
|
5
|
+
#
|
6
|
+
|
7
7
|
class ElementLocator
|
8
8
|
include Celerity::Exception
|
9
9
|
attr_accessor :idents
|
@@ -35,8 +35,6 @@ module Celerity
|
|
35
35
|
raise ArgumentError, "expected an HtmlUnit::Html::HtmlElement subclass, got #{what.inspect}:#{what.class}"
|
36
36
|
end
|
37
37
|
return what
|
38
|
-
when :id
|
39
|
-
return find_by_id(what)
|
40
38
|
when :xpath
|
41
39
|
return find_by_xpath(what)
|
42
40
|
when :label
|
@@ -49,7 +47,9 @@ module Celerity
|
|
49
47
|
how = :text
|
50
48
|
end
|
51
49
|
|
52
|
-
if
|
50
|
+
if how == :id && conditions.size == 1
|
51
|
+
return find_by_id(what)
|
52
|
+
elsif @attributes.include?(how = how.to_sym)
|
53
53
|
attributes[how] << what
|
54
54
|
elsif how == :index
|
55
55
|
index = what.to_i - INDEX_OFFSET
|
@@ -106,12 +106,12 @@ module Celerity
|
|
106
106
|
find_by_id obj.getForAttribute
|
107
107
|
end
|
108
108
|
|
109
|
-
def elements_by_idents(idents =
|
110
|
-
get_by_idents(:select, idents
|
109
|
+
def elements_by_idents(idents = @idents)
|
110
|
+
get_by_idents(:select, idents)
|
111
111
|
end
|
112
112
|
|
113
|
-
def element_by_idents(idents =
|
114
|
-
get_by_idents(:find, idents
|
113
|
+
def element_by_idents(idents = @idents)
|
114
|
+
get_by_idents(:find, idents)
|
115
115
|
end
|
116
116
|
|
117
117
|
private
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Celerity
|
2
|
-
|
2
|
+
|
3
3
|
#
|
4
4
|
# Input: Button
|
5
5
|
#
|
6
6
|
# Class representing button elements
|
7
7
|
#
|
8
|
-
|
8
|
+
|
9
9
|
class Button < InputElement
|
10
10
|
TAGS = [ Identifier.new('button'),
|
11
11
|
Identifier.new('input', :type => %w[submit reset image button]) ]
|
12
|
-
|
12
|
+
|
13
13
|
# Attribute list is a little weird due to this class covering both <button>
|
14
14
|
# and <input type="submit|reset|image|button" />
|
15
15
|
ATTRIBUTES = BASE_ATTRIBUTES | [:type, :disabled, :tabindex, :accesskey, :onfocus, :onblur] | [:src, :usemap, :ismap]
|
@@ -18,19 +18,19 @@ module Celerity
|
|
18
18
|
#
|
19
19
|
# @api private
|
20
20
|
#
|
21
|
-
|
21
|
+
|
22
22
|
def locate
|
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
|
-
|
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
|
+
|
26
26
|
if (val = @conditions[:value])
|
27
27
|
button_ident = Identifier.new('button')
|
28
28
|
button_ident.text = val
|
29
29
|
input_ident = Identifier.new('input', :type => %w[submit reset image button], :value => [val])
|
30
|
-
|
30
|
+
|
31
31
|
locator = ElementLocator.new(@container, self.class)
|
32
32
|
locator.idents = [button_ident, input_ident]
|
33
|
-
|
33
|
+
|
34
34
|
conditions = @conditions.dup
|
35
35
|
conditions.delete(:value)
|
36
36
|
@object = locator.find_by_conditions(conditions)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Celerity
|
2
|
-
|
2
|
+
|
3
3
|
#
|
4
4
|
# For fields that accept file uploads
|
5
5
|
#
|
@@ -10,7 +10,7 @@ module Celerity
|
|
10
10
|
|
11
11
|
#
|
12
12
|
# Set the file field to the given path
|
13
|
-
#
|
13
|
+
#
|
14
14
|
|
15
15
|
def set(path)
|
16
16
|
assert_exists
|
@@ -20,6 +20,6 @@ module Celerity
|
|
20
20
|
@object.setContentType(Celerity::Util.content_type_for(path))
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
end # FileField
|
25
25
|
end # Celerity
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module Celerity
|
2
2
|
class Form < Element
|
3
3
|
include Container
|
4
|
-
|
4
|
+
|
5
5
|
TAGS = [Identifier.new('form')]
|
6
|
-
|
6
|
+
|
7
7
|
# HTML 4.01 Transitional DTD
|
8
8
|
ATTRIBUTES = BASE_ATTRIBUTES | [:action, :method, :enctype, :accept, :name, :onsubmit, :onreset, :target, :'accept-charset']
|
9
9
|
DEFAULT_HOW = :name
|
10
10
|
|
11
11
|
#
|
12
12
|
# Submits the form.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# This method should be avoided - invoke the user interface element that triggers the submit instead.
|
15
|
-
#
|
16
|
-
|
15
|
+
#
|
16
|
+
|
17
17
|
def submit
|
18
18
|
assert_exists
|
19
19
|
@container.update_page @object.submit(nil)
|
@@ -10,7 +10,7 @@ module Celerity
|
|
10
10
|
#
|
11
11
|
# Override the default locate to handle frame and inline frames.
|
12
12
|
# @api private
|
13
|
-
#
|
13
|
+
#
|
14
14
|
|
15
15
|
def locate
|
16
16
|
super
|
@@ -22,7 +22,7 @@ module Celerity
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
#
|
27
27
|
# Override assert_exists to raise UnknownFrameException (for Watir compatibility)
|
28
28
|
# @api private
|
@@ -4,7 +4,7 @@ module Celerity
|
|
4
4
|
include ClickableElement
|
5
5
|
|
6
6
|
TAGS = [ Identifier.new('img') ]
|
7
|
-
|
7
|
+
|
8
8
|
ATTRIBUTES = BASE_ATTRIBUTES | [:src, :alt, :longdesc, :name, :height, :width, :usemap, :ismap, :align, :border, :hspace, :vspace]
|
9
9
|
DEFAULT_HOW = :src
|
10
10
|
|
@@ -71,6 +71,6 @@ module Celerity
|
|
71
71
|
buffered_image = image_reader.read(0);
|
72
72
|
javax.imageio.ImageIO.write(buffered_image, image_reader.getFormatName(), file);
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
end # Image
|
76
76
|
end # Celerity
|
@@ -7,12 +7,12 @@ module Celerity
|
|
7
7
|
:target, :rel, :rev, :accesskey, :shape,
|
8
8
|
:coords, :tabindex, :onfocus, :onblur]
|
9
9
|
DEFAULT_HOW = :href
|
10
|
-
|
10
|
+
|
11
11
|
#
|
12
12
|
# Returns the absolute URL for this link (Celerity-specific)
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# (Watir/IE does this for href(), but we don't want that.)
|
15
|
-
#
|
15
|
+
#
|
16
16
|
|
17
17
|
def absolute_url
|
18
18
|
assert_exists
|
@@ -25,6 +25,6 @@ module Celerity
|
|
25
25
|
href
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
|
29
29
|
end # Link
|
30
30
|
end # Celerity
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Celerity
|
2
|
-
|
2
|
+
|
3
3
|
#
|
4
4
|
# Superclass for for Span, Pre, Div, H1, ...
|
5
5
|
#
|
6
|
-
|
6
|
+
|
7
7
|
class NonControlElement < Element
|
8
8
|
include Exception
|
9
9
|
include ClickableElement
|
@@ -90,7 +90,7 @@ module Celerity
|
|
90
90
|
class Span < NonControlElement
|
91
91
|
TAGS = [ Identifier.new('span') ]
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
class Strong < NonControlElement
|
95
95
|
TAGS = [ Identifier.new('strong') ]
|
96
96
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Celerity
|
2
|
-
|
2
|
+
|
3
3
|
#
|
4
4
|
# Represents an option in a select list.
|
5
5
|
#
|
@@ -14,15 +14,15 @@ module Celerity
|
|
14
14
|
|
15
15
|
alias_method :select, :click
|
16
16
|
|
17
|
-
#
|
17
|
+
#
|
18
18
|
# Is this option selected?
|
19
|
-
#
|
20
|
-
|
19
|
+
#
|
20
|
+
|
21
21
|
def selected?
|
22
22
|
assert_exists
|
23
23
|
@object.isSelected
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def label
|
27
27
|
# overrides Container#label
|
28
28
|
assert_exists
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module Celerity
|
2
|
-
|
2
|
+
|
3
3
|
#
|
4
4
|
# Common superclass for radios and check boxes.
|
5
5
|
#
|
6
|
-
|
6
|
+
|
7
7
|
class RadioCheckCommon < InputElement
|
8
8
|
DEFAULT_HOW = :name
|
9
|
-
|
9
|
+
|
10
10
|
#
|
11
|
-
# Can optionally take a value parameter as a third arg, so we override initialize
|
11
|
+
# Can optionally take a value parameter as a third arg, so we override initialize
|
12
12
|
#
|
13
|
-
|
13
|
+
|
14
14
|
def initialize(container, type, *args)
|
15
15
|
@type = type
|
16
16
|
case args.size
|
@@ -22,12 +22,12 @@ module Celerity
|
|
22
22
|
super(container, *args)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
#
|
27
27
|
# returns true if the element is checked
|
28
28
|
# @return [true, false]
|
29
29
|
#
|
30
|
-
|
30
|
+
|
31
31
|
def set?
|
32
32
|
assert_exists
|
33
33
|
@object.isChecked
|
@@ -37,7 +37,7 @@ module Celerity
|
|
37
37
|
#
|
38
38
|
# Unset this element.
|
39
39
|
#
|
40
|
-
|
40
|
+
|
41
41
|
def clear
|
42
42
|
set(false)
|
43
43
|
end
|
@@ -46,14 +46,14 @@ module Celerity
|
|
46
46
|
#
|
47
47
|
# This class is the representation of a radio button.
|
48
48
|
#
|
49
|
-
|
49
|
+
|
50
50
|
class Radio < RadioCheckCommon
|
51
51
|
TAGS = [Identifier.new('input', :type => %w[radio])]
|
52
|
-
|
52
|
+
|
53
53
|
#
|
54
54
|
# @api private
|
55
55
|
#
|
56
|
-
|
56
|
+
|
57
57
|
def initialize(container, *args)
|
58
58
|
super(container, %w[radio], *args)
|
59
59
|
end
|
@@ -67,7 +67,7 @@ module Celerity
|
|
67
67
|
# radio.set(false)
|
68
68
|
# radio.set? #=> false
|
69
69
|
#
|
70
|
-
|
70
|
+
|
71
71
|
def set(value = true)
|
72
72
|
assert_exists
|
73
73
|
assert_enabled
|
@@ -75,18 +75,18 @@ module Celerity
|
|
75
75
|
end
|
76
76
|
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
#
|
80
80
|
# This class is the representation of a check box.
|
81
81
|
#
|
82
|
-
|
82
|
+
|
83
83
|
class CheckBox < RadioCheckCommon
|
84
84
|
TAGS = [Identifier.new('input', :type => %w[checkbox])]
|
85
85
|
|
86
86
|
#
|
87
87
|
# @api private
|
88
88
|
#
|
89
|
-
|
89
|
+
|
90
90
|
def initialize(container, *args)
|
91
91
|
super(container, %w[checkbox], *args)
|
92
92
|
end
|
@@ -100,7 +100,7 @@ module Celerity
|
|
100
100
|
# checkbox.set(false)
|
101
101
|
# checkbox.set? #=> false
|
102
102
|
#
|
103
|
-
|
103
|
+
|
104
104
|
def set(value = true)
|
105
105
|
assert_exists
|
106
106
|
assert_enabled
|
@@ -6,27 +6,27 @@ module Celerity
|
|
6
6
|
#
|
7
7
|
# @return [Array<String>] An array of strings representing the text value of the select list's options.
|
8
8
|
#
|
9
|
-
|
9
|
+
|
10
10
|
def options
|
11
11
|
assert_exists
|
12
12
|
@object.getOptions.map do |e|
|
13
13
|
e.asText.empty? ? e.getLabelAttribute : e.asText
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
#
|
18
18
|
# @return [Array<String>] An array of strings representing the text value of the currently selected options.
|
19
19
|
#
|
20
|
-
|
20
|
+
|
21
21
|
def selected_options
|
22
22
|
assert_exists
|
23
23
|
@object.getSelectedOptions.map { |e| e.asText.empty? ? e.getLabelAttribute : e.asText }
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
#
|
27
27
|
# Clear all selected options
|
28
28
|
#
|
29
|
-
|
29
|
+
|
30
30
|
def clear
|
31
31
|
# assert_exists called by SelectList#type here
|
32
32
|
# TODO: should update page for each option changed?
|
@@ -40,21 +40,21 @@ module Celerity
|
|
40
40
|
# @param [String, Regexp] value A value.
|
41
41
|
# @raise [Celerity::Exception::NoValueFoundException] if the value does not exist.
|
42
42
|
# @return [String, nil] The option selected. If multiple options match, returns the first match
|
43
|
-
#
|
44
43
|
#
|
45
|
-
|
44
|
+
#
|
45
|
+
|
46
46
|
def select(value)
|
47
47
|
assert_exists
|
48
48
|
raise NoValueFoundException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}" unless include?(value)
|
49
|
-
|
49
|
+
|
50
50
|
selected = nil
|
51
51
|
matching = @object.getOptions.select do |option|
|
52
52
|
next unless matches_option?(option, value)
|
53
|
-
|
53
|
+
|
54
54
|
selected ||= option.asText
|
55
55
|
@container.update_page option.click
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
selected
|
59
59
|
end
|
60
60
|
alias_method :set, :select
|
@@ -65,7 +65,7 @@ module Celerity
|
|
65
65
|
# @param [String, Regexp] value A value.
|
66
66
|
# @return [true, false]
|
67
67
|
#
|
68
|
-
|
68
|
+
|
69
69
|
def include?(value)
|
70
70
|
assert_exists
|
71
71
|
!!@object.getOptions.find { |e| matches_option?(e, value) }
|
@@ -78,7 +78,7 @@ module Celerity
|
|
78
78
|
# @raise [Celerity::Exception::UnknownObjectException] if the value does not exist.
|
79
79
|
# @return [true, false]
|
80
80
|
#
|
81
|
-
|
81
|
+
|
82
82
|
def selected?(value)
|
83
83
|
assert_exists
|
84
84
|
raise UnknownObjectException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}" unless include?(value)
|
@@ -91,7 +91,7 @@ module Celerity
|
|
91
91
|
#
|
92
92
|
# @return [String]
|
93
93
|
#
|
94
|
-
|
94
|
+
|
95
95
|
def type
|
96
96
|
assert_exists
|
97
97
|
'select-' + (@object.hasAttribute('multiple') ? 'multiple' : 'one')
|
@@ -110,12 +110,12 @@ module Celerity
|
|
110
110
|
option.getValueAttribute
|
111
111
|
end
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
private
|
115
|
-
|
115
|
+
|
116
116
|
def matches_option?(option, value)
|
117
117
|
matches?(option.asText, value) || (option.hasAttribute("label") && matches?(option.getLabelAttribute, value))
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
end # SelectList
|
121
121
|
end # Celerity
|