Permalink
Browse files

add same mouse API to AutoIt adapter too

  • Loading branch information...
1 parent 29b0019 commit 8032c20eb2f98d1246e5085c21a0839ae17926b0 @jarmo committed Mar 4, 2012
@@ -3,3 +3,4 @@
require File.dirname(__FILE__) + "/autoit/button"
require File.dirname(__FILE__) + "/autoit/text_field"
require File.dirname(__FILE__) + "/autoit/window"
+require File.dirname(__FILE__) + "/autoit/mouse"
@@ -0,0 +1,38 @@
+module RAutomation
+ module Adapter
+ module Autoit
+ class Mouse
+ def initialize(window)
+ @window = window
+ @autoit = window.class.autoit
+ end
+
+ def move(coords={})
+ @last_position = coords = (@last_position || position).merge coords
+
+ until position[:x] == coords[:x] && position[:y] == coords[:y]
+ @window.activate
+ @autoit.MouseMove(coords[:x], coords[:y])
+ end
+ end
+
+ def position
+ {:x => @autoit.MouseGetPosX, :y => @autoit.MouseGetPosY}
+ end
+
+ def click(button = "left")
+ @autoit.MouseClick(button)
+ end
+
+ def press(button = "left")
+ @autoit.MouseDown(button)
+ end
+
+ def release(button = "left")
+ @autoit.MouseUp(button)
+ end
+
+ end
+ end
+ end
+end
@@ -160,6 +160,11 @@ def close
@@autoit.WinKill(locator_hwnd)
end
+ def mouse
+ @container.wait_until_present
+ Mouse.new(self)
+ end
+
# @see Button#initialize
# @see RAutomation::Window#button
def button(locator={})
@@ -180,27 +185,6 @@ def method_missing(name, *args)
@@autoit.send(name, *args)
end
- # AutoIt adapter specific API methods
- def move_mouse(x_coord, y_coord)
- @@autoit.MouseMove(x_coord, y_coord)
- end
-
- def mouse_position
- [@@autoit.MouseGetPosX, @@autoit.MouseGetPosY]
- end
-
- def click_mouse(button = "left")
- @@autoit.MouseClick(button)
- end
-
- def press_mouse(button = "left")
- @@autoit.MouseDown(button)
- end
-
- def release_mouse(button = "left")
- @@autoit.MouseUp(button)
- end
-
# @private
def locator_hwnd
"[HANDLE:#{hwnd.to_i.to_s(16)}]"
@@ -6,15 +6,13 @@ def initialize(window)
@window = window
end
- def move coords={}
- coords = (@last_position || position).merge coords
+ def move(coords={})
+ @last_position = coords = (@last_position || position).merge coords
until position[:x] == coords[:x] && position[:y] == coords[:y]
@window.activate
Functions.set_cursor_pos coords[:x], coords[:y]
end
-
- @last_position = coords
end
def position
@@ -0,0 +1,53 @@
+require "spec_helper"
+
+describe "AutoIt::Mouse", :if => SpecHelper.adapter == :autoit do
+
+ it "#click" do
+ window = RAutomation::Window.new(:title => "MainFormWindow")
+
+ popup = RAutomation::Window.new(:title => "About")
+ popup.should_not be_present
+
+ window.maximize
+ mouse = window.mouse
+ mouse.move :x => 60, :y => 45
+ mouse.click
+
+ RAutomation::WaitHelper.wait_until {popup.present?}
+ end
+
+ it "#position" do
+ window = RAutomation::Window.new(:title => "MainFormWindow")
+ mouse = window.mouse
+
+ mouse.move :x => 13, :y => 16
+ mouse.position.should == {:x => 13, :y => 16}
+ end
+
+ it "#press/#release" do
+ window = RAutomation::Window.new(:title => "MainFormWindow")
+ window.maximize
+
+ text_field = window.text_field(:index => 1)
+ text_field.set("start string")
+ text_field.value.should == "start string"
+
+ mouse = window.mouse
+ mouse.move :x => 146, :y => 103
+ mouse.press
+ mouse.move :x => 194
+ mouse.release
+ window.send_keys "^c"
+
+ text_field.set("new string")
+ text_field.value.should == "new string"
+
+ mouse.move :x => 146
+ mouse.press
+ mouse.move :x => 194
+ mouse.release
+ window.send_keys "^v"
+
+ text_field.value.should == "start string"
+ end
+end
@@ -1,60 +1,6 @@
require "spec_helper"
describe "AutoIt::Window", :if => SpecHelper.adapter == :autoit do
-
- it "mouse clicking" do
- window = RAutomation::Window.new(:title => "MainFormWindow")
-
- popup = RAutomation::Window.new(:title => "About")
- popup.exist?.should == false
-
- window.maximize
- window.move_mouse(60, 45)
- window.click_mouse
-
- sleep 0.1
-
- popup = RAutomation::Window.new(:title => "About")
- popup.exist?.should == true
- end
-
- it "mouse position" do
- window = RAutomation::Window.new(:title => "MainFormWindow")
-
- window.move_mouse(1, 1)
- window.mouse_position.should_not == [100, 100]
-
- window.move_mouse(100, 100)
- window.mouse_position.should == [100, 100]
- end
-
- it "mouse press/release" do
- window = RAutomation::Window.new(:title => "MainFormWindow")
- window.maximize
-
- text_field = window.text_field(:name => "textField")
- text_field.set("start string")
- text_field.value.should == "start string"
-
- window.move_mouse(146, 103)
- window.press_mouse
- window.move_mouse(194, 103)
- window.release_mouse
-
- window.send_keys("^c")
-
- text_field.set("new string")
- text_field.value.should == "new string"
-
- window.move_mouse(146, 103)
- window.press_mouse
- window.move_mouse(194, 103)
- window.release_mouse
- window.send_keys("^v")
-
- text_field.value.should == "start string"
- end
-
it "#method_missing" do
window = RAutomation::Window.new(:title => "MainFormWindow")
@@ -41,7 +41,6 @@
text_field.set("new string")
text_field.value.should == "new string"
- require "ruby-debug"; debugger;
mouse.move :x => 146
mouse.press

0 comments on commit 8032c20

Please sign in to comment.