oki-celerity 0.8.1.dev

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.
Files changed (77) hide show
  1. data/HISTORY +111 -0
  2. data/LICENSE +621 -0
  3. data/README.rdoc +80 -0
  4. data/Rakefile +11 -0
  5. data/VERSION.yml +5 -0
  6. data/celerity.gemspec +126 -0
  7. data/lib/celerity/browser.rb +908 -0
  8. data/lib/celerity/clickable_element.rb +73 -0
  9. data/lib/celerity/collections.rb +164 -0
  10. data/lib/celerity/container.rb +800 -0
  11. data/lib/celerity/default_viewer.rb +14 -0
  12. data/lib/celerity/disabled_element.rb +40 -0
  13. data/lib/celerity/element.rb +311 -0
  14. data/lib/celerity/element_collection.rb +107 -0
  15. data/lib/celerity/element_locator.rb +164 -0
  16. data/lib/celerity/elements/button.rb +54 -0
  17. data/lib/celerity/elements/file_field.rb +29 -0
  18. data/lib/celerity/elements/form.rb +22 -0
  19. data/lib/celerity/elements/frame.rb +86 -0
  20. data/lib/celerity/elements/image.rb +89 -0
  21. data/lib/celerity/elements/label.rb +16 -0
  22. data/lib/celerity/elements/link.rb +43 -0
  23. data/lib/celerity/elements/meta.rb +14 -0
  24. data/lib/celerity/elements/non_control_elements.rb +124 -0
  25. data/lib/celerity/elements/option.rb +38 -0
  26. data/lib/celerity/elements/radio_check.rb +114 -0
  27. data/lib/celerity/elements/select_list.rb +146 -0
  28. data/lib/celerity/elements/table.rb +153 -0
  29. data/lib/celerity/elements/table_cell.rb +36 -0
  30. data/lib/celerity/elements/table_elements.rb +42 -0
  31. data/lib/celerity/elements/table_row.rb +49 -0
  32. data/lib/celerity/elements/text_field.rb +168 -0
  33. data/lib/celerity/exception.rb +83 -0
  34. data/lib/celerity/htmlunit/apache-mime4j-0.6.jar +0 -0
  35. data/lib/celerity/htmlunit/commons-codec-1.4.jar +0 -0
  36. data/lib/celerity/htmlunit/commons-collections-3.2.1.jar +0 -0
  37. data/lib/celerity/htmlunit/commons-io-1.4.jar +0 -0
  38. data/lib/celerity/htmlunit/commons-lang-2.5.jar +0 -0
  39. data/lib/celerity/htmlunit/commons-logging-1.1.1.jar +0 -0
  40. data/lib/celerity/htmlunit/cssparser-0.9.5.jar +0 -0
  41. data/lib/celerity/htmlunit/htmlunit-2.9-SNAPSHOT.jar +0 -0
  42. data/lib/celerity/htmlunit/htmlunit-core-js-2.8.jar +0 -0
  43. data/lib/celerity/htmlunit/httpclient-4.0.1.jar +0 -0
  44. data/lib/celerity/htmlunit/httpcore-4.0.1.jar +0 -0
  45. data/lib/celerity/htmlunit/httpmime-4.0.1.jar +0 -0
  46. data/lib/celerity/htmlunit/nekohtml-1.9.14.jar +0 -0
  47. data/lib/celerity/htmlunit/sac-1.3.jar +0 -0
  48. data/lib/celerity/htmlunit/serializer-2.7.1.jar +0 -0
  49. data/lib/celerity/htmlunit/xalan-2.7.1.jar +0 -0
  50. data/lib/celerity/htmlunit/xercesImpl-2.9.1.jar +0 -0
  51. data/lib/celerity/htmlunit/xml-apis-1.3.04.jar +0 -0
  52. data/lib/celerity/htmlunit.rb +64 -0
  53. data/lib/celerity/identifier.rb +28 -0
  54. data/lib/celerity/ignoring_web_connection.rb +15 -0
  55. data/lib/celerity/input_element.rb +25 -0
  56. data/lib/celerity/javascript_debugger.rb +32 -0
  57. data/lib/celerity/listener.rb +143 -0
  58. data/lib/celerity/resources/no_viewer.png +0 -0
  59. data/lib/celerity/short_inspect.rb +20 -0
  60. data/lib/celerity/util.rb +129 -0
  61. data/lib/celerity/version.rb +3 -0
  62. data/lib/celerity/viewer_connection.rb +89 -0
  63. data/lib/celerity/watir_compatibility.rb +70 -0
  64. data/lib/celerity/xpath_support.rb +52 -0
  65. data/lib/celerity.rb +77 -0
  66. data/tasks/benchmark.rake +4 -0
  67. data/tasks/check.rake +24 -0
  68. data/tasks/clean.rake +3 -0
  69. data/tasks/fix.rake +25 -0
  70. data/tasks/jar.rake +55 -0
  71. data/tasks/jeweler.rake +28 -0
  72. data/tasks/rdoc.rake +4 -0
  73. data/tasks/snapshot.rake +25 -0
  74. data/tasks/spec.rake +26 -0
  75. data/tasks/website.rake +10 -0
  76. data/tasks/yard.rake +16 -0
  77. metadata +204 -0
@@ -0,0 +1,22 @@
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 | [
9
+ :'accept-charset',
10
+ :accept,
11
+ :action,
12
+ :enctype,
13
+ :method,
14
+ :name,
15
+ :onreset,
16
+ :onsubmit,
17
+ :target,
18
+ ]
19
+ DEFAULT_HOW = :name
20
+
21
+ end # Form
22
+ end # Celerity
@@ -0,0 +1,86 @@
1
+ module Celerity
2
+ class Frame < Element
3
+ include Container
4
+ include XpathSupport
5
+
6
+ attr_accessor :page
7
+
8
+ TAGS = [Identifier.new('frame'), Identifier.new('iframe')]
9
+ ATTRIBUTES = BASE_ATTRIBUTES | [
10
+ :frameborder,
11
+ :longdesc,
12
+ :marginheight,
13
+ :marginwidth,
14
+ :name,
15
+ :noresize,
16
+ :scrolling,
17
+ :src,
18
+ ]
19
+ DEFAULT_HOW = :name
20
+
21
+ #
22
+ # Override the default locate to handle frame and inline frames.
23
+ # @api private
24
+ #
25
+
26
+ def locate
27
+ super
28
+ if @object
29
+ @inline_frame_object = @object.getEnclosedWindow.getFrameElement
30
+ self.page = @object.getEnclosedPage
31
+ if (frame = self.page.getDocumentElement)
32
+ @object = frame
33
+ end
34
+ end
35
+ end
36
+
37
+ #
38
+ # Override assert_exists to raise UnknownFrameException (for Watir compatibility)
39
+ # @api private
40
+ #
41
+
42
+ def assert_exists
43
+ locate
44
+ unless @object
45
+ raise UnknownFrameException, "unable to locate frame, using #{identifier_string}"
46
+ end
47
+ end
48
+
49
+ #
50
+ # Executes the given JavaScript string in this frame. (Celerity only)
51
+ #
52
+
53
+ def execute_script(source)
54
+ assert_exists
55
+ @page.executeJavaScript(source.to_s).getJavaScriptResult
56
+ end
57
+
58
+ #
59
+ # Updates the brwoser page with the page from this frame's top window.
60
+ # Used internally.
61
+ #
62
+ # @api private
63
+ #
64
+
65
+ def update_page(value)
66
+ @browser.page = value.getEnclosingWindow.getTopWindow.getEnclosedPage
67
+ end
68
+
69
+ def to_s
70
+ assert_exists
71
+ Celerity::Util.create_string @inline_frame_object
72
+ end
73
+
74
+ def method_missing(meth, *args, &blk)
75
+ meth = selector_to_attribute(meth)
76
+ if self.class::ATTRIBUTES.include?(meth)
77
+ assert_exists
78
+ @inline_frame_object.getAttribute(meth.to_s)
79
+ else
80
+ Log.warn "Element\#method_missing calling super with #{meth.inspect}"
81
+ super
82
+ end
83
+ end
84
+
85
+ end # Frame
86
+ end # Celerity
@@ -0,0 +1,89 @@
1
+ module Celerity
2
+
3
+ class Image < Element
4
+ include ClickableElement
5
+
6
+ TAGS = [ Identifier.new('img') ]
7
+
8
+ ATTRIBUTES = BASE_ATTRIBUTES | [
9
+ :align,
10
+ :alt,
11
+ :border,
12
+ :height,
13
+ :hspace,
14
+ :ismap,
15
+ :longdesc,
16
+ :name,
17
+ :src,
18
+ :usemap,
19
+ :vspace,
20
+ :width,
21
+ ]
22
+ DEFAULT_HOW = :src
23
+
24
+ #
25
+ # returns the file created date of the image
26
+ #
27
+
28
+ def file_created_date
29
+ assert_exists
30
+ web_response = @object.getWebResponse(true)
31
+ Time.parse(web_response.getResponseHeaderValue("Last-Modified").to_s)
32
+ end
33
+
34
+ #
35
+ # returns the file size of the image in bytes
36
+ #
37
+
38
+ def file_size
39
+ assert_exists
40
+ web_response = @object.getWebResponse(true)
41
+ web_response.getContentAsBytes.length
42
+ end
43
+
44
+ #
45
+ # returns the width in pixels of the image, as a string
46
+ #
47
+
48
+ def width
49
+ assert_exists
50
+ @object.getWidth
51
+ end
52
+
53
+ #
54
+ # returns the height in pixels of the image, as a string
55
+ #
56
+
57
+ def height
58
+ assert_exists
59
+ @object.getHeight
60
+ end
61
+
62
+ #
63
+ # returns true if the image is loaded
64
+ #
65
+
66
+ def loaded?
67
+ assert_exists
68
+ begin
69
+ @object.getImageReader
70
+ true
71
+ rescue
72
+ false
73
+ end
74
+ end
75
+
76
+ #
77
+ # Saves the image to the given file
78
+ #
79
+
80
+ def save(filename)
81
+ assert_exists
82
+ image_reader = @object.getImageReader
83
+ file = java.io.File.new(filename)
84
+ buffered_image = image_reader.read(0);
85
+ javax.imageio.ImageIO.write(buffered_image, image_reader.getFormatName(), file);
86
+ end
87
+
88
+ end # Image
89
+ end # Celerity
@@ -0,0 +1,16 @@
1
+ module Celerity
2
+
3
+ class Label < Element
4
+ include ClickableElement
5
+
6
+ TAGS = [ Identifier.new('label') ]
7
+ ATTRIBUTES = BASE_ATTRIBUTES | [
8
+ :accesskey,
9
+ :for,
10
+ :onblur,
11
+ :onfocus,
12
+ ]
13
+ DEFAULT_HOW = :text
14
+ end
15
+
16
+ end
@@ -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,14 @@
1
+ module Celerity
2
+ class Meta < Element
3
+ ATTRIBUTES = HTML_401_TRANSITIONAL[:i18n] | [
4
+ :'http-equiv',
5
+ :content,
6
+ :id,
7
+ :name,
8
+ :scheme,
9
+ ]
10
+
11
+ DEFAULT_HOW = :id
12
+ TAGS = [ Identifier.new('meta') ]
13
+ end
14
+ end
@@ -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
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