sikuli 0.1.5 → 0.1.6

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.
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module Sikuli
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  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
@@ -2,7 +2,7 @@
2
2
  name: sikuli
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.5
5
+ version: 0.1.6
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-07-30 00:00:00 -04:00
13
+ date: 2011-08-02 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency