sikuli 0.1.6 → 0.1.7
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/lib/sikuli/clickable.rb +66 -1
- data/lib/sikuli/version.rb +1 -1
- data/spec/sikuli/clickable_spec.rb +9 -1
- metadata +2 -2
data/lib/sikuli/clickable.rb
CHANGED
@@ -43,6 +43,28 @@ module Sikuli
|
|
43
43
|
else raise ArgumentError
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
# Public: Performs a click and hold on an image match or point (x, y)
|
48
|
+
#
|
49
|
+
# args - String representing filename of image to find and click
|
50
|
+
# args - Fixnum, Fixnum representing x and y coordinates within
|
51
|
+
# a Region (0,0) is the top left
|
52
|
+
# seconds - Fixnum representing the number of seconds to hold down
|
53
|
+
# before releasing
|
54
|
+
#
|
55
|
+
# Examples
|
56
|
+
#
|
57
|
+
# region.click_and_hold('smile.png', 2)
|
58
|
+
# region.click_and_hold(123, 432, 2)
|
59
|
+
#
|
60
|
+
# Returns nothing
|
61
|
+
def click_and_hold(seconds = 1, *args)
|
62
|
+
case args.length
|
63
|
+
when 1 then click_image_and_hold(args[0], seconds)
|
64
|
+
when 2 then click_point_and_hold(args[0], args[1], seconds)
|
65
|
+
else raise ArgumentError
|
66
|
+
end
|
67
|
+
end
|
46
68
|
|
47
69
|
# Public: Performs a mouse down, drag, and mouse up
|
48
70
|
#
|
@@ -66,6 +88,49 @@ module Sikuli
|
|
66
88
|
|
67
89
|
private
|
68
90
|
|
91
|
+
# Private: clicks on a matched Region based on an image based search
|
92
|
+
#
|
93
|
+
# filename - A String representation of the filename of the region to
|
94
|
+
# match against
|
95
|
+
# seconds - The length in seconds to hold the mouse
|
96
|
+
#
|
97
|
+
# Returns nothing
|
98
|
+
#
|
99
|
+
# Throws Sikuli::FileNotFound if the file could not be found on the system
|
100
|
+
# Throws Sikuli::ImageNotMatched if no matches are found within the region
|
101
|
+
def click_image_and_hold(filename, seconds)
|
102
|
+
begin
|
103
|
+
pattern = org.sikuli.script::Pattern.new(filename).similar(0.9)
|
104
|
+
@java_obj.hover(pattern)
|
105
|
+
@java_obj.mouseDown(java.awt.event.InputEvent::BUTTON1_MASK)
|
106
|
+
sleep(seconds.to_i)
|
107
|
+
@java_obj.mouseUp(0)
|
108
|
+
rescue NativeException => e
|
109
|
+
raise_exception e, filename
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Private: clicks on a point within the region
|
114
|
+
#
|
115
|
+
# filename - A String representation of the filename of the region to
|
116
|
+
# match against
|
117
|
+
#
|
118
|
+
# Returns nothing
|
119
|
+
#
|
120
|
+
# Throws Sikuli::FileNotFound if the file could not be found on the system
|
121
|
+
# Throws Sikuli::ImageNotMatched if no matches are found within the region
|
122
|
+
def click_point_and_hold(x, y, seconds)
|
123
|
+
begin
|
124
|
+
location = org.sikuli.script::Location.new(x, y).offset(x(), y())
|
125
|
+
@java_obj.hover(location)
|
126
|
+
@java_obj.mouseDown(java.awt.event.InputEvent::BUTTON1_MASK)
|
127
|
+
sleep(seconds.to_i)
|
128
|
+
@java_obj.mouseUp(0)
|
129
|
+
rescue NativeException => e
|
130
|
+
raise_exception e, filename
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
69
134
|
# Private: clicks on a matched Region based on an image based search
|
70
135
|
#
|
71
136
|
# filename - A String representation of the filename of the region to
|
@@ -76,7 +141,7 @@ module Sikuli
|
|
76
141
|
#
|
77
142
|
# Throws Sikuli::FileNotFound if the file could not be found on the system
|
78
143
|
# Throws Sikuli::ImageNotMatched if no matches are found within the region
|
79
|
-
def click_image(filename, is_double = false)
|
144
|
+
def click_image(filename, is_double = false, and_hold = false)
|
80
145
|
begin
|
81
146
|
if is_double
|
82
147
|
@java_obj.doubleClick(filename, 0)
|
data/lib/sikuli/version.rb
CHANGED
@@ -27,6 +27,14 @@ describe Sikuli::Region, "#Clickable" do
|
|
27
27
|
|
28
28
|
it "should not perform a click on an image that is outside of the region" do
|
29
29
|
lambda { @region.click("apple.png") }.should
|
30
|
-
|
30
|
+
raise_error(Sikuli::ImageNotFound, "The image 'apple.png' did not match in this region.")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should perform a click and hold on an image" do
|
34
|
+
lambda { @region.click_and_hold(2, "green_apple.png") }.should_not raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should perform a click and hold on a point" do
|
38
|
+
lambda { @region.click_and_hold(2, 100, 100) }.should_not raise_error
|
31
39
|
end
|
32
40
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: sikuli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Chas Lemley
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-08-
|
13
|
+
date: 2011-08-11 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|