operawatir 0.4.1.pre2-jruby → 0.4.1.pre3-jruby

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/CHANGES +233 -0
  2. data/VERSION +1 -1
  3. data/bin/desktopwatir +36 -16
  4. data/bin/operawatir +27 -14
  5. data/lib/operadriver/webdriver-opera.jar +0 -0
  6. data/lib/operawatir/compat/browser.rb +0 -5
  7. data/lib/operawatir/compat/collection.rb +2 -0
  8. data/lib/operawatir/compat/element.rb +3 -0
  9. data/lib/operawatir/compat/element_finders.rb +4 -0
  10. data/lib/operawatir/compat/selector.rb +7 -0
  11. data/lib/operawatir/compat/window.rb +8 -0
  12. data/lib/operawatir/compat.rb +3 -2
  13. data/lib/operawatir/desktop_browser.rb +18 -6
  14. data/lib/operawatir/desktop_helper.rb +2 -0
  15. data/lib/operawatir/quickwidgets/quick_addressfield.rb +12 -0
  16. data/lib/operawatir/quickwidgets/quick_checkbox.rb +1 -1
  17. data/lib/operawatir/quickwidgets/quick_editfield.rb +7 -4
  18. data/lib/operawatir/quickwidgets/quick_searchfield.rb +2 -0
  19. data/lib/operawatir/quickwidgets/quick_widget.rb +1 -1
  20. data/lib/operawatir/quickwidgets/quick_window.rb +6 -2
  21. data/lib/operawatir/screenshot.rb +46 -0
  22. data/lib/operawatir/window.rb +19 -16
  23. data/lib/operawatir.rb +1 -0
  24. data/operawatir.gemspec +23 -2
  25. data/spec/operawatir/core/screenshot_spec.rb +76 -0
  26. data/spec/operawatir/core/window_spec.rb +1 -12
  27. data/spec/operawatir/desktop/desktopbrowser_spec.rb +300 -0
  28. data/spec/operawatir/desktop/quickaddressfield_spec.rb +47 -0
  29. data/spec/operawatir/desktop/quickbutton_spec.rb +34 -0
  30. data/spec/operawatir/desktop/quickwidget_spec.rb +60 -0
  31. data/spec/operawatir/desktop/quickwindow_spec.rb +97 -0
  32. data/spec/operawatir/desktop/shared/shared.rb +48 -0
  33. data/spec/operawatir/matchers.rb +68 -0
  34. data/spec/operawatir/watirspec_desktophelper.rb +14 -0
  35. data/spec/operawatir/watirspec_helper.rb +1 -1
  36. data/spec/watir2/element_spec.rb +90 -21
  37. metadata +24 -3
@@ -0,0 +1,7 @@
1
+ class OperaWatir::Selector
2
+ include Deprecated
3
+
4
+ BASE_TYPES << :selector
5
+ alias_method :selector, :css
6
+ deprecated :selector, "element(:css, 'foo')"
7
+ end
@@ -1,6 +1,7 @@
1
1
  module OperaWatir
2
2
  module Compat
3
3
  module Window
4
+ include Deprecated
4
5
 
5
6
  # Checks whether the body has the given text in it.
6
7
  #
@@ -22,6 +23,13 @@ module OperaWatir
22
23
 
23
24
  alias_method :element_by_xpath, :elements_by_xpath
24
25
 
26
+ # Opera specific
27
+ def get_hash
28
+ visual_hash
29
+ end
30
+
31
+ deprecated :get_hash, 'browser.visual_hash'
32
+
25
33
  end
26
34
  end
27
35
  end
@@ -2,7 +2,7 @@ module OperaWatir
2
2
 
3
3
  module Compat; end
4
4
 
5
- # Switches on compatibility layer (Watir 1 API).
5
+ # Switches on compatibility layer (Watir 2 API).
6
6
  def self.compatibility!
7
7
  require 'operawatir/compat/browser'
8
8
  require 'operawatir/compat/element_finders'
@@ -16,7 +16,8 @@ module OperaWatir
16
16
  # TODO Ruby Modules can't override methods defined in their included klass
17
17
  # Requiring the files is OK, but there needs to be some way of detecting
18
18
  # that we are in compatibility mode.
19
-
19
+
20
+ require 'operawatir/compat/selector'
20
21
  require 'operawatir/compat/collection'
21
22
  require 'operawatir/compat/element'
22
23
  end
@@ -3,9 +3,9 @@ module OperaWatir
3
3
  include DesktopContainer
4
4
  include DesktopCommon
5
5
 
6
- #@private
7
- LoadActions = ["Open url in new page", "Open url in current page", "Open url in background page",
8
- "Open url in new window"]
6
+ LoadActions = ["Open url in new page", "Open url in current page", "Open url in new background page",
7
+ "Open url in new window", "New private page", "Paste and go", "Paste and go background",
8
+ "Hotclick search", "Duplicate page", "Reopen page", "Back", "Forward", "Help"]
9
9
 
10
10
  # @private
11
11
  def initialize
@@ -238,12 +238,24 @@ module OperaWatir
238
238
  # puts quick_widget.to_s
239
239
  # end
240
240
  #
241
- # @param win_name [String] name or [int] id of the window to retrieve the list of widgets from,
241
+ # @param window [String] name or [int] id of the window to retrieve the list of widgets from,
242
242
  #
243
243
  # @return [Array] Array of widgets retrieved from the window
244
244
  #
245
- def widgets(win_name)
246
- driver.getQuickWidgetList(win_name).map do |java_widget|
245
+ def widgets(window)
246
+
247
+ # If window specifies window name, and the active window has this name
248
+ # use its id to get the widgets,
249
+ if window.is_a? String
250
+ active_win_id = driver.getActiveQuickWindowID()
251
+ active_win_name = driver.getQuickWindowName(active_win_id)
252
+
253
+ #If the active window is of same type, then grab that one, not first
254
+ if active_win_name == window #e.g. Both Document Window
255
+ window = active_win_id
256
+ end
257
+ end
258
+ driver.getQuickWidgetList(window).map do |java_widget|
247
259
  case java_widget.getType
248
260
  when QuickWidget::WIDGET_ENUM_MAP[:button]
249
261
  QuickButton.new(self,java_widget)
@@ -8,6 +8,8 @@ require 'operawatir'
8
8
  require 'rspec'
9
9
  require 'rbconfig'
10
10
 
11
+ require File.expand_path('../../../spec/operawatir/matchers', __FILE__)
12
+
11
13
  module OperaWatir::DesktopHelper
12
14
  extend self
13
15
 
@@ -14,7 +14,11 @@ module OperaWatir
14
14
  # @param [String] URL to load
15
15
  # @return [String] text in the address field after the page is loaded
16
16
  # or a blank string
17
+ # @raise [Exceptions::UnknownObjectException] if the widget could not be found
18
+ # using the specified method
17
19
  def load_page_with_url(url)
20
+ # Must focus field before calling enter_text...
21
+ focus_with_click
18
22
  # Enters text in a field and then hits enter
19
23
  enter_text_and_hit_enter(url)
20
24
  end
@@ -22,6 +26,10 @@ module OperaWatir
22
26
  #
23
27
  # Gets the visible text in the address field
24
28
  #
29
+ # @return [String] visible text in address field
30
+ #
31
+ # @raise [Exceptions::UnknownObjectException] if the widget could not be found
32
+ # using the specified method
25
33
  def visible_text
26
34
  element.getVisibleText()
27
35
  end
@@ -29,6 +37,10 @@ module OperaWatir
29
37
  #
30
38
  # Gets the highlighted text in the address field
31
39
  #
40
+ # @return [String] higlighted text in address field, if any, else empty
41
+ #
42
+ # @raise [Exceptions::UnknownObjectException] if the widget could not be found
43
+ # using the specified method
32
44
  def highlighted_text
33
45
  element.getAdditionalText()
34
46
  end
@@ -21,7 +21,7 @@ module OperaWatir
21
21
  ######################################################################
22
22
  # Clicks a radio button or checkbox and toggles it state
23
23
  #
24
- # @return [int] the new state of the radio button or checkbox,
24
+ # @return [Boolean] the new state of the radio button or checkbox,
25
25
  # false for not checked, or true for checked
26
26
  #
27
27
  # @raise [DesktopExceptions::WidgetNotVisibleException] if the checkbox
@@ -45,9 +45,9 @@ module OperaWatir
45
45
  ######################################################################
46
46
  # Clears the contents of the edit field
47
47
  #
48
- # @note The edit field must have focus for this method to work
49
- #
50
48
  def clear
49
+ focus_with_click
50
+
51
51
  key_press_direct("a", :ctrl)
52
52
  key_press_direct("backspace")
53
53
 
@@ -96,10 +96,13 @@ module OperaWatir
96
96
  def enter_text_and_hit_enter(text)
97
97
  loaded_url = ""
98
98
 
99
+ # OBS: only caller should set focus, if not this will happily type
100
+ # away in the incorrect field, if for example called from subclass address_field
99
101
  # Set focus
100
- focus_with_click
102
+ # focus_with_click
103
+
101
104
  # Clear the field
102
- clear()
105
+ clear
103
106
  # Type in the text
104
107
  typed_text = type_text(text) #Opens dropdown window
105
108
  # Check that some text was typed, note the text might be changed in the
@@ -17,6 +17,8 @@ module OperaWatir
17
17
  # or a blank string
18
18
  #
19
19
  def search_with_text(search_text)
20
+ # Must focus field before calling enter_text...
21
+ focus_with_click
20
22
  # Enters text in a field and then hits enter
21
23
  enter_text_and_hit_enter(search_text)
22
24
  end
@@ -303,7 +303,7 @@ private
303
303
 
304
304
  # Click widget
305
305
  def click(button = :left, times = 1, *opts)
306
- raise Exceptions::WidgetDisabledException, "Element #{@selector} is disabled" unless enabled?
306
+ raise DesktopExceptions::WidgetDisabledException, "Element #{@selector} is disabled" unless enabled?
307
307
 
308
308
  #Some buttons etc. aren't visible until hovering them
309
309
  if (visible? == false and type != :dialogtab)
@@ -32,6 +32,8 @@ module OperaWatir
32
32
  #
33
33
  # @return [Symbol] type of the window (e.g. :dropdown, :button)
34
34
  #
35
+ # @raise [Exceptions::UnknownObjectException] if the widget could not be found
36
+ # using the specified method
35
37
  def type
36
38
  return WINDOW_ENUM_MAP.invert[@elm.getType] unless @elm == nil
37
39
  return WINDOW_ENUM_MAP.invert[element.getType]
@@ -149,8 +151,10 @@ private
149
151
  case @method
150
152
  when :name
151
153
  # Use active window when specifying by name "Document Window"
152
- # and not the first if there are more than one
153
- if (@selector == "Document Window")
154
+ # and not the first if there are more than one
155
+ active_window_id = driver.getActiveQuickWindowID()
156
+ name = driver.getQuickWindowName(active_window_id);
157
+ if (@selector == "Document Window" && name == "Document Window")
154
158
  @element = driver.findWindowById(driver.getActiveQuickWindowID())
155
159
  else
156
160
  @element = driver.findWindowByName(@selector)
@@ -0,0 +1,46 @@
1
+ class OperaWatir::Screenshot
2
+
3
+ attr_accessor :browser, :reply
4
+
5
+ def initialize(parent)
6
+ self.browser = parent.browser
7
+ self.reply = driver.saveScreenshot(2, [].to_java(:string))
8
+ end
9
+
10
+ # Saves screenshot to specified location.
11
+ #
12
+ # @param [String] Path to where you want the screenshot saved.
13
+ # @return [String] The full path to the file that was saved.
14
+ def save(filename)
15
+ File.open(filename, 'w') { |f| f.write png }
16
+ File.expand_path filename
17
+ end
18
+
19
+ # Is the screenshot blank?
20
+ #
21
+ # @return [Boolean] True/false depending on the screenshot is blank.
22
+ def blank?
23
+ reply.isBlank
24
+ end
25
+
26
+ # Returns the raw byte string of the screenshot in PNG format.
27
+ #
28
+ # @return [String] A png image in a raw byte string.
29
+ def png
30
+ String.from_java_bytes reply.getPng
31
+ end
32
+
33
+ # Lets you get a MD5 sum of the screen.
34
+ #
35
+ # @return [String] A hash.
36
+ def md5
37
+ reply.getMd5
38
+ end
39
+
40
+ private
41
+
42
+ def driver
43
+ browser.driver
44
+ end
45
+
46
+ end
@@ -105,26 +105,22 @@ class OperaWatir::Window
105
105
 
106
106
  # Opera-specific
107
107
 
108
- # Saves a screenshot of the window to the filesystem of the server.
108
+ # Creates a Screenshot interface or saves screenshot to specified
109
+ # location if a file path is given.
109
110
  #
110
- # @param [String] file_name The absolute path to the location where
111
- # you want the screenshot saved.
112
- # @param [Hash] hashes A list of hashes to compare. If the hashes
113
- # match the hashes of what you are trying to take a screenshot of,
114
- # this method will return a boolean value instead of an actual
115
- # screenshot.
116
- # @param [Integer] time_out Specifies how long we should wait before
117
- # timing out.
111
+ # @param [String] file_name The absolute path to the location where
112
+ # you want the screenshot saved.
118
113
  #
119
- # @return [Object] A ScreenShotReply object.
120
- # @return [Boolean] True/false depending on whether you have given a
121
- # hash as an argument.
122
- def screenshot(file_name, hashes=[], time_out=2)
123
- driver.saveScreenshot(file_name, time_out, hashes.to_java(:string))
114
+ # @return [Object] A Screenshot object.
115
+ # @return [String] Filename to the saved file.
116
+ def screenshot(filename=nil)
117
+ # TODO: This should call document.screenshot instead, but that
118
+ # requires a generic ScreenShotReply interface in OperaDriver.
119
+ filename.nil? ? OperaWatir::Screenshot.new(self) : OperaWatir::Screenshot.new(self).save(filename)
124
120
  end
125
121
 
126
- def visual_hash(time_out=50)
127
- document.visual_hash time_out
122
+ def visual_hash
123
+ document.visual_hash
128
124
  end
129
125
 
130
126
  # Raw finders
@@ -140,6 +136,13 @@ class OperaWatir::Window
140
136
  alias_method :find_by_class, :find_by_class_name
141
137
  alias_method :find_by_tag, :find_by_tag_name
142
138
 
139
+ # Finds the document of a page.
140
+ #
141
+ # @return [Element] The body/document of a page.
142
+ def document
143
+ find_by_tag('body')
144
+ end
145
+
143
146
  # Finds all elements in document.
144
147
  #
145
148
  # @return [Collection] A collection of elements.
data/lib/operawatir.rb CHANGED
@@ -47,6 +47,7 @@ end
47
47
  require 'operawatir/version'
48
48
  require 'operawatir/platform'
49
49
  require 'operawatir/keys'
50
+ require 'operawatir/screenshot'
50
51
  require 'operawatir/preferences'
51
52
  require 'operawatir/spatnav'
52
53
 
data/operawatir.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{operawatir}
8
- s.version = "0.4.1.pre2"
8
+ s.version = "0.4.1.pre3"
9
9
  s.platform = %q{jruby}
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Andreas Tolf Tolfsen", "Chris Lloyd", "Stuart Knightley", "Deniz Turkoglu"]
13
- s.date = %q{2011-03-08}
13
+ s.date = %q{2011-03-14}
14
14
  s.description = %q{ OperaWatir is a part of the Watir (pronounced water) family of
15
15
  free software Ruby libraries for automating web browsers.
16
16
  OperaWatir provides a querying engine and Ruby bindings for a
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  ".gitmodules",
28
28
  ".yardopts",
29
29
  "AUTHORS",
30
+ "CHANGES",
30
31
  "Gemfile",
31
32
  "LICENSE",
32
33
  "README.md",
@@ -49,6 +50,7 @@ Gem::Specification.new do |s|
49
50
  "lib/operawatir/compat/collection.rb",
50
51
  "lib/operawatir/compat/element.rb",
51
52
  "lib/operawatir/compat/element_finders.rb",
53
+ "lib/operawatir/compat/selector.rb",
52
54
  "lib/operawatir/compat/window.rb",
53
55
  "lib/operawatir/desktop-waiter.rb",
54
56
  "lib/operawatir/desktop_browser.rb",
@@ -80,6 +82,7 @@ Gem::Specification.new do |s|
80
82
  "lib/operawatir/quickwidgets/quick_treeview.rb",
81
83
  "lib/operawatir/quickwidgets/quick_widget.rb",
82
84
  "lib/operawatir/quickwidgets/quick_window.rb",
85
+ "lib/operawatir/screenshot.rb",
83
86
  "lib/operawatir/selector.rb",
84
87
  "lib/operawatir/spatnav.rb",
85
88
  "lib/operawatir/version.rb",
@@ -101,8 +104,15 @@ Gem::Specification.new do |s|
101
104
  "spec/operawatir/core/browser_spec.rb",
102
105
  "spec/operawatir/core/element_spec.rb",
103
106
  "spec/operawatir/core/preferences_spec.rb",
107
+ "spec/operawatir/core/screenshot_spec.rb",
104
108
  "spec/operawatir/core/spatnav_spec.rb",
105
109
  "spec/operawatir/core/window_spec.rb",
110
+ "spec/operawatir/desktop/desktopbrowser_spec.rb",
111
+ "spec/operawatir/desktop/quickaddressfield_spec.rb",
112
+ "spec/operawatir/desktop/quickbutton_spec.rb",
113
+ "spec/operawatir/desktop/quickwidget_spec.rb",
114
+ "spec/operawatir/desktop/quickwindow_spec.rb",
115
+ "spec/operawatir/desktop/shared/shared.rb",
106
116
  "spec/operawatir/fixtures/boxes.html",
107
117
  "spec/operawatir/fixtures/grid.html",
108
118
  "spec/operawatir/fixtures/input_fields_value.html",
@@ -110,8 +120,10 @@ Gem::Specification.new do |s|
110
120
  "spec/operawatir/fixtures/paragraphs.html",
111
121
  "spec/operawatir/fixtures/two_input_fields.html",
112
122
  "spec/operawatir/guards.rb",
123
+ "spec/operawatir/matchers.rb",
113
124
  "spec/operawatir/server.rb",
114
125
  "spec/operawatir/watirspec.rake",
126
+ "spec/operawatir/watirspec_desktophelper.rb",
115
127
  "spec/operawatir/watirspec_helper.rb",
116
128
  "spec/watir2/area_spec.rb",
117
129
  "spec/watir2/areas_spec.rb",
@@ -249,10 +261,19 @@ Gem::Specification.new do |s|
249
261
  "spec/operawatir/core/browser_spec.rb",
250
262
  "spec/operawatir/core/element_spec.rb",
251
263
  "spec/operawatir/core/preferences_spec.rb",
264
+ "spec/operawatir/core/screenshot_spec.rb",
252
265
  "spec/operawatir/core/spatnav_spec.rb",
253
266
  "spec/operawatir/core/window_spec.rb",
267
+ "spec/operawatir/desktop/desktopbrowser_spec.rb",
268
+ "spec/operawatir/desktop/quickaddressfield_spec.rb",
269
+ "spec/operawatir/desktop/quickbutton_spec.rb",
270
+ "spec/operawatir/desktop/quickwidget_spec.rb",
271
+ "spec/operawatir/desktop/quickwindow_spec.rb",
272
+ "spec/operawatir/desktop/shared/shared.rb",
254
273
  "spec/operawatir/guards.rb",
274
+ "spec/operawatir/matchers.rb",
255
275
  "spec/operawatir/server.rb",
276
+ "spec/operawatir/watirspec_desktophelper.rb",
256
277
  "spec/operawatir/watirspec_helper.rb",
257
278
  "spec/watir2/area_spec.rb",
258
279
  "spec/watir2/areas_spec.rb",
@@ -0,0 +1,76 @@
1
+ require File.expand_path('../../watirspec_helper', __FILE__)
2
+ require 'tmpdir'
3
+
4
+ RSpec::Matchers.define :save_file do
5
+ match { |filename| File.exists? filename }
6
+ end
7
+
8
+ RSpec::Matchers.define :be_boolean do
9
+ match { |variable| !!variable == variable }
10
+ end
11
+
12
+ describe 'Screenshot' do
13
+
14
+ before :all do
15
+ browser.url = fixture('boxes.html')
16
+ @screenshot = window.screenshot
17
+ @filename = "#{Dir.tmpdir}/screenshot.png"
18
+ end
19
+
20
+ describe '#new' do
21
+ context 'given no argument' do
22
+ it 'creates a new Screenshot object' do
23
+ @screenshot.should be_kind_of OperaWatir::Screenshot
24
+ end
25
+ end
26
+
27
+ context 'given an argument' do
28
+ it 'saves a screenshot' do
29
+ window.screenshot(@filename).should save_file
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '#save' do
35
+ it 'saves screenshot to disk' do
36
+ @screenshot.save(@filename).should save_file
37
+ end
38
+ end
39
+
40
+ describe '#blank?' do
41
+ it 'returns a valid type' do
42
+ @screenshot.blank?.should be_boolean
43
+ end
44
+
45
+ it 'is not blank' do
46
+ @screenshot.blank?.should be_false
47
+ end
48
+ end
49
+
50
+ describe '#png' do
51
+ before(:all) { @png = @screenshot.png }
52
+
53
+ it 'returns a valid type' do
54
+ @png.should be_kind_of String
55
+ end
56
+
57
+ it 'is a real type PNG image' do
58
+ @png.should match /PNG/
59
+ end
60
+ end
61
+
62
+ describe '#md5' do
63
+ before(:all) { @md5 = @screenshot.md5 }
64
+
65
+ it 'returns a valid type' do
66
+ @md5.should be_kind_of String
67
+ end
68
+
69
+ it 'returns a hash' do
70
+ @md5.should match /^(0x)[a-f0-9]{32}$/
71
+ end
72
+ end
73
+
74
+ after(:all) { File.delete @filename if File.exists? @filename }
75
+
76
+ end