walidhalabi-celerity 0.0.6.12 → 0.0.6.13

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.
@@ -32,7 +32,7 @@ module Celerity
32
32
  # @see Celerity::Container for an introduction to the main API.
33
33
  #
34
34
  # @option opts :log_level [Symbol] (:warning) @see log_level=
35
- # @option opts :browser [:firefox, :internet_explorer] (:internet_explorer) Set the BrowserVersion used by HtmlUnit. Defaults to Internet Explorer.
35
+ # @option opts :browser [:internet_explorer, :firefox, :firefox3] (:firefox) Set the BrowserVersion used by HtmlUnit. Defaults to Firefox 2.
36
36
  # @option opts :css [Boolean] (false) Enable CSS. Disabled by default.
37
37
  # @option opts :secure_ssl [Boolean] (true) Disable secure SSL. Enabled by default.
38
38
  # @option opts :resynchronize [Boolean] (false) Use HtmlUnit::NicelyResynchronizingAjaxController to resynchronize Ajax calls.
@@ -56,8 +56,9 @@ module Celerity
56
56
  unless (render_types = [:html, :xml, nil]).include?(opts[:render])
57
57
  raise ArgumentError, "expected one of #{render_types.inspect} for key :render"
58
58
  end
59
-
60
- @options = opts.dup # for ClickableElement#click_and_attach
59
+
60
+ opts = opts.dup # we'll delete from opts, so dup to avoid side effects
61
+ @options = opts.dup # keep the unmodified version around as well
61
62
 
62
63
  @render_type = opts.delete(:render) || :html
63
64
  @charset = opts.delete(:charset) || "UTF-8"
@@ -348,7 +349,7 @@ module Celerity
348
349
  max_age = opts.delete(:max_age) || (Time.now + 60*60*24) # not sure if this is correct
349
350
  secure = opts.delete(:secure) || false
350
351
 
351
- raise "unknown option: #{opts.inspect}" unless opts.empty?
352
+ raise(ArgumentError, "unknown option: #{opts.inspect}") unless opts.empty?
352
353
 
353
354
  cookie = Cookie.new(domain, name, value, path, max_age, secure)
354
355
  @webclient.getCookieManager.addCookie(cookie)
@@ -359,6 +360,8 @@ module Celerity
359
360
  #
360
361
  # @param [String] domain
361
362
  # @param [String] name
363
+ #
364
+ # @raise [CookieNotFoundError] if the cookie doesn't exist
362
365
  #
363
366
 
364
367
  def remove_cookie(domain, name)
@@ -366,7 +369,7 @@ module Celerity
366
369
  cookie = cm.getCookies.find { |c| c.getDomain == domain && c.getName == name }
367
370
 
368
371
  if cookie.nil?
369
- raise "no cookie with domain #{domain.inspect} and name #{name.inspect}"
372
+ raise CookieNotFoundError, "no cookie with domain #{domain.inspect} and name #{name.inspect}"
370
373
  end
371
374
 
372
375
  cm.removeCookie(cookie)
@@ -407,12 +410,16 @@ module Celerity
407
410
  #
408
411
 
409
412
  def wait_until(timeout = 30, &block)
413
+ returned = nil
414
+
410
415
  Timeout.timeout(timeout) do
411
- until yield(self)
416
+ until returned = yield(self)
412
417
  refresh_page_from_window
413
418
  sleep 0.1
414
419
  end
415
420
  end
421
+
422
+ returned
416
423
  end
417
424
 
418
425
  #
@@ -424,12 +431,16 @@ module Celerity
424
431
  #
425
432
 
426
433
  def wait_while(timeout = 30, &block)
434
+ returned = nil
435
+
427
436
  Timeout.timeout(timeout) do
428
- while yield(self)
437
+ while returned = yield(self)
429
438
  refresh_page_from_window
430
439
  sleep 0.1
431
440
  end
432
441
  end
442
+
443
+ returned
433
444
  end
434
445
 
435
446
  #
@@ -471,21 +482,18 @@ module Celerity
471
482
  # Start or stop HtmlUnit's DebuggingWebConnection. (Celerity only)
472
483
  # The output will go to /tmp/«name»
473
484
  #
474
- # @param [Boolean] bool start or stop
475
- # @param [String] name required if bool is true
485
+ # @param [String] name directory name
486
+ # @param [block] blk block to execute
476
487
  #
477
488
 
478
- def debug_web_connection(bool, name = nil)
479
- if bool
480
- raise "no name given" unless name
481
- @old_webconnection = @webclient.getWebConnection
482
- dwc = HtmlUnit::Util::DebuggingWebConnection.new(@old_webconnection, name)
483
- @webclient.setWebConnection(dwc)
484
- $stderr.puts "debug-webconnection on"
485
- else
486
- @webclient.setWebConnection(@old_webconnection) if @old_webconnection
487
- $stderr.puts "debug-webconnection off"
488
- end
489
+ def debug_web_connection(name, &blk)
490
+ old_wc = @webclient.getWebConnection
491
+
492
+ @webclient.setWebConnection HtmlUnit::Util::DebuggingWebConnection.new(old_wc, name)
493
+ res = yield
494
+ @webclient.setWebConnection old_wc
495
+
496
+ res
489
497
  end
490
498
 
491
499
  #
@@ -684,7 +692,7 @@ module Celerity
684
692
  #
685
693
  # Check that we have a @page object.
686
694
  #
687
- # @raise [Celerity::Exception::UnknownObjectException] if no page is loaded.
695
+ # @raise [UnknownObjectException] if no page is loaded.
688
696
  # @api private
689
697
  #
690
698
 
@@ -722,8 +730,10 @@ module Celerity
722
730
  browser = (opts.delete(:browser) || :firefox).to_sym
723
731
 
724
732
  case browser
725
- when :firefox, :ff
733
+ when :firefox, :ff, :ff2
726
734
  browser_version = ::HtmlUnit::BrowserVersion::FIREFOX_2
735
+ when :firefox3, :ff3
736
+ browser_version = ::HtmlUnit::BrowserVersion::FIREFOX_3
727
737
  when :internet_explorer, :ie
728
738
  browser_version = ::HtmlUnit::BrowserVersion::INTERNET_EXPLORER_7
729
739
  else
@@ -52,6 +52,7 @@ module Celerity
52
52
  end
53
53
 
54
54
  @conditions.freeze
55
+ @object = nil
55
56
  end
56
57
 
57
58
  #
@@ -118,7 +118,7 @@ module Celerity
118
118
 
119
119
  def get_by_idents(meth, idents)
120
120
  with_nullpointer_retry do
121
- @object.getAllHtmlChildElements.send(meth) do |e|
121
+ all_elements.send(meth) do |e|
122
122
  next unless @tags.include?(e.getTagName)
123
123
  idents.any? { |id| element_matches_ident?(e, id) }
124
124
  end
@@ -142,13 +142,22 @@ module Celerity
142
142
  def elements_by_tag_names(tags = @tags)
143
143
  with_nullpointer_retry do
144
144
  # HtmlUnit's getHtmlElementsByTagNames won't get elements in the correct
145
- # order (making :index fail), so we're using getAllHtmlChildElements instead.
146
- @object.getAllHtmlChildElements.select do |elem|
145
+ # order (making :index fail), so we're looping through all elements instead.
146
+ all_elements.select do |elem|
147
147
  tags.include?(elem.getTagName)
148
148
  end
149
149
  end
150
150
  end
151
151
 
152
+ def all_elements
153
+ unless @object
154
+ raise %{internal error in #{self.class}: @object=#{@object.inspect} @container=#{@container.inspect} @element_class=#{@element_class.inspect}
155
+ Please report this failure and the code/HTML that caused it at http://github.com/jarib/celerity/issues}
156
+ end
157
+
158
+ @object.getAllHtmlChildElements
159
+ end
160
+
152
161
  # HtmlUnit throws NPEs sometimes when we're locating elements
153
162
  # Retry seems to work fine.
154
163
  def with_nullpointer_retry(max_retries = 3)
@@ -3,7 +3,9 @@ module Celerity
3
3
  #
4
4
  # Input: Button
5
5
  #
6
- # Class representing button elements
6
+ # Class representing button elements.
7
+ #
8
+ # This class covers both <button> and <input type="submit|reset|image|button" /> elements.
7
9
  #
8
10
 
9
11
  class Button < InputElement
@@ -1,6 +1,7 @@
1
1
  module Celerity
2
2
  class Meta < Element
3
- ATTRIBUTES = [:name, :id, :'http-equiv', :content, :scheme] | HTML_401_TRANSITIONAL[:i18n]
3
+ ATTRIBUTES = [:name, :id, :'http-equiv', :content, :scheme] | HTML_401_TRANSITIONAL[:i18n]
4
+ DEFAULT_HOW = :id
4
5
  TAGS = [ Identifier.new('meta') ]
5
6
  end
6
7
  end
@@ -73,5 +73,11 @@ module Celerity
73
73
 
74
74
  class UnexpectedPageException < CelerityException; end
75
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
+
76
82
  end # Exception
77
83
  end # Celerity
@@ -3,7 +3,7 @@ module Celerity #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
5
  TINY = 6
6
- PATCH = 10 # Set to nil for official release
6
+ PATCH = 11 # Set to nil for official release
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: walidhalabi-celerity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6.12
4
+ version: 0.0.6.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
@@ -24,7 +24,7 @@ dependencies:
24
24
  - !ruby/object:Gem::Version
25
25
  version: 2.0.0
26
26
  version:
27
- description: "Celerity is a JRuby wrapper around HtmlUnit \xE2\x80\x93 a headless Java browser with JavaScript support. It provides a simple API for programmatic navigation through web applications. Celerity aims at being API compatible with Watir. This version has been modified slightly to include a workaround for a YUI issue by by Walid Halabi."
27
+ description: "Celerity is a JRuby wrapper around HtmlUnit \xE2\x80\x93 a headless Java browser with JavaScript support. It provides a simple API for programmatic navigation through web applications. Celerity aims at being API compatible with Watir. This version has been modified slightly to include a workaround for a YUI issue by Walid Halabi."
28
28
  email: jari.bakken@finn.no
29
29
  executables: []
30
30
 
@@ -75,7 +75,7 @@ files:
75
75
  - lib/celerity/htmlunit/commons-logging-1.1.1.jar
76
76
  - lib/celerity/htmlunit/cssparser-0.9.5.jar
77
77
  - lib/celerity/htmlunit/htmlunit-2.6-SNAPSHOT.jar
78
- - lib/celerity/htmlunit/htmlunit-core-js-2.5.jar
78
+ - lib/celerity/htmlunit/htmlunit-core-js-2.6-SNAPSHOT.jar
79
79
  - lib/celerity/htmlunit/nekohtml-1.9.13-20090507.082850-2.jar
80
80
  - lib/celerity/htmlunit/sac-1.3.jar
81
81
  - lib/celerity/htmlunit/serializer-2.7.1.jar