rautomation 0.7.0 → 0.7.1

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/History.rdoc CHANGED
@@ -1,4 +1,12 @@
1
- == Version 0.7.0 / 2012-xx-xx
1
+ == 0.7.1 / 2012-02-26
2
+
3
+ === Win32 adapter
4
+
5
+ * add Window#dimensions to get coordinates of the window
6
+ * add Window#move to move/resize the window
7
+ * fix Window#child not to raise any exceptions for cases where window isn't technically a child
8
+
9
+ == Version 0.7.0 / 2012-02-23
2
10
 
3
11
  === All adapters
4
12
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.1
@@ -12,6 +12,10 @@ module RAutomation
12
12
  callback :enum_callback, [:long, :pointer], :bool
13
13
 
14
14
  # user32
15
+ attach_function :_get_window_rect, :GetWindowRect,
16
+ [:long, :pointer], :bool
17
+ attach_function :_move_window, :MoveWindow,
18
+ [:long, :int, :int, :int, :int, :bool], :bool
15
19
  attach_function :enum_windows, :EnumWindows,
16
20
  [:enum_callback, :pointer], :long
17
21
  attach_function :enum_child_windows, :EnumChildWindows,
@@ -98,6 +102,16 @@ module RAutomation
98
102
 
99
103
  alias_method :control_title, :window_title
100
104
 
105
+ def move_window(hwnd, x, y, width, height)
106
+ _move_window(hwnd, x, y, width, height, true)
107
+ end
108
+
109
+ def window_rect(hwnd)
110
+ x = FFI::MemoryPointer.new(:long, 4)
111
+ _get_window_rect(hwnd, x)
112
+ x.read_array_of_long(4)
113
+ end
114
+
101
115
  def window_text(hwnd)
102
116
  found_text = []
103
117
  window_callback = FFI::Function.new(:bool, [:long, :pointer], {:convention => :stdcall}) do |child_hwnd, _|
@@ -170,12 +184,9 @@ module RAutomation
170
184
  alias_method :activate_control, :activate_window
171
185
 
172
186
  def control_hwnd(window_hwnd, locators)
173
- hwnd = find_hwnd(locators, window_hwnd) do |hwnd|
187
+ find_hwnd(locators, window_hwnd) do |hwnd|
174
188
  locators_match?(locators, control_properties(hwnd, locators))
175
189
  end
176
-
177
- raise UnknownElementException, "Element with #{locators.inspect} does not exist" if hwnd == 0 || hwnd.nil?
178
- hwnd
179
190
  end
180
191
 
181
192
  alias_method :child_hwnd, :control_hwnd
@@ -11,10 +11,10 @@ module RAutomation
11
11
  class << self
12
12
  def oleacc_module_handle
13
13
  @oleacc_module_handle ||= begin
14
- oleacc = Functions.load_library "oleacc.dll"
15
- Functions.co_initialize nil
16
- oleacc
17
- end
14
+ oleacc = Functions.load_library "oleacc.dll"
15
+ Functions.co_initialize nil
16
+ oleacc
17
+ end
18
18
  end
19
19
  end
20
20
 
@@ -119,12 +119,34 @@ module RAutomation
119
119
  sleep 1
120
120
  end
121
121
 
122
+ # Moves/resizes the window.
123
+ # @note All coordinates are optional and if not specified current coordinates will be used
124
+ # @param [Hash] coords for specifying the coordinates.
125
+ # @option coords [Fixnum] :left Window coordinate from the left side of screen
126
+ # @option coords [Fixnum] :top Window coordinate from the top of the screen
127
+ # @option coords [Fixnum] :width Width of window
128
+ # @option coords [Fixnum] :height Height of window
129
+ def move(coords={})
130
+ @container.wait_until_present
131
+ rect = dimensions.merge(coords)
132
+ Functions.move_window(hwnd, rect[:left], rect[:top], rect[:width], rect[:height])
133
+ sleep 1
134
+ end
135
+
136
+ # @return [Hash] Hash[:left, :top, :width, :height] with window coordinates
137
+ def dimensions
138
+ @container.wait_until_present
139
+ left, top, right, bottom = Functions.window_rect(hwnd)
140
+ {:left => left, :top => top, :width => right - left, :height => bottom - top}
141
+ end
142
+
143
+
122
144
  # Activates the window and sends keys to it.
123
145
  #
124
146
  # @example
125
147
  # RAutomation::Window.new(:title => //).send_keys "hello!"
126
148
  # RAutomation::Window.new(:title => //).send_keys [:control, "a"], "world!"
127
- # Refer to Keys#KEYS for all the special keycodes.
149
+ # Refer to {Keys::KEYS} for all the special keycodes.
128
150
  # @see RAutomation::Window#send_keys
129
151
  def send_keys(args)
130
152
  Keys.encode(args).each do |arg|
@@ -1,8 +1,9 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "Win32::Window", :if => SpecHelper.adapter == :win_32 do
4
+ let(:window) {RAutomation::Window.new(:title => /MainFormWindow/i)}
5
+
4
6
  it "#child" do
5
- window = RAutomation::Window.new(:title => /MainFormWindow/i)
6
7
  window.should exist
7
8
 
8
9
  # buttons are windows too. so let's find the button for now
@@ -11,38 +12,58 @@ describe "Win32::Window", :if => SpecHelper.adapter == :win_32 do
11
12
  child.title.should == "&About"
12
13
  end
13
14
 
14
- it "send tab keystrokes to move focus between elements" do
15
- window = RAutomation::Window.new(:title => /MainFormWindow/i)
16
- window.button(:value => "&About").focus
17
- window.button(:value => "&About").should be_focused
15
+ context "#send_keys" do
16
+ it "send tab keystrokes to move focus between elements" do
17
+ window.button(:value => "&About").focus
18
+ window.button(:value => "&About").should be_focused
18
19
 
19
- window.send_keys(:tab, :tab, :tab)
20
- button = window.button(:value => "Close")
21
- button.should exist
22
- button.should be_focused
23
- end
20
+ window.send_keys(:tab, :tab, :tab)
21
+ button = window.button(:value => "Close")
22
+ button.should exist
23
+ button.should be_focused
24
+ end
24
25
 
25
- it "#send_keys" do
26
- window = RAutomation::Window.new(:title => /MainFormWindow/i)
27
- text_field = window.text_field(:index => 1)
28
- text_field.focus
29
- window.send_keys "abc123ABChiHI!"
30
- text_field.value.should == "abc123ABChiHI!"
26
+ it "send arbitrary characters and control keys" do
27
+ text_field = window.text_field(:index => 1)
28
+ text_field.focus
29
+ window.send_keys "abc123ABChiHI!"
30
+ text_field.value.should == "abc123ABChiHI!"
31
31
 
32
- window.send_keys :space, "X"
33
- text_field.value.should == "abc123ABChiHI! X"
32
+ window.send_keys :space, "X"
33
+ text_field.value.should == "abc123ABChiHI! X"
34
34
 
35
- window.send_keys [:control, "a"], :backspace
36
- text_field.value.should be_empty
35
+ window.send_keys [:control, "a"], :backspace
36
+ text_field.value.should be_empty
37
+ end
37
38
  end
38
39
 
39
40
  it "#control" do
40
- window = RAutomation::Window.new(:title => /MainFormWindow/i)
41
41
  window.control(:value => "&About").should exist
42
42
  end
43
43
 
44
- it "has controls" do
45
- window = RAutomation::Window.new(:title => /MainFormWindow/i)
44
+ it "#controls" do
46
45
  window.controls(:class => /button/i).size.should == 12
47
46
  end
47
+
48
+ context "#move" do
49
+ it "width=500, height=400, left=10, top=0" do
50
+ window.move :width => 500, :height => 400, :left => 10, :top => 0
51
+ coords = window.dimensions
52
+ coords[:width].should == 500
53
+ coords[:height].should == 400
54
+ coords[:left].should == 10
55
+ coords[:top].should == 0
56
+ end
57
+
58
+ it "uses default dimensions if not specified" do
59
+ coords = window.dimensions
60
+ window.move :width => 253, :left => 26
61
+
62
+ new_coords = window.dimensions
63
+ new_coords[:width].should == 253
64
+ new_coords[:left].should == 26
65
+ new_coords[:top].should == coords[:top]
66
+ new_coords[:height].should == coords[:height]
67
+ end
68
+ end
48
69
  end
data/spec/spec_helper.rb CHANGED
@@ -2,9 +2,6 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  require 'rautomation'
3
3
  require 'rspec'
4
4
 
5
- #require 'simplecov'
6
- #SimpleCov.start
7
-
8
5
  module SpecHelper
9
6
  # @private
10
7
  def adapter
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rautomation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-23 00:00:00.000000000 Z
12
+ date: 2012-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &26885976 !ruby/object:Gem::Requirement
16
+ requirement: &25954488 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '2.3'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *26885976
24
+ version_requirements: *25954488
25
25
  description: ! "RAutomation is a small and easy to use library for helping out to
26
26
  automate windows and their controls\nfor automated testing.\n\nRAutomation provides:\n*
27
27
  Easy to use and user-friendly API (inspired by Watir http://www.watir.com)\n* Cross-platform