jarib-celerity 0.0.5 → 0.0.5.1

Sign up to get free protection for your applications and to get access to all the features.
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 library for easy and fast functional test automation for web applications.
12
- It is a wrapper around the HtmlUnit Java library and is currently aimed at providing the same API and functionality as Watir.
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
- == GIT
45
+ == SOURCE
46
+
47
+ The source code is available at http://github.com/jarib/celerity/tree/master
48
+
49
+ == WIKI:
45
50
 
46
- The project is manually mirrored @ http://github.com/jarib/celerity/tree/master
51
+ * http://github.com/jarib/celerity/wikis
47
52
 
48
53
  == LICENSE:
49
54
 
@@ -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
- raise TypeError, "bad argument: #{opts.inspect}" unless opts.is_a? Hash
37
- unless [:html, :xml, nil].include?(opts[:render])
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
- opts[:render] = opts[:render] || :html
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
- self.log_level = @opts[:log_level] || :warning
49
-
50
- browser = @opts[:browser] == :firefox ?
51
- ::HtmlUnit::BrowserVersion::FIREFOX_2 : ::HtmlUnit::BrowserVersion::INTERNET_EXPLORER_7_0
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
- self.page = @webclient.getPage(uri)
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 @opts[:javascript_exceptions]
360
- @webclient.throwExceptionOnFailingStatusCode = false unless @opts[:status_code_exceptions]
361
- @webclient.cssEnabled = false unless @opts[:css]
362
- @webclient.useInsecureSSL = @opts[:secure_ssl] == false
363
- @webclient.setAjaxController(::HtmlUnit::NicelyResynchronizingAjaxController.new) if @opts[:resynchronize]
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(@opts[:render]), url)
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
@@ -17,7 +17,7 @@ module Celerity
17
17
  assert_exists
18
18
  assert_enabled if respond_to?(:assert_enabled)
19
19
 
20
- browser = Browser.new
20
+ browser = Browser.new(:log_level => @browser.log_level)
21
21
  browser.update_page(@object.click)
22
22
 
23
23
  browser
@@ -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
@@ -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)
@@ -162,7 +162,7 @@ module Celerity
162
162
 
163
163
  result = ''
164
164
  @object.getAttributes.each do |attribute|
165
- result << %Q{#{attribute.getName}="#{attribute.getHtmlValue.to_s}"}
165
+ result << %Q{#{attribute.getName}="#{attribute.getHtmlValue}"}
166
166
  end
167
167
 
168
168
  result
@@ -29,6 +29,5 @@ module Celerity
29
29
  end
30
30
  end
31
31
 
32
- end
33
-
34
- end
32
+ end # Button
33
+ end # Celerity
@@ -13,7 +13,8 @@ module Celerity
13
13
  super
14
14
  if @object
15
15
  @inline_frame_object = @object.getEnclosedWindow.getFrameElement
16
- if (frame = @object.getEnclosedPage.getDocumentElement)
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(TEST_HOST + "/forms_with_input_elements.html")
153
+ # @ie.goto(HTML_DIR + "/forms_with_input_elements.html")
154
154
  #
155
155
  # puts MethodGenerator.new(@ie).parse
156
- # @ie.goto(TEST_HOST + "/forms3.html")
156
+ # @ie.goto(HTML_DIR + "/forms3.html")
157
157
  # puts MethodGenerator.new(@ie).parse
158
158
  # end
data/lib/celerity.rb CHANGED
@@ -10,6 +10,7 @@ require "timeout"
10
10
  require "time"
11
11
  require 'drb'
12
12
  require "fileutils"
13
+ require "thread"
13
14
 
14
15
  module Celerity
15
16
  Log = Logger.new($DEBUG ? $stderr : nil)
data/tasks/rspec.rake CHANGED
@@ -19,6 +19,7 @@ desc "Run the specs under spec/"
19
19
  Spec::Rake::SpecTask.new do |t|
20
20
  t.spec_opts = ['--options', "spec/spec.opts"]
21
21
  t.spec_files = FileList['spec/**/*_spec.rb']
22
+ # t.ruby_opts = %w[--headless] if RUBY_PLATFORM =~ /java/
22
23
 
23
24
  begin
24
25
  require 'rcov'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jarib-celerity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken