jarib-celerity 0.0.5.6 → 0.0.5.7

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.
@@ -125,8 +125,7 @@ module Celerity
125
125
 
126
126
  def url
127
127
  assert_exists
128
- # will be renamed getUrl => getRequestUrl
129
- @page.getWebResponse.getUrl.toString
128
+ @page.getWebResponse.getRequestUrl.toString
130
129
  end
131
130
 
132
131
  #
@@ -506,6 +505,14 @@ module Celerity
506
505
  def assert_exists
507
506
  raise UnknownObjectException, "no page loaded" unless exist?
508
507
  end
508
+
509
+ #
510
+ # Returns the element that currently has the focus (Celerity only)
511
+ #
512
+
513
+ def focused_element
514
+ element_from_dom_node(page.getFocusedElement())
515
+ end
509
516
 
510
517
  private
511
518
 
@@ -51,6 +51,10 @@ module Celerity
51
51
  class Dts < ElementCollection
52
52
  def element_class; Dt; end
53
53
  end
54
+
55
+ class Ems < ElementCollection
56
+ def element_class; Em; end
57
+ end
54
58
 
55
59
  class Maps < ElementCollection
56
60
  def element_class; Map; end
@@ -228,6 +228,22 @@ module Celerity
228
228
  def dts
229
229
  Dts.new(self)
230
230
  end
231
+
232
+ #
233
+ # @return [Celerity::Em]
234
+ #
235
+
236
+ def em(*args)
237
+ Em.new(self, *args)
238
+ end
239
+
240
+ #
241
+ # @return [Celerity::Ems]
242
+ #
243
+
244
+ def ems
245
+ Ems.new(self)
246
+ end
231
247
 
232
248
  #
233
249
  # @return [Celerity::FileField]
@@ -237,6 +237,12 @@ module Celerity
237
237
  Log.warn "Element\#method_missing calling super with #{meth.inspect}"
238
238
  super
239
239
  end
240
+
241
+ def methods(*args)
242
+ ms = super
243
+ ms += self.class::ATTRIBUTES.map { |e| e.to_s }
244
+ ms.sort
245
+ end
240
246
 
241
247
  def respond_to?(meth, include_private = false)
242
248
  meth = selector_to_attribute(meth)
@@ -0,0 +1,106 @@
1
+ module Celerity
2
+
3
+ #
4
+ # This class is the superclass for the iterator classes (Buttons, Links, Spans etc.)
5
+ # It would normally only be accessed by the iterator methods (Browser#spans, Browser#links, ...).
6
+ #
7
+
8
+ class ElementCollection
9
+ include Enumerable
10
+
11
+ #
12
+ # @api private
13
+ #
14
+
15
+ def initialize(container, how = nil, what = nil)
16
+ @container = container
17
+ @object = (how == :object ? what : nil)
18
+ @length = length
19
+ end
20
+
21
+ #
22
+ # @return [Fixnum] The number of elements in this collection.
23
+ #
24
+
25
+ def length
26
+ if @object
27
+ @object.length
28
+ else
29
+ @elements ||= ElementLocator.new(@container, element_class).elements_by_idents
30
+ @elements.size
31
+ end
32
+ end
33
+ alias_method :size, :length
34
+
35
+ #
36
+ # @yieldparam [Celerity::Element] element Iterate through the elements in this collection.
37
+ #
38
+
39
+ def each
40
+ if @elements
41
+ @elements.each { |e| yield(element_class.new(@container, :object, e)) }
42
+ else
43
+ 0.upto(@length - 1) { |i| yield iterator_object(i) }
44
+ end
45
+
46
+ @length
47
+ end
48
+
49
+ #
50
+ # Get the element at the given index.
51
+ # This is 1-indexed to keep compatibility with Watir - subject to change.
52
+ # Also note that because of Watir's lazy loading, this will return an Element
53
+ # instance even if the index is out of bounds.
54
+ #
55
+ # @param [Fixnum] n Index of wanted element, 1-indexed.
56
+ # @return [Celerity::Element] Returns a subclass of Celerity::Element
57
+ #
58
+
59
+ def [](n)
60
+ if @elements && @elements[n - INDEX_OFFSET]
61
+ element_class.new(@container, :object, @elements[n - INDEX_OFFSET])
62
+ else
63
+ iterator_object(n - INDEX_OFFSET)
64
+ end
65
+ end
66
+
67
+ #
68
+ # Get the first element in this collection. (Celerity-specific)
69
+ #
70
+ # @return [Celerity::Element] Returns a subclass of Celerity::Element
71
+ #
72
+
73
+ def first
74
+ self[INDEX_OFFSET]
75
+ end
76
+
77
+ #
78
+ # Get the last element in this collection. (Celerity-specific)
79
+ #
80
+ # @return [Celerity::Element] Returns a subclass of Celerity::Element
81
+ #
82
+
83
+ def last
84
+ self[INDEX_OFFSET - 1]
85
+ end
86
+
87
+ #
88
+ # Note: This can be quite useful in irb:
89
+ #
90
+ # puts browser.text_fields
91
+ #
92
+ # @return [String] A string representation of all elements in this collection.
93
+ #
94
+
95
+ def to_s
96
+ map { |e| e.to_s }.join("\n")
97
+ end
98
+
99
+ private
100
+
101
+ def iterator_object(i)
102
+ element_class.new(@container, :index, i+1)
103
+ end
104
+
105
+ end # ElementCollection
106
+ end # Celerity
@@ -7,6 +7,24 @@ module Celerity
7
7
  :target, :rel, :rev, :accesskey, :shape,
8
8
  :coords, :tabindex, :onfocus, :onblur]
9
9
  DEFAULT_HOW = :href
10
- end
10
+
11
+ #
12
+ # Returns the absolute URL for this link (Celerity-specific)
13
+ #
14
+ # (Watir/IE does this for href(), but we don't want that.)
15
+ #
11
16
 
12
- end
17
+ def absolute_url
18
+ assert_exists
19
+ href = @object.getAttributeValue('href')
20
+
21
+ unless href.empty? || URI.parse(href).absolute?
22
+ href = URI.join(browser.url, href).to_s
23
+ end
24
+
25
+ href
26
+ end
27
+
28
+
29
+ end # Link
30
+ end # Celerity
@@ -39,6 +39,10 @@ module Celerity
39
39
  TAGS = [ Identifier.new('dt')]
40
40
  end
41
41
 
42
+ class Em < NonControlElement
43
+ TAGS = [ Identifier.new('em')]
44
+ end
45
+
42
46
  class H1 < NonControlElement
43
47
  TAGS = [ Identifier.new('h1') ]
44
48
  end
@@ -3,7 +3,7 @@ module Celerity #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
5
  TINY = 5
6
- PATCH = 6 # Set to nil for official release
6
+ PATCH = 7 # 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: jarib-celerity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5.6
4
+ version: 0.0.5.7
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-02-19 00:00:00 -08:00
14
+ date: 2009-02-20 00:00:00 -08:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -46,7 +46,7 @@ files:
46
46
  - lib/celerity/default_viewer.rb
47
47
  - lib/celerity/disabled_element.rb
48
48
  - lib/celerity/element.rb
49
- - lib/celerity/element_collections.rb
49
+ - lib/celerity/element_collection.rb
50
50
  - lib/celerity/element_locator.rb
51
51
  - lib/celerity/elements
52
52
  - lib/celerity/elements/button.rb