celerity_thingista 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/.document +5 -0
  2. data/.gitignore +9 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +278 -0
  7. data/README.rdoc +84 -0
  8. data/Rakefile +15 -0
  9. data/benchmark/bm_2000_spans.rb +48 -0
  10. data/benchmark/bm_digg.rb +26 -0
  11. data/benchmark/bm_google_images.rb +36 -0
  12. data/benchmark/bm_input_locator.rb +69 -0
  13. data/benchmark/bm_text_input.rb +19 -0
  14. data/benchmark/loader.rb +14 -0
  15. data/celerity.gemspec +26 -0
  16. data/lib/celerity.rb +75 -0
  17. data/lib/celerity/browser.rb +924 -0
  18. data/lib/celerity/clickable_element.rb +73 -0
  19. data/lib/celerity/collections.rb +164 -0
  20. data/lib/celerity/container.rb +802 -0
  21. data/lib/celerity/default_viewer.rb +14 -0
  22. data/lib/celerity/disabled_element.rb +40 -0
  23. data/lib/celerity/element.rb +314 -0
  24. data/lib/celerity/element_collection.rb +115 -0
  25. data/lib/celerity/element_locator.rb +164 -0
  26. data/lib/celerity/elements/button.rb +54 -0
  27. data/lib/celerity/elements/file_field.rb +29 -0
  28. data/lib/celerity/elements/form.rb +22 -0
  29. data/lib/celerity/elements/frame.rb +86 -0
  30. data/lib/celerity/elements/image.rb +89 -0
  31. data/lib/celerity/elements/label.rb +16 -0
  32. data/lib/celerity/elements/link.rb +43 -0
  33. data/lib/celerity/elements/meta.rb +14 -0
  34. data/lib/celerity/elements/non_control_elements.rb +124 -0
  35. data/lib/celerity/elements/option.rb +38 -0
  36. data/lib/celerity/elements/radio_check.rb +114 -0
  37. data/lib/celerity/elements/select_list.rb +146 -0
  38. data/lib/celerity/elements/table.rb +154 -0
  39. data/lib/celerity/elements/table_cell.rb +36 -0
  40. data/lib/celerity/elements/table_elements.rb +42 -0
  41. data/lib/celerity/elements/table_row.rb +54 -0
  42. data/lib/celerity/elements/text_field.rb +168 -0
  43. data/lib/celerity/exception.rb +83 -0
  44. data/lib/celerity/htmlunit.rb +64 -0
  45. data/lib/celerity/htmlunit/commons-codec-1.7.jar +0 -0
  46. data/lib/celerity/htmlunit/commons-collections-3.2.1.jar +0 -0
  47. data/lib/celerity/htmlunit/commons-io-2.4.jar +0 -0
  48. data/lib/celerity/htmlunit/commons-lang3-3.1.jar +0 -0
  49. data/lib/celerity/htmlunit/commons-logging-1.1.1.jar +0 -0
  50. data/lib/celerity/htmlunit/cssparser-0.9.9.jar +0 -0
  51. data/lib/celerity/htmlunit/htmlunit-2.12.jar +0 -0
  52. data/lib/celerity/htmlunit/htmlunit-core-js-2.12.jar +0 -0
  53. data/lib/celerity/htmlunit/httpclient-4.2.3.jar +0 -0
  54. data/lib/celerity/htmlunit/httpcore-4.2.2.jar +0 -0
  55. data/lib/celerity/htmlunit/httpmime-4.2.3.jar +0 -0
  56. data/lib/celerity/htmlunit/jetty-http-8.1.9.v20130131.jar +0 -0
  57. data/lib/celerity/htmlunit/jetty-io-8.1.9.v20130131.jar +0 -0
  58. data/lib/celerity/htmlunit/jetty-util-8.1.9.v20130131.jar +0 -0
  59. data/lib/celerity/htmlunit/jetty-websocket-8.1.9.v20130131.jar +0 -0
  60. data/lib/celerity/htmlunit/nekohtml-1.9.18.jar +0 -0
  61. data/lib/celerity/htmlunit/sac-1.3.jar +0 -0
  62. data/lib/celerity/htmlunit/serializer-2.7.1.jar +0 -0
  63. data/lib/celerity/htmlunit/xalan-2.7.1.jar +0 -0
  64. data/lib/celerity/htmlunit/xercesImpl-2.10.0.jar +0 -0
  65. data/lib/celerity/htmlunit/xml-apis-1.4.01.jar +0 -0
  66. data/lib/celerity/identifier.rb +28 -0
  67. data/lib/celerity/ignoring_web_connection.rb +15 -0
  68. data/lib/celerity/input_element.rb +25 -0
  69. data/lib/celerity/javascript_debugger.rb +32 -0
  70. data/lib/celerity/listener.rb +143 -0
  71. data/lib/celerity/resources/no_viewer.png +0 -0
  72. data/lib/celerity/short_inspect.rb +29 -0
  73. data/lib/celerity/util.rb +129 -0
  74. data/lib/celerity/version.rb +3 -0
  75. data/lib/celerity/viewer_connection.rb +89 -0
  76. data/lib/celerity/watir_compatibility.rb +70 -0
  77. data/lib/celerity/xpath_support.rb +50 -0
  78. data/spec/browser_authentication_spec.rb +16 -0
  79. data/spec/browser_spec.rb +439 -0
  80. data/spec/button_spec.rb +24 -0
  81. data/spec/clickable_element_spec.rb +39 -0
  82. data/spec/default_viewer_spec.rb +23 -0
  83. data/spec/element_spec.rb +77 -0
  84. data/spec/filefield_spec.rb +18 -0
  85. data/spec/htmlunit_spec.rb +63 -0
  86. data/spec/implementation.rb +7 -0
  87. data/spec/index_offset_spec.rb +24 -0
  88. data/spec/link_spec.rb +16 -0
  89. data/spec/listener_spec.rb +142 -0
  90. data/spec/spec_helper.rb +6 -0
  91. data/spec/table_spec.rb +41 -0
  92. data/spec/watir_compatibility_spec.rb +32 -0
  93. data/tasks/benchmark.rake +4 -0
  94. data/tasks/check.rake +24 -0
  95. data/tasks/clean.rake +3 -0
  96. data/tasks/fix.rake +25 -0
  97. data/tasks/jar.rake +55 -0
  98. data/tasks/rdoc.rake +4 -0
  99. data/tasks/snapshot.rake +25 -0
  100. data/tasks/spec.rake +27 -0
  101. data/tasks/website.rake +10 -0
  102. data/tasks/yard.rake +16 -0
  103. data/website/benchmarks.html +237 -0
  104. data/website/css/color.css +153 -0
  105. data/website/css/hacks.css +3 -0
  106. data/website/css/layout.css +179 -0
  107. data/website/css/screen.css +5 -0
  108. data/website/css/textmate.css +226 -0
  109. data/website/css/typography.css +72 -0
  110. data/website/gfx/body_bg.gif +0 -0
  111. data/website/gfx/button_bg.jpg +0 -0
  112. data/website/gfx/header_bg.jpg +0 -0
  113. data/website/gfx/header_left.jpg +0 -0
  114. data/website/gfx/header_right.jpg +0 -0
  115. data/website/gfx/nav_bg.jpg +0 -0
  116. data/website/index.html +125 -0
  117. data/website/yard/index.html +1 -0
  118. metadata +246 -0
@@ -0,0 +1,83 @@
1
+ module Celerity
2
+ module Exception
3
+
4
+ #
5
+ # Superclass for all Celerity exceptions.
6
+ #
7
+
8
+ class CelerityException < StandardError; end
9
+
10
+ #
11
+ # This exception is thrown if an attempt is made to access an object that doesn't exist
12
+ #
13
+
14
+ class UnknownObjectException < CelerityException; end
15
+
16
+ #
17
+ # This exception is thrown if an attempt is made to access an object that is in a disabled state
18
+ #
19
+
20
+ class ObjectDisabledException < CelerityException; end
21
+
22
+ #
23
+ # This exception is thrown if an attempt is made to access a frame that cannot be found
24
+ #
25
+
26
+ class UnknownFrameException < CelerityException; end
27
+
28
+ #
29
+ # This exception is thrown if an attempt is made to access a form that cannot be found
30
+ #
31
+
32
+ class UnknownFormException < CelerityException; end
33
+
34
+ #
35
+ # This exception is thrown if an attempt is made to access an object that is in a read-only state
36
+ #
37
+
38
+ class ObjectReadOnlyException < CelerityException; end
39
+
40
+ #
41
+ # This exception is thrown if an attempt is made to access an object when the specified value cannot be found
42
+ #
43
+
44
+ class NoValueFoundException < CelerityException; end
45
+
46
+ #
47
+ # This exception gets raised if the how argument is wrong.
48
+ #
49
+
50
+ class MissingWayOfFindingObjectException < CelerityException; end
51
+
52
+ #
53
+ # This exception is raised if an attempt is made to access a table row that doesn't exist
54
+ #
55
+
56
+ class UnknownRowException < CelerityException; end
57
+
58
+ #
59
+ # This exception is raised if an attempt is made to access a table cell that doesn't exist
60
+ #
61
+
62
+ class UnknownCellException < CelerityException; end
63
+
64
+ #
65
+ # This exception is thrown if an http error, such as a 404, 500 etc is encountered while navigating
66
+ #
67
+
68
+ class NavigationException < CelerityException; end
69
+
70
+ #
71
+ # This exception is thrown if an unexpected content type is returned by the server.
72
+ #
73
+
74
+ class UnexpectedPageException < CelerityException; end
75
+
76
+ #
77
+ # This exception is thrown if an unexpected content type is returned by the server.
78
+ #
79
+
80
+ class CookieNotFoundError < CelerityException; end
81
+
82
+ end # Exception
83
+ end # Celerity
@@ -0,0 +1,64 @@
1
+ module Celerity
2
+ Jars = Dir[File.dirname(__FILE__) + '/htmlunit/*.jar']
3
+ Jars.each { |jar| require(jar) }
4
+
5
+ module JsxHelper
6
+ def method_missing(meth, *args, &blk)
7
+ m = ["jsxGet_#{meth}", "jsx_get_#{meth}"].find { |m| respond_to?(m) }
8
+ m ? __send__(m) : super
9
+ end
10
+ end
11
+ end
12
+
13
+ module HtmlUnit
14
+ include_package 'com.gargoylesoftware.htmlunit'
15
+
16
+ module Html
17
+ include_package 'com.gargoylesoftware.htmlunit.html'
18
+ end
19
+
20
+ module Util
21
+ include_package 'com.gargoylesoftware.htmlunit.util'
22
+ end
23
+
24
+ end
25
+
26
+ module Java::OrgW3cDom::NamedNodeMap
27
+ include Enumerable
28
+
29
+ def each
30
+ 0.upto(getLength - 1) do |idx|
31
+ yield item(idx)
32
+ end
33
+ end
34
+ end
35
+
36
+ module Java::JavaLang::Iterable
37
+ include Enumerable
38
+
39
+ def each
40
+ it = iterator
41
+ yield it.next while it.hasNext
42
+ end
43
+
44
+ end unless Java::JavaLang::Iterable < Enumerable # depends on JRuby version
45
+
46
+ class Java::ComGargoylesoftwareHtmlunitHtml::HtmlPage
47
+ def inspect
48
+ '#<HtmlPage:0x%s(%s)>' % [self.hash.to_s(16), getWebResponse.getWebRequest.getUrl.toString]
49
+ end
50
+ end
51
+
52
+ class Java::ComGargoylesoftwareHtmlunitHtml::HtmlElement
53
+ def inspect
54
+ '#<%s:0x%s>' % [self.class.name.split("::").last, self.hash.to_s(16)]
55
+ end
56
+ end
57
+
58
+ class Java::ComGargoylesoftwareHtmlunitJavascriptHostHtml::HTMLElement
59
+ include Celerity::JsxHelper
60
+ end
61
+
62
+ class Java::ComGargoylesoftwareHtmlunitJavascriptHostCss::CSSStyleDeclaration
63
+ include Celerity::JsxHelper
64
+ end
Binary file
@@ -0,0 +1,28 @@
1
+ module Celerity
2
+
3
+ class Identifier
4
+ attr_accessor :text
5
+ attr_reader :tag, :attributes
6
+
7
+ def initialize(tag, attributes = {})
8
+ @tag = tag
9
+ @attributes = attributes
10
+ @text = nil
11
+ end
12
+
13
+ def match?(element)
14
+ return false unless @tag == element.getTagName
15
+
16
+ attr_result = @attributes.all? do |key, values|
17
+ values.any? { |val| Util.matches?(element.getAttribute(key.to_s), val) }
18
+ end
19
+
20
+ if @text
21
+ attr_result && Util.matches?(element.asText.strip, @text)
22
+ else
23
+ attr_result
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,15 @@
1
+ module Celerity
2
+ class IgnoringWebConnection < HtmlUnit::Util::FalsifyingWebConnection
3
+
4
+ def initialize(web_client, pattern)
5
+ super(web_client)
6
+ @pattern = pattern
7
+ end
8
+
9
+ def getResponse(request_settings)
10
+ return super unless request_settings.getUrl.toString =~ @pattern
11
+ createWebResponse(request_settings, "", "text/html")
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ module Celerity
2
+ class InputElement < Element
3
+ include ClickableElement
4
+ include DisabledElement
5
+
6
+ ATTRIBUTES = BASE_ATTRIBUTES | [:type, :name, :value, :checked, :disabled, :readonly, :size, :maxlength,
7
+ :src, :alt, :usemap, :ismap, :tabindex, :accesskey, :onfocus, :onblur,
8
+ :onselect, :onchange, :accept, :align]
9
+
10
+ def readonly?
11
+ assert_exists
12
+ @object.hasAttribute 'readonly'
13
+ end
14
+
15
+ private
16
+
17
+ def assert_not_readonly
18
+ if readonly?
19
+ raise ObjectReadOnlyException,
20
+ "InputElement #{identifier_string} is read only."
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ module Celerity
2
+ class JavascriptDebugger
3
+ include Java::net.sourceforge.htmlunit.corejs.javascript.debug.Debugger
4
+
5
+ def handleCompilationDone(ctx, script, source)
6
+ p debug_info_for(script).merge(:source_code => source)
7
+ end
8
+
9
+ def getFrame(ctx, script)
10
+ p debug_info_for(script)
11
+ end
12
+
13
+ private
14
+
15
+ def string_for_context(ctx)
16
+ ctx.toString
17
+ end
18
+
19
+ def string_for_script(script)
20
+ script.toString
21
+ end
22
+
23
+ def debug_info_for(script)
24
+ {
25
+ :source => "#{script.getSourceName}:#{script.getLineNumbers.to_a.join(",")}",
26
+ :function_name => script.getFunctionName,
27
+ :params => (0...script.getParamAndVarCount).map { |idx| script.getParamOrVarName(idx) },
28
+ :function? => script.isFunction,
29
+ }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,143 @@
1
+ module Celerity
2
+
3
+ #
4
+ # This class is used to wrap some of the listeners available from HtmlUnit's WebClient.
5
+ #
6
+
7
+ class Listener
8
+ include com.gargoylesoftware.htmlunit.AlertHandler
9
+ include com.gargoylesoftware.htmlunit.ConfirmHandler
10
+ include com.gargoylesoftware.htmlunit.PromptHandler
11
+ include com.gargoylesoftware.htmlunit.html.HTMLParserListener
12
+ include com.gargoylesoftware.htmlunit.IncorrectnessListener
13
+ include com.gargoylesoftware.htmlunit.StatusHandler
14
+ include com.gargoylesoftware.htmlunit.WebWindowListener
15
+ include com.gargoylesoftware.htmlunit.attachment.AttachmentHandler
16
+
17
+ def initialize(webclient)
18
+ @webclient = webclient
19
+ @procs = Hash.new { |h, k| h[k] = [] }
20
+ end
21
+
22
+ #
23
+ # Add a listener block for one of the available types.
24
+ # @see Celerity::Browser#add_listener
25
+ #
26
+
27
+ def add_listener(type, &block)
28
+ case type
29
+ when :status
30
+ @webclient.setStatusHandler(self)
31
+ when :alert
32
+ @webclient.setAlertHandler(self)
33
+ when :attachment
34
+ @webclient.setAttachmentHandler(self)
35
+ when :web_window_event
36
+ @webclient.addWebWindowListener(self)
37
+ when :html_parser
38
+ @webclient.setHTMLParserListener(self)
39
+ when :incorrectness
40
+ @webclient.setIncorrectnessListener(self)
41
+ when :confirm
42
+ @webclient.setConfirmHandler(self)
43
+ when :prompt
44
+ @webclient.setPromptHandler(self)
45
+ else
46
+ raise ArgumentError, "unknown listener type #{type.inspect}"
47
+ end
48
+
49
+ @procs[type] << block
50
+ end
51
+
52
+ def remove_listener(type, proc_or_index)
53
+ unless @procs.has_key?(type)
54
+ raise ArgumentError, "unknown listener type #{type.inspect}"
55
+ end
56
+
57
+ procs = @procs[type]
58
+
59
+ case proc_or_index
60
+ when Fixnum
61
+ procs.delete_at proc_or_index
62
+ when Proc
63
+ procs.delete proc_or_index
64
+ else
65
+ raise TypeError, "must give proc or index"
66
+ end
67
+ end
68
+
69
+ #
70
+ # interface StatusHandler
71
+ #
72
+
73
+ def statusMessageChanged(page, message)
74
+ @procs[:status].each { |handler| handler.call(page, message) }
75
+ end
76
+
77
+ #
78
+ # interface AlertHandler
79
+ #
80
+
81
+ def handleAlert(page, message)
82
+ @procs[:alert].each { |handler| handler.call(page, message) }
83
+ end
84
+
85
+ #
86
+ # interface ConfirmHandler
87
+ #
88
+ # The returned value is determined by the last registered :confirm listener proc.
89
+ # If it is nil, return true, otherwise return that value as a boolean.
90
+ #
91
+ # @see Browser#confirm
92
+ #
93
+
94
+ def handleConfirm(page, message)
95
+ val = @procs[:confirm].map { |handler| handler.call(page, message) }.last
96
+ val.nil? || !!val
97
+ end
98
+
99
+ #
100
+ # interface AttachmentHandler
101
+ #
102
+
103
+ def handleAttachment(page)
104
+ @procs[:attachment].each { |handler| handler.call(page) }
105
+ end
106
+
107
+ #
108
+ # interface PromptHandler
109
+ #
110
+
111
+ def handlePrompt(page, message)
112
+ @procs[:prompt].each { |handler| handler.call(page, message) }
113
+ end
114
+
115
+ #
116
+ # interface WebWindowListener
117
+ #
118
+
119
+ def webWindowClosed(web_window_event)
120
+ @procs[:web_window_event].each { |handler| handler.call(web_window_event) }
121
+ end
122
+ alias_method :webWindowOpened, :webWindowClosed
123
+ alias_method :webWindowContentChanged, :webWindowClosed
124
+
125
+ #
126
+ # interface HTMLParserListener
127
+ #
128
+
129
+ def error(message, url, line, column, key)
130
+ @procs[:html_parser].each { |handler| handler.call(message, url, line, column, key) }
131
+ end
132
+ alias_method :warning, :error
133
+
134
+ #
135
+ # interface IncorrectnessListener
136
+ #
137
+
138
+ def notify(message, origin)
139
+ @procs[:incorrectness].each { |handler| handler.call(message, origin) }
140
+ end
141
+
142
+ end # Listener
143
+ end # Celerity