jarib-celerity 0.0.5 → 0.0.5.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/README.txt +13 -8
- data/lib/celerity/browser.rb +76 -30
- data/lib/celerity/clickable_element.rb +1 -1
- data/lib/celerity/collections.rb +4 -0
- data/lib/celerity/container.rb +10 -0
- data/lib/celerity/element.rb +1 -1
- data/lib/celerity/elements/button.rb +2 -3
- data/lib/celerity/elements/frame.rb +2 -1
- data/lib/celerity/elements/non_control_elements.rb +4 -0
- data/lib/celerity/extra/method_generator.rb +2 -2
- data/lib/celerity.rb +1 -0
- data/tasks/rspec.rake +1 -0
- metadata +1 -1
- data/lib/celerity/htmlunit/htmlunit-2.4-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-core-js-2.4-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/nekohtml-1.9.10-20081209.100757-4.jar +0 -0
data/README.txt
CHANGED
@@ -2,14 +2,11 @@
|
|
2
2
|
|
3
3
|
* http://celerity.rubyforge.org/
|
4
4
|
|
5
|
-
== TUTORIAL:
|
6
|
-
|
7
|
-
* http://celerity.rubyforge.org/wiki/wiki.pl?GettingStarted
|
8
|
-
|
9
5
|
== DESCRIPTION:
|
10
6
|
|
11
|
-
Celerity is a JRuby
|
12
|
-
It
|
7
|
+
Celerity is a JRuby wrapper around HtmlUnit – a headless Java browser with
|
8
|
+
JavaScript support. It provides a simple API for programmatic navigation through
|
9
|
+
web applications. Celerity aims at being API compatible with Watir.
|
13
10
|
|
14
11
|
== FEATURES:
|
15
12
|
|
@@ -28,6 +25,10 @@ It is a wrapper around the HtmlUnit Java library and is currently aimed at provi
|
|
28
25
|
|
29
26
|
`jruby -S gem install celerity`
|
30
27
|
|
28
|
+
or from GitHub
|
29
|
+
|
30
|
+
`jruby -S gem install jarib-celerity`
|
31
|
+
|
31
32
|
|
32
33
|
== EXAMPLE:
|
33
34
|
|
@@ -41,9 +42,13 @@ It is a wrapper around the HtmlUnit Java library and is currently aimed at provi
|
|
41
42
|
|
42
43
|
puts "yay" if browser.text.include? 'celerity.rubyforge.org'
|
43
44
|
|
44
|
-
==
|
45
|
+
== SOURCE
|
46
|
+
|
47
|
+
The source code is available at http://github.com/jarib/celerity/tree/master
|
48
|
+
|
49
|
+
== WIKI:
|
45
50
|
|
46
|
-
|
51
|
+
* http://github.com/jarib/celerity/wikis
|
47
52
|
|
48
53
|
== LICENSE:
|
49
54
|
|
data/lib/celerity/browser.rb
CHANGED
@@ -2,7 +2,7 @@ module Celerity
|
|
2
2
|
class Browser
|
3
3
|
include Container
|
4
4
|
|
5
|
-
attr_accessor :page, :object
|
5
|
+
attr_accessor :page, :object, :charset
|
6
6
|
attr_reader :webclient, :viewer
|
7
7
|
|
8
8
|
# Initialize a browser and goto the given URL
|
@@ -14,45 +14,54 @@ module Celerity
|
|
14
14
|
browser
|
15
15
|
end
|
16
16
|
|
17
|
+
# Not implemented. Use ClickableElement#click_and_attach instead.
|
17
18
|
def self.attach(*args)
|
18
19
|
raise NotImplementedError, "use ClickableElement#click_and_attach instead"
|
19
20
|
end
|
20
21
|
|
21
22
|
# Creates a browser object.
|
22
23
|
#
|
23
|
-
# @option opts :log_level [Symbol] (:warning) @see log_level=
|
24
|
+
# @option opts :log_level [Symbol] (:warning) @see log_level=
|
24
25
|
# @option opts :browser [:firefox, :internet_explorer] (:internet_explorer) Set the BrowserVersion used by HtmlUnit. Defaults to Internet Explorer.
|
25
26
|
# @option opts :css [Boolean] (false) Enable CSS. Disabled by default.
|
26
27
|
# @option opts :secure_ssl [Boolean] (true) Disable secure SSL. Enabled by default.
|
27
28
|
# @option opts :resynchronize [Boolean] (false) Use HtmlUnit::NicelyResynchronizingAjaxController to resynchronize Ajax calls.
|
28
29
|
# @option opts :javascript_exceptions [Boolean] (false) Raise exceptions on script errors. Disabled by default.
|
29
30
|
# @option opts :status_code_exceptions [Boolean] (false) Raise exceptions on failing status codes (404 etc.). Disabled by default.
|
30
|
-
# @option opts :render [:html, :xml](:html) What DOM representation to send to connected viewers.
|
31
|
+
# @option opts :render [:html, :xml] (:html) What DOM representation to send to connected viewers.
|
32
|
+
# @option opts :charset [String] ("UTF-8") Specify the charset that webclient will use by default.
|
33
|
+
# @option opts :proxy [String] (nil) Proxy server to use, in address:port format.
|
31
34
|
#
|
32
35
|
# @return [Celerity::Browser] An instance of the browser.
|
33
36
|
# @see Celerity::Container for a small introduction to the API.
|
34
37
|
# @api public
|
35
38
|
def initialize(opts = {})
|
36
|
-
|
37
|
-
|
38
|
-
raise ArgumentError, "bad argument :render => #{opts[:render].inspect}"
|
39
|
+
unless opts.is_a?(Hash)
|
40
|
+
raise TypeError, "wrong argument type #{opts.class}, expected Hash"
|
39
41
|
end
|
40
42
|
|
41
|
-
|
43
|
+
unless (render_types = [:html, :xml, nil]).include?(opts[:render])
|
44
|
+
raise ArgumentError, "expected one of #{render_types.inspect} for key :render"
|
45
|
+
end
|
46
|
+
|
47
|
+
@render_type = opts.delete(:render) || :html
|
48
|
+
@charset = opts.delete(:charset) || "UTF-8"
|
49
|
+
@proxy = opts.delete(:proxy) || nil
|
50
|
+
self.log_level = opts.delete(:log_level) || :warning
|
42
51
|
|
43
|
-
@opts = opts
|
44
52
|
@last_url, @page = nil
|
45
53
|
@error_checkers = []
|
46
54
|
@browser = self # for Container#browser
|
47
55
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
browser = case opts.delete(:browser)
|
57
|
+
when :firefox then ::HtmlUnit::BrowserVersion::FIREFOX_2
|
58
|
+
else ::HtmlUnit::BrowserVersion::INTERNET_EXPLORER_7_0
|
59
|
+
end
|
52
60
|
|
53
61
|
@webclient = ::HtmlUnit::WebClient.new(browser)
|
54
|
-
|
55
|
-
configure_webclient
|
62
|
+
|
63
|
+
configure_webclient(opts)
|
64
|
+
raise ArgumentError, "unknown option #{opts.inspect}" unless opts.empty?
|
56
65
|
find_viewer
|
57
66
|
end
|
58
67
|
|
@@ -62,7 +71,11 @@ module Celerity
|
|
62
71
|
# @return [String] The url.
|
63
72
|
def goto(uri)
|
64
73
|
uri = "http://#{uri}" unless uri =~ %r{://}
|
65
|
-
|
74
|
+
|
75
|
+
request = HtmlUnit::WebRequestSettings.new(::Java::JavaNet::URL.new(uri))
|
76
|
+
request.setCharset(@charset)
|
77
|
+
|
78
|
+
self.page = @webclient.getPage(request)
|
66
79
|
|
67
80
|
url()
|
68
81
|
end
|
@@ -110,6 +123,27 @@ module Celerity
|
|
110
123
|
# Celerity::Util.normalize_text(string)
|
111
124
|
string
|
112
125
|
end
|
126
|
+
|
127
|
+
# @return [Hash] response headers as a hash
|
128
|
+
def response_headers
|
129
|
+
return {} unless @page
|
130
|
+
|
131
|
+
Hash[*@page.getWebResponse.getResponseHeaders.map { |obj| [obj.name, obj.value] }.flatten]
|
132
|
+
end
|
133
|
+
|
134
|
+
# @return [String] content-type as in 'text/html'
|
135
|
+
def content_type
|
136
|
+
return '' unless @page
|
137
|
+
|
138
|
+
@page.getWebResponse.getContentType
|
139
|
+
end
|
140
|
+
|
141
|
+
# @return [IO, nil] page contents as an IO, returns nil if no page is loaded.
|
142
|
+
def io
|
143
|
+
return nil unless @page
|
144
|
+
|
145
|
+
@page.getWebResponse.getContentAsStream.to_io
|
146
|
+
end
|
113
147
|
|
114
148
|
# Check if the current page contains the given text.
|
115
149
|
#
|
@@ -152,6 +186,12 @@ module Celerity
|
|
152
186
|
goto(@last_url) if @last_url
|
153
187
|
end
|
154
188
|
|
189
|
+
# Wait for ajax calls to finish
|
190
|
+
def join_threads
|
191
|
+
assert_exists
|
192
|
+
@page.getEnclosingWindow.getThreadManager.joinAll(10000)
|
193
|
+
end
|
194
|
+
|
155
195
|
# Refresh the current page
|
156
196
|
def refresh
|
157
197
|
assert_exists
|
@@ -234,12 +274,13 @@ module Celerity
|
|
234
274
|
def disable_checker(checker)
|
235
275
|
@error_checkers.delete(checker)
|
236
276
|
end
|
237
|
-
|
277
|
+
|
278
|
+
# :finest, :finer, :fine, :config, :info, :warning, :severe, or :off, :all
|
238
279
|
# @return [Symbol] the current log level
|
239
280
|
def log_level
|
240
281
|
java.util.logging.Logger.getLogger('com.gargoylesoftware.htmlunit').level.to_s.downcase.to_sym
|
241
282
|
end
|
242
|
-
|
283
|
+
|
243
284
|
# Set Java log level (default is :warning)
|
244
285
|
#
|
245
286
|
# @param [Symbol] level :finest, :finer, :fine, :config, :info, :warning, :severe, or :off, :all
|
@@ -313,14 +354,14 @@ module Celerity
|
|
313
354
|
|
314
355
|
value
|
315
356
|
end
|
316
|
-
|
317
|
-
# Start or stop HtmlUnit's DebuggingWebConnection.
|
357
|
+
|
358
|
+
# Start or stop HtmlUnit's DebuggingWebConnection.
|
318
359
|
# The output will go to /tmp/«name»
|
319
|
-
#
|
360
|
+
#
|
320
361
|
# @param [Boolean] bool start or stop
|
321
362
|
# @param [String] name required if bool is true
|
322
363
|
def debug_web_connection(bool, name = nil)
|
323
|
-
if bool
|
364
|
+
if bool
|
324
365
|
raise "no name given" unless name
|
325
366
|
@old_webconnection = @webclient.getWebConnection
|
326
367
|
dwc = HtmlUnit::Util::DebuggingWebConnection.new(@old_webconnection, name)
|
@@ -355,13 +396,18 @@ module Celerity
|
|
355
396
|
|
356
397
|
# Configure the webclient according to the options given to #new.
|
357
398
|
# @see initialize
|
358
|
-
def configure_webclient
|
359
|
-
@webclient.throwExceptionOnScriptError = false unless
|
360
|
-
@webclient.throwExceptionOnFailingStatusCode = false unless
|
361
|
-
@webclient.cssEnabled = false unless
|
362
|
-
@webclient.useInsecureSSL =
|
363
|
-
|
364
|
-
|
399
|
+
def configure_webclient(opts)
|
400
|
+
@webclient.throwExceptionOnScriptError = false unless opts.delete(:javascript_exceptions)
|
401
|
+
@webclient.throwExceptionOnFailingStatusCode = false unless opts.delete(:status_code_exceptions)
|
402
|
+
@webclient.cssEnabled = false unless opts.delete(:css)
|
403
|
+
@webclient.useInsecureSSL = opts.delete(:secure_ssl) == false
|
404
|
+
|
405
|
+
if @proxy
|
406
|
+
phost, pport = @proxy.split(":")
|
407
|
+
@webclient.proxyHost = phost
|
408
|
+
@webclient.proxyPort = pport.to_i
|
409
|
+
end
|
410
|
+
@webclient.setAjaxController(::HtmlUnit::NicelyResynchronizingAjaxController.new) if opts.delete(:resynchronize)
|
365
411
|
end
|
366
412
|
|
367
413
|
# This *should* be unneccessary, but sometimes the page we get from the
|
@@ -380,7 +426,7 @@ module Celerity
|
|
380
426
|
# Render the current page on the viewer.
|
381
427
|
# @api private
|
382
428
|
def render
|
383
|
-
@viewer.render_html(self.send(@
|
429
|
+
@viewer.render_html(self.send(@render_type), url)
|
384
430
|
rescue DRb::DRbConnError, Errno::ECONNREFUSED => e
|
385
431
|
@viewer = DefaultViewer
|
386
432
|
end
|
@@ -390,7 +436,7 @@ module Celerity
|
|
390
436
|
def find_viewer
|
391
437
|
viewer = DRbObject.new_with_uri("druby://127.0.0.1:6429")
|
392
438
|
if viewer.respond_to?(:render_html)
|
393
|
-
@viewer = viewer
|
439
|
+
@viewer = viewer
|
394
440
|
else
|
395
441
|
@viewer = DefaultViewer
|
396
442
|
end
|
data/lib/celerity/collections.rb
CHANGED
@@ -109,6 +109,10 @@ module Celerity
|
|
109
109
|
class Spans < ElementCollections
|
110
110
|
def element_class; Span; end
|
111
111
|
end
|
112
|
+
|
113
|
+
class Strongs < ElementCollections
|
114
|
+
def element_class; Strong; end
|
115
|
+
end
|
112
116
|
|
113
117
|
class Divs < ElementCollections
|
114
118
|
def element_class; Div; end
|
data/lib/celerity/container.rb
CHANGED
@@ -409,6 +409,16 @@ module Celerity
|
|
409
409
|
Spans.new(self)
|
410
410
|
end
|
411
411
|
|
412
|
+
# @return [Celerity::Spans]
|
413
|
+
def strong(*args)
|
414
|
+
Strong.new(self, *args)
|
415
|
+
end
|
416
|
+
|
417
|
+
# @return [Celerity::Strongs]
|
418
|
+
def strongs
|
419
|
+
Strongs.new(self)
|
420
|
+
end
|
421
|
+
|
412
422
|
# @return [Celerity::Table]
|
413
423
|
def table(*args)
|
414
424
|
Table.new(self, *args)
|
data/lib/celerity/element.rb
CHANGED
@@ -13,7 +13,8 @@ module Celerity
|
|
13
13
|
super
|
14
14
|
if @object
|
15
15
|
@inline_frame_object = @object.getEnclosedWindow.getFrameElement
|
16
|
-
|
16
|
+
self.page = @object.getEnclosedPage
|
17
|
+
if (frame = self.page.getDocumentElement)
|
17
18
|
@object = frame
|
18
19
|
end
|
19
20
|
end
|
@@ -81,6 +81,10 @@ module Celerity
|
|
81
81
|
class Span < NonControlElement
|
82
82
|
TAGS = [ Identifier.new('span') ]
|
83
83
|
end
|
84
|
+
|
85
|
+
class Strong < NonControlElement
|
86
|
+
TAGS = [ Identifier.new('strong') ]
|
87
|
+
end
|
84
88
|
|
85
89
|
# class Title < NonControlElement
|
86
90
|
# TAGS = [ Identifier.new('title') ]
|
@@ -150,9 +150,9 @@ end # Celerity
|
|
150
150
|
# require File.dirname(__FILE__) + "/../spec/spec_helper"
|
151
151
|
# $stdout.sync = true
|
152
152
|
# @ie = Browser.new
|
153
|
-
# @ie.goto(
|
153
|
+
# @ie.goto(HTML_DIR + "/forms_with_input_elements.html")
|
154
154
|
#
|
155
155
|
# puts MethodGenerator.new(@ie).parse
|
156
|
-
# @ie.goto(
|
156
|
+
# @ie.goto(HTML_DIR + "/forms3.html")
|
157
157
|
# puts MethodGenerator.new(@ie).parse
|
158
158
|
# end
|
data/lib/celerity.rb
CHANGED
data/tasks/rspec.rake
CHANGED
metadata
CHANGED
Binary file
|
Binary file
|
Binary file
|