Module: WatirRobot::Native
- Included in:
- KeywordLibrary
- Defined in:
- lib/watir_robot/keywords/native.rb
Overview
Native functionality for manipulating the mouse and keyboard via Java’s java.awt.Robot class
Instance Method Summary collapse
-
#capture_screenshot(path = nil) ⇒ Object
Take a screenshot of the entire screen.
-
#click_left_mouse_button ⇒ Object
Left mouse click.
-
#click_right_mouse_button ⇒ Object
Right mouse click.
-
#drag_and_drop(start_x, start_y, finish_x, finish_y) ⇒ Object
Drag and drop with the mouse.
-
#move_mouse_to_position(x, y) ⇒ Object
Move mouse to specific coordinates.
-
#press_left_mouse_button ⇒ Object
Left mouse press.
-
#press_right_mouse_button ⇒ Object
Right mouse press.
-
#release_left_mouse_button ⇒ Object
Left mouse release.
-
#release_right_mouse_button ⇒ Object
Right mouse release.
Instance Method Details
#capture_screenshot(path = nil) ⇒ Object
Take a screenshot of the entire screen
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/watir_robot/keywords/native.rb', line 132 def capture_screenshot(path = nil) t = Toolkit.getDefaultToolkit s = t.getScreenSize rect = Rectangle.new(0, 0, s.width, s.height); @robot ||= Robot.new image = @robot.createScreenCapture(rect) if path.nil? path = Time.now.to_i.to_s + '_screenshot.png' end file = java.io.File.new(path) ImageIO.write(image, 'png', file) end |
#click_left_mouse_button ⇒ Object
Left mouse click
63 64 65 66 67 |
# File 'lib/watir_robot/keywords/native.rb', line 63 def @robot ||= Robot.new end |
#click_right_mouse_button ⇒ Object
Right mouse click
72 73 74 75 76 |
# File 'lib/watir_robot/keywords/native.rb', line 72 def @robot ||= Robot.new end |
#drag_and_drop(start_x, start_y, finish_x, finish_y) ⇒ Object
Drag and drop with the mouse
This is at the operating system level. Consider using WebDriver’s facilities for drag and drop if you need drag-and-drop within a web page.
119 120 121 122 123 124 125 |
# File 'lib/watir_robot/keywords/native.rb', line 119 def drag_and_drop(start_x, start_y, finish_x, finish_y) @robot ||= Robot.new move_mouse_to_position(start_x.to_i, start_y.to_i) move_mouse_to_position(finish_x.to_i, finish_y.to_i) end |
#move_mouse_to_position(x, y) ⇒ Object
Move mouse to specific coordinates
23 24 25 26 |
# File 'lib/watir_robot/keywords/native.rb', line 23 def move_mouse_to_position(x, y) @robot ||= Robot.new @robot.mouseMove(x.to_i, y.to_i) end |
#press_left_mouse_button ⇒ Object
Left mouse press
31 32 33 34 |
# File 'lib/watir_robot/keywords/native.rb', line 31 def @robot ||= Robot.new @robot.mousePress(InputEvent::BUTTON1_MASK) end |
#press_right_mouse_button ⇒ Object
Right mouse press
39 40 41 42 |
# File 'lib/watir_robot/keywords/native.rb', line 39 def @robot ||= Robot.new @robot.mousePress(InputEvent::BUTTON2_MASK) end |
#release_left_mouse_button ⇒ Object
Left mouse release
47 48 49 50 |
# File 'lib/watir_robot/keywords/native.rb', line 47 def @robot ||= Robot.new @robot.mouseRelease(InputEvent::BUTTON1_MASK) end |
#release_right_mouse_button ⇒ Object
Right mouse release
55 56 57 58 |
# File 'lib/watir_robot/keywords/native.rb', line 55 def @robot ||= Robot.new @robot.mouseRelease(InputEvent::BUTTON2_MASK) end |