sikuli 0.1.5 → 0.2.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/README.md +1 -1
- data/lib/sikuli/clickable.rb +66 -1
- data/lib/sikuli/searchable.rb +43 -18
- data/lib/sikuli/sikuli-script.jar +0 -0
- data/lib/sikuli/version.rb +1 -1
- data/spec/sikuli/clickable_spec.rb +9 -1
- data/spec/sikuli/searchable_spec.rb +16 -7
- metadata +81 -87
data/README.md
CHANGED
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/searchable.rb
CHANGED
@@ -24,14 +24,35 @@ module Sikuli
|
|
24
24
|
def find(filename, similarity = 0.9)
|
25
25
|
begin
|
26
26
|
pattern = build_pattern(filename, similarity)
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
match = Region.new(@java_obj.find(pattern))
|
28
|
+
match.highlight if Sikuli::Config.highlight_on_find
|
29
|
+
match
|
30
30
|
rescue NativeException => e
|
31
31
|
raise_exception e, filename
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
# Public: search for an image within a region (does not raise ImageNotFound exceptions)
|
36
|
+
#
|
37
|
+
# filename - A String representation of the filename to match against
|
38
|
+
# similarity - A Float between 0 and 1 representing the threshold for
|
39
|
+
# matching an image. Passing 1 corresponds to a 100% pixel for pixel
|
40
|
+
# match. Defaults to 0.9 (90% match)
|
41
|
+
#
|
42
|
+
# Examples
|
43
|
+
#
|
44
|
+
# region.find!('needle.png')
|
45
|
+
# region.find!('needle.png', 0.5)
|
46
|
+
#
|
47
|
+
# Returns the match or nil if no match is found
|
48
|
+
def find!(filename, similarity = 0.9)
|
49
|
+
begin
|
50
|
+
find(filename, similarity)
|
51
|
+
rescue Sikuli::ImageNotFound => e
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
35
56
|
# Public: search for an image within a Region and return all matches
|
36
57
|
#
|
37
58
|
# TODO: Sort return results so they are always returned in the same order
|
@@ -61,36 +82,40 @@ module Sikuli
|
|
61
82
|
match.highlight if Sikuli::Config.highlight_on_find
|
62
83
|
match
|
63
84
|
end
|
64
|
-
|
85
|
+
regions
|
65
86
|
rescue NativeException => e
|
66
87
|
raise_exception e, filename
|
67
88
|
end
|
68
89
|
end
|
69
90
|
|
70
|
-
# Public:
|
91
|
+
# Public: wait for a match to appear within a region
|
71
92
|
#
|
72
93
|
# filename - A String representation of the filename to match against
|
94
|
+
# time - A Fixnum representing the amount of time to wait defaults
|
95
|
+
# to 2 seconds
|
73
96
|
# similarity - A Float between 0 and 1 representing the threshold for
|
74
97
|
# matching an image. Passing 1 corresponds to a 100% pixel for pixel
|
75
98
|
# match. Defaults to 0.9 (90% match)
|
76
|
-
# time - time in seconds to search before returning false
|
77
99
|
#
|
78
100
|
# Examples
|
79
101
|
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
# region.exists?('needle.png', 0.5, 3)
|
102
|
+
# region.wait('needle.png') # wait for needle.png to appear for up to 1 second
|
103
|
+
# region.wait('needle.png', 10) # wait for needle.png to appear for 10 seconds
|
83
104
|
#
|
84
|
-
# Returns
|
85
|
-
def exists?(filename, similarity = 0.9, time = 0.5)
|
86
|
-
pattern = build_pattern(filename, similarity)
|
87
|
-
@java_obj.exists(pattern, time)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Public: alias for exists?
|
105
|
+
# Returns nothing
|
91
106
|
#
|
92
|
-
#
|
93
|
-
|
107
|
+
# Throws Sikuli::FileNotFound if the file could not be found on the system
|
108
|
+
# Throws Sikuli::ImageNotMatched if no matches are found within the region
|
109
|
+
def wait(filename, time = 2, similarity = 0.9)
|
110
|
+
begin
|
111
|
+
pattern = build_pattern(filename, similarity)
|
112
|
+
match = Region.new(@java_obj.wait(pattern, time))
|
113
|
+
match.highlight if Sikuli::Config.highlight_on_find
|
114
|
+
match
|
115
|
+
rescue NativeException => e
|
116
|
+
raise_exception e, filename
|
117
|
+
end
|
118
|
+
end
|
94
119
|
|
95
120
|
private
|
96
121
|
|
Binary file
|
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
|
@@ -24,19 +24,28 @@ describe Sikuli::Region, "#Searchable" do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should return true if the image is found" do
|
27
|
-
@region.
|
27
|
+
@region.find!("smiley_face.png").should be_an_instance_of Sikuli::Region
|
28
28
|
end
|
29
29
|
|
30
|
-
it "should
|
31
|
-
@region.
|
30
|
+
it "should return nil if the image is not found" do
|
31
|
+
@region.find!("apple.png").should be_nil
|
32
32
|
end
|
33
33
|
|
34
|
-
it "should
|
35
|
-
@region.
|
34
|
+
it "should raise an exception if the file does not exist" do
|
35
|
+
lambda { @region.find!("no_photo.png") }.should
|
36
|
+
raise_error(Sikuli::FileDoesNotExist, "The file 'no_photo.png' does not exist.")
|
36
37
|
end
|
37
38
|
|
38
|
-
|
39
|
-
|
39
|
+
context "#wait" do
|
40
|
+
it "should raise an error if no match is found after a given time" do
|
41
|
+
lambda { @region.wait('apple.png') }.should
|
42
|
+
raise_error(Sikuli::ImageNotFound, "The image 'apple.png' did not match in this region.")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return a Region object when a match is found" do
|
46
|
+
match = @region.wait('green_apple.png', 5)
|
47
|
+
match.should be_an_instance_of Sikuli::Region
|
48
|
+
end
|
40
49
|
end
|
41
50
|
|
42
51
|
context "#find_all" do
|
metadata
CHANGED
@@ -1,106 +1,100 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sikuli
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
|
9
|
-
autorequire:
|
7
|
+
authors:
|
8
|
+
- Chas Lemley
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
version_requirements: *id001
|
12
|
+
date: 2011-12-04 00:00:00.000000000 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
version_requirements: &2086 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
none: false
|
23
|
+
requirement: *2086
|
24
|
+
prerelease: false
|
25
|
+
type: :development
|
27
26
|
description: Sikuli allows you to interact with your application's user interface using image based search to automate user actions.
|
28
|
-
email:
|
29
|
-
|
27
|
+
email:
|
28
|
+
- chas.lemley@gmail.com
|
30
29
|
executables: []
|
31
|
-
|
32
30
|
extensions: []
|
33
|
-
|
34
31
|
extra_rdoc_files: []
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
- spec/support/images/test_area.jpg
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/sikuli.rb
|
38
|
+
- lib/sikuli/app.rb
|
39
|
+
- lib/sikuli/clickable.rb
|
40
|
+
- lib/sikuli/config.rb
|
41
|
+
- lib/sikuli/exception.rb
|
42
|
+
- lib/sikuli/key_code.rb
|
43
|
+
- lib/sikuli/region.rb
|
44
|
+
- lib/sikuli/screen.rb
|
45
|
+
- lib/sikuli/searchable.rb
|
46
|
+
- lib/sikuli/sikuli-script.jar
|
47
|
+
- lib/sikuli/typeable.rb
|
48
|
+
- lib/sikuli/version.rb
|
49
|
+
- sikuli.gemspec
|
50
|
+
- spec/sikuli/app_spec.rb
|
51
|
+
- spec/sikuli/clickable_spec.rb
|
52
|
+
- spec/sikuli/config_spec.rb
|
53
|
+
- spec/sikuli/region_spec.rb
|
54
|
+
- spec/sikuli/screen_spec.rb
|
55
|
+
- spec/sikuli/searchable_spec.rb
|
56
|
+
- spec/sikuli/typeable_spec.rb
|
57
|
+
- spec/spec_helper.rb
|
58
|
+
- spec/support/images/apple.png
|
59
|
+
- spec/support/images/green_apple.png
|
60
|
+
- spec/support/images/smiley_face.png
|
61
|
+
- spec/support/images/test_area.jpg
|
66
62
|
has_rdoc: true
|
67
63
|
homepage: https://github.com/chaslemley/sikuli_ruby
|
68
64
|
licenses: []
|
69
|
-
|
70
|
-
post_install_message:
|
65
|
+
post_install_message:
|
71
66
|
rdoc_options: []
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
76
74
|
none: false
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
82
80
|
none: false
|
83
|
-
requirements:
|
84
|
-
- - ">="
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
version: "0"
|
87
81
|
requirements: []
|
88
|
-
|
89
82
|
rubyforge_project: sikuli
|
90
83
|
rubygems_version: 1.5.1
|
91
|
-
signing_key:
|
84
|
+
signing_key:
|
92
85
|
specification_version: 3
|
93
86
|
summary: Ruby wrapper for Sikuli GUI automation library
|
94
|
-
test_files:
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
87
|
+
test_files:
|
88
|
+
- spec/sikuli/app_spec.rb
|
89
|
+
- spec/sikuli/clickable_spec.rb
|
90
|
+
- spec/sikuli/config_spec.rb
|
91
|
+
- spec/sikuli/region_spec.rb
|
92
|
+
- spec/sikuli/screen_spec.rb
|
93
|
+
- spec/sikuli/searchable_spec.rb
|
94
|
+
- spec/sikuli/typeable_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
- spec/support/images/apple.png
|
97
|
+
- spec/support/images/green_apple.png
|
98
|
+
- spec/support/images/smiley_face.png
|
99
|
+
- spec/support/images/test_area.jpg
|
100
|
+
...
|