jarib-celerity 0.0.6.12 → 0.0.6.14

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/lib/celerity.rb CHANGED
@@ -44,6 +44,7 @@ require "celerity/element_locator"
44
44
  require "celerity/identifier"
45
45
  require "celerity/short_inspect"
46
46
  require "celerity/container"
47
+ require "celerity/xpath_support"
47
48
  require "celerity/element"
48
49
  require "celerity/input_element"
49
50
  require "celerity/elements/non_control_elements"
@@ -1,6 +1,7 @@
1
1
  module Celerity
2
2
  class Browser
3
3
  include Container
4
+ include XpathSupport
4
5
 
5
6
  attr_accessor :page, :object, :charset
6
7
  attr_reader :webclient, :viewer, :options
@@ -238,33 +239,6 @@ module Celerity
238
239
  super
239
240
  end
240
241
 
241
- #
242
- # Get the first element found matching the given XPath.
243
- #
244
- # @param [String] xpath
245
- # @return [Celerity::Element] An element subclass (or Element if none is found)
246
- #
247
-
248
- def element_by_xpath(xpath)
249
- assert_exists
250
- obj = @page.getFirstByXPath(xpath)
251
- element_from_dom_node(obj)
252
- end
253
-
254
- #
255
- # Get all the elements matching the given XPath.
256
- #
257
- # @param [String] xpath
258
- # @return [Array<Celerity::Element>] array of elements
259
- #
260
-
261
- def elements_by_xpath(xpath)
262
- assert_exists
263
- objects = @page.getByXPath(xpath)
264
- # should use an ElementCollection here?
265
- objects.map { |o| element_from_dom_node(o) }.compact
266
- end
267
-
268
242
  #
269
243
  # @return [HtmlUnit::HtmlHtml] the underlying HtmlUnit document.
270
244
  #
@@ -312,7 +286,7 @@ module Celerity
312
286
 
313
287
  def refresh
314
288
  assert_exists
315
- self.page = @page.refresh
289
+ @page.refresh
316
290
  end
317
291
 
318
292
  #
@@ -719,6 +693,7 @@ module Celerity
719
693
  #
720
694
 
721
695
  def page=(value)
696
+ return if @page == value
722
697
  @page = value
723
698
 
724
699
  if @page.respond_to?("getDocumentElement")
@@ -752,6 +727,37 @@ module Celerity
752
727
  element_from_dom_node(page.getFocusedElement())
753
728
  end
754
729
 
730
+ #
731
+ # Enable Celerity's internal WebWindowEventListener
732
+ #
733
+ # @api private
734
+ #
735
+
736
+ def enable_event_listener
737
+ @event_listener ||= lambda do |event|
738
+ self.page = @page ? @page.getEnclosingWindow.getEnclosedPage : event.getNewPage
739
+ end
740
+
741
+ listener.add_listener(:web_window_event, &@event_listener)
742
+ end
743
+
744
+ #
745
+ # Disable Celerity's internal WebWindowEventListener
746
+ #
747
+ # @api private
748
+ #
749
+
750
+ def disable_event_listener
751
+ listener.remove_listener(:web_window_event, @event_listener)
752
+
753
+ if block_given?
754
+ result = yield
755
+ enable_event_listener
756
+
757
+ result
758
+ end
759
+ end
760
+
755
761
  private
756
762
 
757
763
  #
@@ -803,6 +809,7 @@ module Celerity
803
809
  self.ignore_pattern = opts.delete(:ignore_pattern) if opts[:ignore_pattern]
804
810
 
805
811
  @webclient.setAjaxController(::HtmlUnit::NicelyResynchronizingAjaxController.new) if opts.delete(:resynchronize)
812
+ enable_event_listener
806
813
  end
807
814
 
808
815
  #
@@ -851,15 +858,6 @@ module Celerity
851
858
  @viewer = DefaultViewer
852
859
  end
853
860
 
854
- #
855
- # Convert the given HtmlUnit object to a Celerity object
856
- #
857
-
858
- def element_from_dom_node(obj)
859
- element_class = Celerity::Util.htmlunit2celerity(obj.class) || Element
860
- element_class.new(self, :object, obj)
861
- end
862
-
863
861
  def listener
864
862
  @listener ||= Celerity::Listener.new(@webclient)
865
863
  end
@@ -7,7 +7,7 @@ module Celerity
7
7
 
8
8
  def click
9
9
  assert_exists_and_enabled
10
- rescue_status_code_exception { @container.update_page(@object.click) }
10
+ rescue_status_code_exception { @object.click }
11
11
  end
12
12
 
13
13
  #
@@ -16,7 +16,7 @@ module Celerity
16
16
 
17
17
  def double_click
18
18
  assert_exists_and_enabled
19
- rescue_status_code_exception { @container.update_page(@object.dblClick) }
19
+ rescue_status_code_exception { @object.dblClick }
20
20
  end
21
21
 
22
22
  #
@@ -25,7 +25,7 @@ module Celerity
25
25
 
26
26
  def right_click
27
27
  assert_exists_and_enabled
28
- rescue_status_code_exception { @container.update_page(@object.rightClick) }
28
+ rescue_status_code_exception { @object.rightClick }
29
29
  end
30
30
 
31
31
  #
@@ -42,7 +42,9 @@ module Celerity
42
42
  @browser.webclient.get_cookie_manager
43
43
  ) # hirobumi: we do want cookies as well.
44
44
 
45
- rescue_status_code_exception { browser.update_page(@object.click) }
45
+ @browser.disable_event_listener do
46
+ rescue_status_code_exception { browser.page = @object.click }
47
+ end
46
48
 
47
49
  browser
48
50
  end
@@ -56,7 +58,9 @@ module Celerity
56
58
 
57
59
  def download
58
60
  assert_exists_and_enabled
59
- @object.click.getWebResponse.getContentAsStream.to_io
61
+ @browser.disable_event_listener do
62
+ @object.click.getWebResponse.getContentAsStream.to_io
63
+ end
60
64
  end
61
65
 
62
66
  private
@@ -75,15 +75,6 @@ module Celerity
75
75
  container
76
76
  end
77
77
 
78
- #
79
- # Used internally to update the page object.
80
- # @api private
81
- #
82
-
83
- def update_page(page)
84
- @browser.page = page
85
- end
86
-
87
78
  #--
88
79
  # below methods sorted alphabetically
89
80
  #++
@@ -14,7 +14,7 @@ module Celerity
14
14
 
15
15
  # Attribute list is a little weird due to this class covering both <button>
16
16
  # and <input type="submit|reset|image|button" />
17
- ATTRIBUTES = BASE_ATTRIBUTES | [:type, :disabled, :tabindex, :accesskey, :onfocus, :onblur] | [:src, :usemap, :ismap]
17
+ ATTRIBUTES = ATTRIBUTES | [:type, :disabled, :tabindex, :accesskey, :onfocus, :onblur] | [:src, :usemap, :ismap]
18
18
  DEFAULT_HOW = :value
19
19
 
20
20
  #
@@ -15,10 +15,14 @@ module Celerity
15
15
  def set(path)
16
16
  assert_exists
17
17
  path = path.to_s
18
- @container.update_page @object.setValueAttribute(path)
18
+
19
+ @object.setValueAttribute path
20
+
19
21
  unless @object.getContentType
20
22
  @object.setContentType(Celerity::Util.content_type_for(path))
21
23
  end
24
+
25
+ path
22
26
  end
23
27
 
24
28
  end # FileField
@@ -16,7 +16,7 @@ module Celerity
16
16
 
17
17
  def submit
18
18
  assert_exists
19
- @container.update_page @object.submit(nil)
19
+ @object.submit(nil)
20
20
  end
21
21
 
22
22
  end # Form
@@ -1,6 +1,8 @@
1
1
  module Celerity
2
2
  class Frame < Element
3
3
  include Container
4
+ include XpathSupport
5
+
4
6
  attr_accessor :page
5
7
 
6
8
  TAGS = [Identifier.new('frame'), Identifier.new('iframe')]
@@ -72,4 +74,4 @@ module Celerity
72
74
  end
73
75
 
74
76
  end # Frame
75
- end # Celerity
77
+ end # Celerity
@@ -71,7 +71,7 @@ module Celerity
71
71
  def set(value = true)
72
72
  assert_exists
73
73
  assert_enabled
74
- @container.update_page(value ? @object.click : @object.setChecked(value))
74
+ value ? @object.click : @object.setChecked(value)
75
75
  end
76
76
 
77
77
  end
@@ -107,7 +107,7 @@ module Celerity
107
107
 
108
108
  if (value && !set?) || (!value && set?)
109
109
  Log.debug(@object.inspect)
110
- @container.update_page(@object.click)
110
+ @object.click
111
111
  end
112
112
  end
113
113
  end
@@ -52,7 +52,7 @@ module Celerity
52
52
  next unless matches_option?(option, value)
53
53
 
54
54
  selected ||= option.asText
55
- @container.update_page option.click
55
+ option.click
56
56
  end
57
57
 
58
58
  selected
@@ -134,7 +134,7 @@ module Celerity
134
134
 
135
135
  def type_string(value)
136
136
  java.lang.String.new(value.to_java_bytes, @browser.page.getPageEncoding).toCharArray.each do |char|
137
- @container.update_page @object.type(char)
137
+ @object.type(char)
138
138
  end
139
139
  end
140
140
 
@@ -3,7 +3,7 @@ module Celerity #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
5
  TINY = 6
6
- PATCH = 12 # Set to nil for official release
6
+ PATCH = 14 # Set to nil for official release
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
9
9
  end
@@ -0,0 +1,48 @@
1
+ module Celerity
2
+
3
+ #
4
+ # Module to search by xpath
5
+ #
6
+
7
+ module XpathSupport
8
+
9
+ #
10
+ # Get the first element found matching the given XPath.
11
+ #
12
+ # @param [String] xpath
13
+ # @return [Celerity::Element] An element subclass (or Element if none is found)
14
+ #
15
+
16
+ def element_by_xpath(xpath)
17
+ assert_exists
18
+ obj = @page.getFirstByXPath(xpath)
19
+ element_from_dom_node(obj)
20
+ end
21
+
22
+ #
23
+ # Get all the elements matching the given XPath.
24
+ #
25
+ # @param [String] xpath
26
+ # @return [Array<Celerity::Element>] array of elements
27
+ #
28
+
29
+ def elements_by_xpath(xpath)
30
+ assert_exists
31
+ objects = @page.getByXPath(xpath)
32
+ # should use an ElementCollection here?
33
+ objects.map { |o| element_from_dom_node(o) }.compact
34
+ end
35
+
36
+ #
37
+ # Convert the given HtmlUnit DomNode to a Celerity object
38
+ #
39
+
40
+ def element_from_dom_node(obj)
41
+ element_class = Util.htmlunit2celerity(obj.class) || Element
42
+ element_class.new(self, :object, obj)
43
+ end
44
+
45
+
46
+ end
47
+
48
+ end
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.6.12
4
+ version: 0.0.6.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-07-28 00:00:00 -07:00
14
+ date: 2009-07-31 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -73,6 +73,7 @@ files:
73
73
  - lib/celerity/util.rb
74
74
  - lib/celerity/version.rb
75
75
  - lib/celerity/watir_compatibility.rb
76
+ - lib/celerity/xpath_support.rb
76
77
  - lib/celerity.rb
77
78
  - lib/celerity/htmlunit/commons-codec-1.3.jar
78
79
  - lib/celerity/htmlunit/commons-collections-3.2.1.jar