sikuli 0.1.5 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,7 +7,7 @@ Requirements
7
7
  ------------
8
8
 
9
9
  * JRuby `rvm install jruby`
10
- * [Sikuli X 1.0rc2](http://sikuli.org/)
10
+ * [Sikuli X 1.0rc3](http://sikuli.org/)
11
11
  * OSX
12
12
 
13
13
  Compatibility
@@ -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)
@@ -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
- region = Region.new(@java_obj.find(pattern))
28
- region.highlight if Sikuli::Config.highlight_on_find
29
- return region
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
- return regions
85
+ regions
65
86
  rescue NativeException => e
66
87
  raise_exception e, filename
67
88
  end
68
89
  end
69
90
 
70
- # Public: check if an image is matched within a Region
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
- # region.exists?('needle.png')
81
- # region.exists?('needle.png', 0.5)
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 a Boolean (true if match found, false if not)
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
- # Returns a Boolean (true if match found, false if not)
93
- alias_method :contains?, :exists?
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
@@ -1,3 +1,3 @@
1
1
  module Sikuli
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -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
- # raise_error(Sikuli::ImageNotFound, "The image 'apple.png' did not match in this region.")
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.exists?("smiley_face.png").should be_true
27
+ @region.find!("smiley_face.png").should be_an_instance_of Sikuli::Region
28
28
  end
29
29
 
30
- it "should allow you to call contains?" do
31
- @region.contains?("smiley_face.png").should be_true
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 return false if the image is not found" do
35
- @region.exists?("apple.png").should be_false
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
- it "should return false if the file does not exist" do
39
- @region.exists?("no_photo.png").should be_false
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.5
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.2.1
6
6
  platform: ruby
7
- authors:
8
- - Chas Lemley
9
- autorequire:
7
+ authors:
8
+ - Chas Lemley
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-07-30 00:00:00 -04:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: rspec
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
20
- none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
25
- type: :development
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
- - chas.lemley@gmail.com
27
+ email:
28
+ - chas.lemley@gmail.com
30
29
  executables: []
31
-
32
30
  extensions: []
33
-
34
31
  extra_rdoc_files: []
35
-
36
- files:
37
- - .gitignore
38
- - Gemfile
39
- - README.md
40
- - Rakefile
41
- - lib/sikuli.rb
42
- - lib/sikuli/app.rb
43
- - lib/sikuli/clickable.rb
44
- - lib/sikuli/config.rb
45
- - lib/sikuli/exception.rb
46
- - lib/sikuli/key_code.rb
47
- - lib/sikuli/region.rb
48
- - lib/sikuli/screen.rb
49
- - lib/sikuli/searchable.rb
50
- - lib/sikuli/sikuli-script.jar
51
- - lib/sikuli/typeable.rb
52
- - lib/sikuli/version.rb
53
- - sikuli.gemspec
54
- - spec/sikuli/app_spec.rb
55
- - spec/sikuli/clickable_spec.rb
56
- - spec/sikuli/config_spec.rb
57
- - spec/sikuli/region_spec.rb
58
- - spec/sikuli/screen_spec.rb
59
- - spec/sikuli/searchable_spec.rb
60
- - spec/sikuli/typeable_spec.rb
61
- - spec/spec_helper.rb
62
- - spec/support/images/apple.png
63
- - spec/support/images/green_apple.png
64
- - spec/support/images/smiley_face.png
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
- require_paths:
74
- - lib
75
- required_ruby_version: !ruby/object:Gem::Requirement
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
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: "0"
81
- required_rubygems_version: !ruby/object:Gem::Requirement
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
- - spec/sikuli/app_spec.rb
96
- - spec/sikuli/clickable_spec.rb
97
- - spec/sikuli/config_spec.rb
98
- - spec/sikuli/region_spec.rb
99
- - spec/sikuli/screen_spec.rb
100
- - spec/sikuli/searchable_spec.rb
101
- - spec/sikuli/typeable_spec.rb
102
- - spec/spec_helper.rb
103
- - spec/support/images/apple.png
104
- - spec/support/images/green_apple.png
105
- - spec/support/images/smiley_face.png
106
- - spec/support/images/test_area.jpg
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
+ ...