rautomation 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,3 +1,14 @@
1
+ == 0.7.2 / 2012-03-18
2
+
3
+ === Win32 adapter
4
+
5
+ * add mouse API with Window#mouse method
6
+ * add Mouse#move, #position, #click, #press and #release methods
7
+
8
+ === AutoIt adapter
9
+
10
+ * support the same mouse API as Win32 adapter
11
+
1
12
  == 0.7.1 / 2012-02-26
2
13
 
3
14
  === Win32 adapter
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.1
1
+ 0.7.2
@@ -3,3 +3,4 @@ require File.dirname(__FILE__) + "/autoit/locators"
3
3
  require File.dirname(__FILE__) + "/autoit/button"
4
4
  require File.dirname(__FILE__) + "/autoit/text_field"
5
5
  require File.dirname(__FILE__) + "/autoit/window"
6
+ require File.dirname(__FILE__) + "/autoit/mouse"
@@ -0,0 +1,38 @@
1
+ module RAutomation
2
+ module Adapter
3
+ module Autoit
4
+ class Mouse
5
+ def initialize(window)
6
+ @window = window
7
+ @autoit = window.class.autoit
8
+ end
9
+
10
+ def move(coords={})
11
+ @last_position = coords = (@last_position || position).merge(coords)
12
+
13
+ until position[:x] == coords[:x] && position[:y] == coords[:y]
14
+ @window.activate
15
+ @autoit.MouseMove(coords[:x], coords[:y])
16
+ end
17
+ end
18
+
19
+ def position
20
+ {:x => @autoit.MouseGetPosX, :y => @autoit.MouseGetPosY}
21
+ end
22
+
23
+ def click(button = "left")
24
+ @autoit.MouseClick(button)
25
+ end
26
+
27
+ def press(button = "left")
28
+ @autoit.MouseDown(button)
29
+ end
30
+
31
+ def release(button = "left")
32
+ @autoit.MouseUp(button)
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -160,6 +160,11 @@ module RAutomation
160
160
  @@autoit.WinKill(locator_hwnd)
161
161
  end
162
162
 
163
+ def mouse
164
+ @container.wait_until_present
165
+ Mouse.new(self)
166
+ end
167
+
163
168
  # @see Button#initialize
164
169
  # @see RAutomation::Window#button
165
170
  def button(locator={})
@@ -180,27 +185,6 @@ module RAutomation
180
185
  @@autoit.send(name, *args)
181
186
  end
182
187
 
183
- # AutoIt adapter specific API methods
184
- def move_mouse(x_coord, y_coord)
185
- @@autoit.MouseMove(x_coord, y_coord)
186
- end
187
-
188
- def mouse_position
189
- [@@autoit.MouseGetPosX, @@autoit.MouseGetPosY]
190
- end
191
-
192
- def click_mouse(button = "left")
193
- @@autoit.MouseClick(button)
194
- end
195
-
196
- def press_mouse(button = "left")
197
- @@autoit.MouseDown(button)
198
- end
199
-
200
- def release_mouse(button = "left")
201
- @@autoit.MouseUp(button)
202
- end
203
-
204
188
  # @private
205
189
  def locator_hwnd
206
190
  "[HANDLE:#{hwnd.to_i.to_s(16)}]"
@@ -19,3 +19,4 @@ require File.dirname(__FILE__) + "/win_32/select_list"
19
19
  require File.dirname(__FILE__) + "/win_32/table"
20
20
  require File.dirname(__FILE__) + "/win_32/label"
21
21
  require File.dirname(__FILE__) + "/win_32/list_box"
22
+ require File.dirname(__FILE__) + "/win_32/mouse"
@@ -62,6 +62,11 @@ module RAutomation
62
62
  LB_SETCURSEL = 0x186
63
63
  LB_GETSEL = 0x187
64
64
 
65
+ # SendInput
66
+ INPUT_MOUSE = 0
67
+ MOUSEEVENTF_LEFTDOWN = 0x2
68
+ MOUSEEVENTF_LEFTUP = 0x4
69
+
65
70
  end
66
71
  end
67
72
  end
@@ -64,6 +64,12 @@ module RAutomation
64
64
  [:long, :uint], :long
65
65
  attach_function :get_last_error, :GetLastError,
66
66
  [], :long
67
+ attach_function :send_input, :SendInput,
68
+ [:uint, :pointer, :int], :int
69
+ attach_function :_get_cursor_pos, :GetCursorPos,
70
+ [:pointer], :bool
71
+ attach_function :set_cursor_pos, :SetCursorPos,
72
+ [:int, :int], :int
67
73
 
68
74
  # kernel32
69
75
  attach_function :current_thread_id, :GetCurrentThreadId,
@@ -106,6 +112,13 @@ module RAutomation
106
112
  _move_window(hwnd, x, y, width, height, true)
107
113
  end
108
114
 
115
+ def get_cursor_pos
116
+ ptr = FFI::MemoryPointer.new(:long, 2)
117
+ _get_cursor_pos(ptr)
118
+ x, y = ptr.read_array_of_long(2)
119
+ return {:x => x, :y => y}
120
+ end
121
+
109
122
  def window_rect(hwnd)
110
123
  x = FFI::MemoryPointer.new(:long, 4)
111
124
  _get_window_rect(hwnd, x)
@@ -0,0 +1,59 @@
1
+ module RAutomation
2
+ module Adapter
3
+ module Win32
4
+ class Mouse
5
+ def initialize(window)
6
+ @window = window
7
+ end
8
+
9
+ def move(coords={})
10
+ @last_position = coords = (@last_position || position).merge(coords)
11
+
12
+ until position[:x] == coords[:x] && position[:y] == coords[:y]
13
+ @window.activate
14
+ Functions.set_cursor_pos coords[:x], coords[:y]
15
+ end
16
+ end
17
+
18
+ def position
19
+ Functions.get_cursor_pos
20
+ end
21
+
22
+ def click
23
+ send_input down_event, up_event
24
+ end
25
+
26
+ def press
27
+ send_input down_event
28
+ end
29
+
30
+ def release
31
+ send_input up_event
32
+ end
33
+
34
+ private
35
+
36
+ def send_input *inputs
37
+ @window.activate
38
+ Functions.send_input inputs.size, inputs.join, inputs[0].size
39
+ end
40
+
41
+ def down_event
42
+ input Constants::MOUSEEVENTF_LEFTDOWN
43
+ end
44
+
45
+ def up_event
46
+ input Constants::MOUSEEVENTF_LEFTUP
47
+ end
48
+
49
+ def input flag
50
+ mouse_input = Array.new(7, 0)
51
+ mouse_input[0] = Constants::INPUT_MOUSE
52
+ mouse_input[4] = flag
53
+ mouse_input.pack "L*"
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
@@ -177,6 +177,11 @@ module RAutomation
177
177
  Functions.close_window(hwnd)
178
178
  end
179
179
 
180
+ def mouse
181
+ @container.wait_until_present
182
+ Mouse.new(self)
183
+ end
184
+
180
185
  # @see Button#initialize
181
186
  # @see RAutomation::Window#button
182
187
  def button(locator)
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ describe "AutoIt::Mouse", :if => SpecHelper.adapter == :autoit do
4
+
5
+ it "#click" do
6
+ window = RAutomation::Window.new(:title => "MainFormWindow")
7
+
8
+ popup = RAutomation::Window.new(:title => "About")
9
+ popup.should_not be_present
10
+
11
+ window.maximize
12
+ mouse = window.mouse
13
+ mouse.move :x => 60, :y => 45
14
+ mouse.click
15
+
16
+ RAutomation::WaitHelper.wait_until {popup.present?}
17
+ end
18
+
19
+ it "#position" do
20
+ window = RAutomation::Window.new(:title => "MainFormWindow")
21
+ mouse = window.mouse
22
+
23
+ mouse.move :x => 13, :y => 16
24
+ mouse.position.should == {:x => 13, :y => 16}
25
+ end
26
+
27
+ it "#press/#release" do
28
+ window = RAutomation::Window.new(:title => "MainFormWindow")
29
+ window.maximize
30
+
31
+ text_field = window.text_field(:index => 1)
32
+ text_field.set("start string")
33
+ text_field.value.should == "start string"
34
+
35
+ mouse = window.mouse
36
+ mouse.move :x => 146, :y => 103
37
+ mouse.press
38
+ mouse.move :x => 194
39
+ mouse.release
40
+ window.send_keys "^c"
41
+
42
+ text_field.set("new string")
43
+ text_field.value.should == "new string"
44
+
45
+ mouse.move :x => 146
46
+ mouse.press
47
+ mouse.move :x => 194
48
+ mouse.release
49
+ window.send_keys "^v"
50
+
51
+ text_field.value.should == "start string"
52
+ end
53
+ end
@@ -1,60 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "AutoIt::Window", :if => SpecHelper.adapter == :autoit do
4
-
5
- it "mouse clicking" do
6
- window = RAutomation::Window.new(:title => "MainFormWindow")
7
-
8
- popup = RAutomation::Window.new(:title => "About")
9
- popup.exist?.should == false
10
-
11
- window.maximize
12
- window.move_mouse(60, 45)
13
- window.click_mouse
14
-
15
- sleep 0.1
16
-
17
- popup = RAutomation::Window.new(:title => "About")
18
- popup.exist?.should == true
19
- end
20
-
21
- it "mouse position" do
22
- window = RAutomation::Window.new(:title => "MainFormWindow")
23
-
24
- window.move_mouse(1, 1)
25
- window.mouse_position.should_not == [100, 100]
26
-
27
- window.move_mouse(100, 100)
28
- window.mouse_position.should == [100, 100]
29
- end
30
-
31
- it "mouse press/release" do
32
- window = RAutomation::Window.new(:title => "MainFormWindow")
33
- window.maximize
34
-
35
- text_field = window.text_field(:name => "textField")
36
- text_field.set("start string")
37
- text_field.value.should == "start string"
38
-
39
- window.move_mouse(146, 103)
40
- window.press_mouse
41
- window.move_mouse(194, 103)
42
- window.release_mouse
43
-
44
- window.send_keys("^c")
45
-
46
- text_field.set("new string")
47
- text_field.value.should == "new string"
48
-
49
- window.move_mouse(146, 103)
50
- window.press_mouse
51
- window.move_mouse(194, 103)
52
- window.release_mouse
53
- window.send_keys("^v")
54
-
55
- text_field.value.should == "start string"
56
- end
57
-
58
4
  it "#method_missing" do
59
5
  window = RAutomation::Window.new(:title => "MainFormWindow")
60
6
 
@@ -0,0 +1,54 @@
1
+ require "spec_helper"
2
+
3
+ describe "Win32::Mouse", :if => SpecHelper.adapter == :win_32 do
4
+
5
+ it "#click" do
6
+ window = RAutomation::Window.new(:title => "MainFormWindow")
7
+
8
+ popup = RAutomation::Window.new(:title => "About")
9
+ popup.should_not be_present
10
+
11
+ window.maximize
12
+ mouse = window.mouse
13
+ mouse.move :x => 60, :y => 45
14
+ mouse.click
15
+
16
+ RAutomation::WaitHelper.wait_until {popup.present?}
17
+ end
18
+
19
+ it "#position" do
20
+ window = RAutomation::Window.new(:title => "MainFormWindow")
21
+ mouse = window.mouse
22
+
23
+ mouse.move :x => 13, :y => 16
24
+ mouse.position.should == {:x => 13, :y => 16}
25
+ end
26
+
27
+ it "#press/#release" do
28
+ window = RAutomation::Window.new(:title => "MainFormWindow")
29
+ window.maximize
30
+
31
+ text_field = window.text_field(:index => 1)
32
+ text_field.set("start string")
33
+ text_field.value.should == "start string"
34
+
35
+ mouse = window.mouse
36
+ mouse.move :x => 146, :y => 103
37
+ mouse.press
38
+ mouse.move :x => 194
39
+ mouse.release
40
+ window.send_keys [:control, "c"]
41
+
42
+ text_field.set("new string")
43
+ text_field.value.should == "new string"
44
+
45
+ mouse.move :x => 146
46
+ mouse.press
47
+ mouse.move :x => 194
48
+ mouse.release
49
+ window.send_keys [:control, "v"]
50
+
51
+ text_field.value.should == "start string"
52
+ end
53
+ end
54
+
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.1
4
+ version: 0.7.2
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-26 00:00:00.000000000 Z
12
+ date: 2012-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &25954488 !ruby/object:Gem::Requirement
16
+ requirement: &25277112 !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: *25954488
24
+ version_requirements: *25277112
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
@@ -112,6 +112,7 @@ files:
112
112
  - lib/rautomation/adapter/autoit.rb
113
113
  - lib/rautomation/adapter/autoit/button.rb
114
114
  - lib/rautomation/adapter/autoit/locators.rb
115
+ - lib/rautomation/adapter/autoit/mouse.rb
115
116
  - lib/rautomation/adapter/autoit/text_field.rb
116
117
  - lib/rautomation/adapter/autoit/window.rb
117
118
  - lib/rautomation/adapter/helper.rb
@@ -144,6 +145,7 @@ files:
144
145
  - lib/rautomation/adapter/win_32/label.rb
145
146
  - lib/rautomation/adapter/win_32/list_box.rb
146
147
  - lib/rautomation/adapter/win_32/locators.rb
148
+ - lib/rautomation/adapter/win_32/mouse.rb
147
149
  - lib/rautomation/adapter/win_32/radio.rb
148
150
  - lib/rautomation/adapter/win_32/select_list.rb
149
151
  - lib/rautomation/adapter/win_32/table.rb
@@ -155,6 +157,7 @@ files:
155
157
  - lib/rautomation/wait_helper.rb
156
158
  - lib/rautomation/window.rb
157
159
  - rautomation.gemspec
160
+ - spec/adapter/autoit/mouse_spec.rb
158
161
  - spec/adapter/autoit/window_spec.rb
159
162
  - spec/adapter/ms_uia/button_spec.rb
160
163
  - spec/adapter/ms_uia/checkbox_spec.rb
@@ -172,6 +175,7 @@ files:
172
175
  - spec/adapter/win_32/checkbox_spec.rb
173
176
  - spec/adapter/win_32/label_spec.rb
174
177
  - spec/adapter/win_32/listbox_spec.rb
178
+ - spec/adapter/win_32/mouse_spec.rb
175
179
  - spec/adapter/win_32/radio_spec.rb
176
180
  - spec/adapter/win_32/select_list_spec.rb
177
181
  - spec/adapter/win_32/table_spec.rb
@@ -209,6 +213,7 @@ signing_key:
209
213
  specification_version: 3
210
214
  summary: Automate windows and their controls through user-friendly API with Ruby
211
215
  test_files:
216
+ - spec/adapter/autoit/mouse_spec.rb
212
217
  - spec/adapter/autoit/window_spec.rb
213
218
  - spec/adapter/ms_uia/button_spec.rb
214
219
  - spec/adapter/ms_uia/checkbox_spec.rb
@@ -226,6 +231,7 @@ test_files:
226
231
  - spec/adapter/win_32/checkbox_spec.rb
227
232
  - spec/adapter/win_32/label_spec.rb
228
233
  - spec/adapter/win_32/listbox_spec.rb
234
+ - spec/adapter/win_32/mouse_spec.rb
229
235
  - spec/adapter/win_32/radio_spec.rb
230
236
  - spec/adapter/win_32/select_list_spec.rb
231
237
  - spec/adapter/win_32/table_spec.rb