jarib-celerity 0.0.5.4 → 0.0.5.5

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.
@@ -179,10 +179,10 @@ module Celerity
179
179
  goto(@last_url) if @last_url
180
180
  end
181
181
 
182
- # Wait for ajax calls to finish
183
- def join_threads
182
+ # Wait for javascript jobs to finish
183
+ def wait
184
184
  assert_exists
185
- @page.getEnclosingWindow.getThreadManager.joinAll(10000)
185
+ @page.getEnclosingWindow.getJobManager.waitForAllJobsToFinish(10000)
186
186
  end
187
187
 
188
188
  # Refresh the current page
@@ -191,12 +191,24 @@ module Celerity
191
191
  self.page = @page.refresh
192
192
  end
193
193
 
194
- # Clears all cookies. (Celerity-specific API)
194
+ # Clears all cookies. (Celerity only)
195
195
  def clear_cookies
196
196
  @webclient.getCookieManager.clearCookies
197
197
  end
198
198
 
199
- # Execute the given JavaScript on the current page. (Celerity-specific API)
199
+ # Get the cookies for this session. (Celerity only)
200
+ def cookies
201
+ result = {}
202
+
203
+ cookies = @webclient.getCookieManager.getCookies.to_a
204
+ cookies.each do |cookie|
205
+ result[cookie.getName] = cookie.getValue
206
+ end
207
+
208
+ result
209
+ end
210
+
211
+ # Execute the given JavaScript on the current page. (Celerity only)
200
212
  # @return [Object] The resulting Object
201
213
  def execute_script(source)
202
214
  assert_exists
@@ -219,7 +231,7 @@ module Celerity
219
231
  end
220
232
  end
221
233
 
222
- # Wait until the given block evaluates to true (Celerity-specific API)
234
+ # Wait until the given block evaluates to true (Celerity only)
223
235
  #
224
236
  # @param [Fixnum] timeout Number of seconds to wait before timing out (default: 30).
225
237
  # @yieldparam [Celerity::Browser] browser The browser instance.
@@ -233,7 +245,7 @@ module Celerity
233
245
  end
234
246
  end
235
247
 
236
- # Wait while the given block evaluates to true (Celerity-specific API)
248
+ # Wait while the given block evaluates to true (Celerity only)
237
249
  #
238
250
  # @param [Fixnum] timeout Number of seconds to wait before timing out (default: 30).
239
251
  # @yieldparam [Celerity::Browser] browser The browser instance.
@@ -1,26 +1,53 @@
1
1
  module Celerity
2
2
  module ClickableElement
3
3
 
4
- # clicks the element
5
- def click
6
- assert_exists
7
- assert_enabled if respond_to?(:assert_enabled)
4
+ #
5
+ # click the element
6
+ #
8
7
 
8
+ def click
9
+ assert_exists_and_enabled
9
10
  @container.update_page(@object.click)
10
11
  end
11
12
 
13
+ #
14
+ # double click the element (Celerity only)
15
+ #
16
+
17
+ def double_click
18
+ assert_exists_and_enabled
19
+ @container.update_page(@object.dblClick)
20
+ end
21
+
22
+ #
23
+ # right click the element (Celerity only)
24
+ #
25
+
26
+ def right_click
27
+ assert_exists_and_enabled
28
+ @container.update_page(@object.rightClick)
29
+ end
30
+
31
+ #
12
32
  # Click the element and return a new Browser instance with the resulting page.
13
33
  # This is useful for elements that trigger popups when clicked.
14
34
  #
15
35
  # @return [Celerity::Browser]
16
- def click_and_attach
17
- assert_exists
18
- assert_enabled if respond_to?(:assert_enabled)
36
+ #
19
37
 
38
+ def click_and_attach
39
+ assert_exists_and_enabled
20
40
  browser = Browser.new(:log_level => @browser.log_level)
21
41
  browser.update_page(@object.click)
22
42
 
23
43
  browser
24
44
  end
45
+
46
+ private
47
+
48
+ def assert_exists_and_enabled
49
+ assert_exists
50
+ assert_enabled if respond_to?(:assert_enabled)
51
+ end
25
52
  end
26
53
  end
@@ -49,6 +49,20 @@ module Celerity
49
49
  end
50
50
  end
51
51
 
52
+ # Get the first element in this collection. (Celerity-specific)
53
+ #
54
+ # @return [Celerity::Element] Returns a subclass of Celerity::Element
55
+ def first
56
+ self[INDEX_OFFSET]
57
+ end
58
+
59
+ # Get the last element in this collection. (Celerity-specific)
60
+ #
61
+ # @return [Celerity::Element] Returns a subclass of Celerity::Element
62
+ def last
63
+ self[INDEX_OFFSET - 1]
64
+ end
65
+
52
66
  # Note: This can be quite useful in irb:
53
67
  #
54
68
  # puts browser.text_fields
@@ -1,6 +1,8 @@
1
1
  module Celerity
2
2
 
3
3
  class Label < Element
4
+ include ClickableElement
5
+
4
6
  TAGS = [ Identifier.new('label') ]
5
7
  ATTRIBUTES = BASE_ATTRIBUTES | [:for, :accesskey, :onfocus, :onblur]
6
8
  DEFAULT_HOW = :text
@@ -1,6 +1,7 @@
1
1
  module Celerity
2
2
 
3
3
  class Table < Element
4
+ include ClickableElement
4
5
  include Enumerable
5
6
  include Container
6
7
 
@@ -1,6 +1,7 @@
1
1
  module Celerity
2
2
 
3
3
  class TableCell < Element
4
+ include ClickableElement
4
5
  include Celerity::Exception
5
6
  include Container
6
7
 
@@ -1,6 +1,7 @@
1
1
  module Celerity
2
2
  class TableElement < Element
3
3
  include Enumerable
4
+ include ClickableElement
4
5
 
5
6
  ATTRIBUTES = BASE_ATTRIBUTES | CELLHALIGN_ATTRIBUTES | CELLVALIGN_ATTRIBUTES
6
7
  DEFAULT_HOW = :id
@@ -1,6 +1,7 @@
1
1
  module Celerity
2
2
  class TableRow < Element
3
3
  include Enumerable
4
+ include ClickableElement
4
5
 
5
6
  TAGS = [ Identifier.new('tr') ]
6
7
  DEFAULT_HOW = :id
data/lib/celerity/util.rb CHANGED
@@ -3,45 +3,48 @@ module Celerity
3
3
  module_function
4
4
 
5
5
  HtmlUnit2CelerityElement = {
6
- HtmlUnit::Html::HtmlAnchor => Celerity::Link,
7
- HtmlUnit::Html::HtmlArea => Celerity::Area,
8
- HtmlUnit::Html::HtmlButton => Celerity::Button,
9
- HtmlUnit::Html::HtmlButtonInput => Celerity::Button,
10
- HtmlUnit::Html::HtmlCaption => Celerity::Button, # ?
11
- HtmlUnit::Html::HtmlCheckBoxInput => Celerity::CheckBox,
12
- HtmlUnit::Html::HtmlDivision => Celerity::Div,
13
- HtmlUnit::Html::HtmlFileInput => Celerity::FileField,
14
- HtmlUnit::Html::HtmlForm => Celerity::Form,
15
- HtmlUnit::Html::HtmlFrame => Celerity::Frame,
16
- HtmlUnit::Html::HtmlHeading1 => Celerity::H1,
17
- HtmlUnit::Html::HtmlHeading2 => Celerity::H2,
18
- HtmlUnit::Html::HtmlHeading3 => Celerity::H3,
19
- HtmlUnit::Html::HtmlHeading4 => Celerity::H4,
20
- HtmlUnit::Html::HtmlHeading5 => Celerity::H5,
21
- HtmlUnit::Html::HtmlHeading6 => Celerity::H6,
22
- HtmlUnit::Html::HtmlHiddenInput => Celerity::Hidden,
23
- HtmlUnit::Html::HtmlImage => Celerity::Image,
24
- HtmlUnit::Html::HtmlLabel => Celerity::Label,
25
- HtmlUnit::Html::HtmlLink => Celerity::Link,
26
- HtmlUnit::Html::HtmlListItem => Celerity::Li,
27
- HtmlUnit::Html::HtmlMap => Celerity::Map,
28
- HtmlUnit::Html::HtmlOption => Celerity::Option,
29
- HtmlUnit::Html::HtmlOrderedList => Celerity::Ol,
30
- HtmlUnit::Html::HtmlParagraph => Celerity::P,
31
- HtmlUnit::Html::HtmlPasswordInput => Celerity::TextField,
32
- HtmlUnit::Html::HtmlPreformattedText => Celerity::Pre,
33
- HtmlUnit::Html::HtmlRadioButtonInput => Celerity::Radio,
34
- HtmlUnit::Html::HtmlSelect => Celerity::SelectList,
35
- HtmlUnit::Html::HtmlSpan => Celerity::Span,
36
- HtmlUnit::Html::HtmlTable => Celerity::Table,
37
- HtmlUnit::Html::HtmlTableBody => Celerity::TableBody,
38
- HtmlUnit::Html::HtmlTableCell => Celerity::TableCell,
39
- HtmlUnit::Html::HtmlTableFooter => Celerity::TableFooter,
40
- HtmlUnit::Html::HtmlTableHeader => Celerity::TableHeader,
41
- HtmlUnit::Html::HtmlTableRow => Celerity::TableRow,
42
- HtmlUnit::Html::HtmlTextArea => Celerity::Area,
43
- HtmlUnit::Html::HtmlTextInput => Celerity::TextField,
44
- HtmlUnit::Html::HtmlUnorderedList => Celerity::Ul
6
+ HtmlUnit::Html::HtmlAnchor => Celerity::Link,
7
+ HtmlUnit::Html::HtmlArea => Celerity::Area,
8
+ HtmlUnit::Html::HtmlButton => Celerity::Button,
9
+ HtmlUnit::Html::HtmlButtonInput => Celerity::Button,
10
+ HtmlUnit::Html::HtmlCaption => Celerity::Button, # ?
11
+ HtmlUnit::Html::HtmlCheckBoxInput => Celerity::CheckBox,
12
+ HtmlUnit::Html::HtmlDefinitionDescription => Celerity::Dd,
13
+ HtmlUnit::Html::HtmlDefinitionList => Celerity::Dl,
14
+ HtmlUnit::Html::HtmlDefinitionTerm => Celerity::Dt,
15
+ HtmlUnit::Html::HtmlDivision => Celerity::Div,
16
+ HtmlUnit::Html::HtmlFileInput => Celerity::FileField,
17
+ HtmlUnit::Html::HtmlForm => Celerity::Form,
18
+ HtmlUnit::Html::HtmlFrame => Celerity::Frame,
19
+ HtmlUnit::Html::HtmlHeading1 => Celerity::H1,
20
+ HtmlUnit::Html::HtmlHeading2 => Celerity::H2,
21
+ HtmlUnit::Html::HtmlHeading3 => Celerity::H3,
22
+ HtmlUnit::Html::HtmlHeading4 => Celerity::H4,
23
+ HtmlUnit::Html::HtmlHeading5 => Celerity::H5,
24
+ HtmlUnit::Html::HtmlHeading6 => Celerity::H6,
25
+ HtmlUnit::Html::HtmlHiddenInput => Celerity::Hidden,
26
+ HtmlUnit::Html::HtmlImage => Celerity::Image,
27
+ HtmlUnit::Html::HtmlLabel => Celerity::Label,
28
+ HtmlUnit::Html::HtmlLink => Celerity::Link,
29
+ HtmlUnit::Html::HtmlListItem => Celerity::Li,
30
+ HtmlUnit::Html::HtmlMap => Celerity::Map,
31
+ HtmlUnit::Html::HtmlOption => Celerity::Option,
32
+ HtmlUnit::Html::HtmlOrderedList => Celerity::Ol,
33
+ HtmlUnit::Html::HtmlParagraph => Celerity::P,
34
+ HtmlUnit::Html::HtmlPasswordInput => Celerity::TextField,
35
+ HtmlUnit::Html::HtmlPreformattedText => Celerity::Pre,
36
+ HtmlUnit::Html::HtmlRadioButtonInput => Celerity::Radio,
37
+ HtmlUnit::Html::HtmlSelect => Celerity::SelectList,
38
+ HtmlUnit::Html::HtmlSpan => Celerity::Span,
39
+ HtmlUnit::Html::HtmlTable => Celerity::Table,
40
+ HtmlUnit::Html::HtmlTableBody => Celerity::TableBody,
41
+ HtmlUnit::Html::HtmlTableCell => Celerity::TableCell,
42
+ HtmlUnit::Html::HtmlTableFooter => Celerity::TableFooter,
43
+ HtmlUnit::Html::HtmlTableHeader => Celerity::TableHeader,
44
+ HtmlUnit::Html::HtmlTableRow => Celerity::TableRow,
45
+ HtmlUnit::Html::HtmlTextArea => Celerity::TextField,
46
+ HtmlUnit::Html::HtmlTextInput => Celerity::TextField,
47
+ HtmlUnit::Html::HtmlUnorderedList => Celerity::Ul
45
48
  }
46
49
 
47
50
  def htmlunit2celerity(klass)
@@ -71,7 +74,7 @@ module Celerity
71
74
 
72
75
  def normalize_text(string)
73
76
  string.gsub("\302\240", ' '). # non-breaking space 00A0
74
- gsub(/\n|\t/, '' ). # get rid of newlines/tabs ( could switch back to asText()? )
77
+ gsub(/\n|\t/, ''). # get rid of newlines/tabs
75
78
  strip
76
79
  end
77
80
 
@@ -3,7 +3,7 @@ module Celerity #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
5
  TINY = 5
6
- PATCH = 4 # Set to nil for official release
6
+ PATCH = 5 # Set to nil for official release
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
9
9
  end
@@ -25,8 +25,6 @@ module Celerity
25
25
  # Added for Watir compatability - not in use by Celerity
26
26
  def speed=(s); s end
27
27
  # Added for Watir compatability - not in use by Celerity
28
- def wait; end
29
- # Added for Watir compatability - not in use by Celerity
30
28
  def status; '' end
31
29
  end
32
30
 
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
4
+ version: 0.0.5.5
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-04 00:00:00 -08:00
14
+ date: 2009-02-10 00:00:00 -08:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 1.8.3
24
+ version: 1.8.2
25
25
  version:
26
26
  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."
27
27
  email: jari.bakken@finn.no