sikuli 0.1.3 → 0.1.4
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/.gitignore +1 -0
- data/README.md +22 -6
- data/lib/sikuli/app.rb +3 -3
- data/lib/sikuli/clickable.rb +6 -6
- data/lib/sikuli/config.rb +24 -19
- data/lib/sikuli/region.rb +7 -7
- data/lib/sikuli/searchable.rb +6 -4
- data/lib/sikuli/version.rb +1 -1
- data/spec/sikuli/app_spec.rb +2 -2
- data/spec/sikuli/clickable_spec.rb +7 -8
- data/spec/sikuli/config_spec.rb +17 -7
- data/spec/sikuli/screen_spec.rb +6 -4
- data/spec/sikuli/searchable_spec.rb +7 -8
- data/spec/sikuli/typeable_spec.rb +6 -8
- data/spec/spec_helper.rb +3 -3
- metadata +2 -4
- data/spec/support/images/.DS_Store +0 -0
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -10,28 +10,44 @@ Requirements
|
|
10
10
|
* [Sikuli X 1.0rc2](http://sikuli.org/)
|
11
11
|
* OSX
|
12
12
|
|
13
|
+
Compatibility
|
14
|
+
-------------
|
15
|
+
It's recommended to use JRuby ~> 1.6.0 and run it in 1.9 mode to get unicode characters working
|
16
|
+
as expected.
|
17
|
+
|
18
|
+
```
|
19
|
+
export JRUBY_OPTS=--1.9
|
20
|
+
```
|
21
|
+
|
13
22
|
Installation
|
14
23
|
------------
|
15
24
|
|
16
25
|
gem install sikuli
|
17
|
-
|
26
|
+
|
18
27
|
Usage
|
19
28
|
-----
|
20
|
-
|
29
|
+
|
21
30
|
require 'java'
|
22
31
|
require 'sikuli'
|
23
|
-
|
24
|
-
Sikuli::Config.run do |config|
|
32
|
+
|
33
|
+
Sikuli::Config.run do |config|
|
25
34
|
config.image_path = "#{Dir.pwd}/images/"
|
26
35
|
config.logging = false
|
27
36
|
end
|
28
|
-
|
37
|
+
|
29
38
|
screen = Sikuli::Screen.new
|
30
39
|
screen.click(10, 10) # should open your apple menu
|
31
|
-
|
40
|
+
|
32
41
|
app = Sikuli::App.new("iPhone Simulator")
|
33
42
|
app.window.click('ui_element.png') if app.window.exists?('ui_element.png')
|
34
43
|
|
44
|
+
Running the test suite
|
45
|
+
----------------------
|
46
|
+
|
47
|
+
1. You need to open `test_area.jpg` in **Preview** from `spec/support/images/` directory
|
48
|
+
before running tests.
|
49
|
+
2. You also need to open the **TextEdit** app
|
50
|
+
|
35
51
|
Examples
|
36
52
|
--------
|
37
53
|
|
data/lib/sikuli/app.rb
CHANGED
data/lib/sikuli/clickable.rb
CHANGED
@@ -15,7 +15,7 @@ module Sikuli
|
|
15
15
|
else raise ArgumentError
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def dragDrop(start_x, start_y, end_x, end_y)
|
20
20
|
@java_obj.dragDrop(
|
21
21
|
org.sikuli.script::Location.new(start_x, start_y).offset(x(), y()),
|
@@ -23,10 +23,10 @@ module Sikuli
|
|
23
23
|
0
|
24
24
|
)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
private
|
28
|
-
|
29
|
-
def click_image(filename, opts = {})
|
28
|
+
|
29
|
+
def click_image(filename, opts = {})
|
30
30
|
begin
|
31
31
|
if opts[:double]
|
32
32
|
@java_obj.doubleClick(filename, 0)
|
@@ -37,7 +37,7 @@ module Sikuli
|
|
37
37
|
raise "File Not Found: #{filename}"
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def click_point(x, y, opts = {})
|
42
42
|
if opts[:double]
|
43
43
|
@java_obj.doubleClick(org.sikuli.script::Location.new(x, y).offset(x(), y()), 0)
|
@@ -46,4 +46,4 @@ module Sikuli
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
|
-
end
|
49
|
+
end
|
data/lib/sikuli/config.rb
CHANGED
@@ -1,24 +1,29 @@
|
|
1
1
|
module Sikuli
|
2
2
|
class Config
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
3
|
+
class << self
|
4
|
+
attr_accessor :highlight_on_find
|
5
|
+
|
6
|
+
def image_path
|
7
|
+
java.lang.System.getProperty("SIKULI_IMAGE_PATH")
|
8
|
+
end
|
9
|
+
|
10
|
+
def image_path=(path)
|
11
|
+
java.lang.System.setProperty("SIKULI_IMAGE_PATH", path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def logging=(boolean)
|
15
|
+
return unless [TrueClass, FalseClass].include? boolean.class
|
16
|
+
org.sikuli.script::Settings.InfoLogs = boolean
|
17
|
+
org.sikuli.script::Settings.ActionLogs = boolean
|
18
|
+
org.sikuli.script::Settings.DebugLogs = boolean
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(*args)
|
22
|
+
if block_given?
|
23
|
+
yield self
|
24
|
+
end
|
21
25
|
end
|
26
|
+
|
22
27
|
end
|
23
28
|
end
|
24
|
-
end
|
29
|
+
end
|
data/lib/sikuli/region.rb
CHANGED
@@ -7,29 +7,29 @@ module Sikuli
|
|
7
7
|
include Clickable
|
8
8
|
include Typeable
|
9
9
|
include Searchable
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(*args)
|
12
12
|
@java_obj = org.sikuli.script::Region.new(*args)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def highlight(seconds = 1)
|
16
16
|
@java_obj.highlight(seconds)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def x
|
20
20
|
@java_obj.x()
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def y
|
24
24
|
@java_obj.y()
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def width
|
28
28
|
@java_obj.w()
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def height
|
32
32
|
@java_obj.h()
|
33
33
|
end
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|
data/lib/sikuli/searchable.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
module Sikuli
|
2
|
-
module Searchable
|
2
|
+
module Searchable
|
3
3
|
def find(filename, similarity = 0.9)
|
4
4
|
begin
|
5
5
|
pattern = org.sikuli.script::Pattern.new(filename).similar(similarity)
|
6
|
-
Region.new(@java_obj.find(pattern))
|
6
|
+
region = Region.new(@java_obj.find(pattern))
|
7
|
+
region.highlight if Sikuli::Config.highlight_on_find
|
8
|
+
return region
|
7
9
|
rescue
|
8
10
|
raise "File Not Found: #{filename}"
|
9
11
|
end
|
10
12
|
end
|
11
|
-
|
13
|
+
|
12
14
|
def exists?(filename, similarity = 0.9, time = 0.5)
|
13
15
|
pattern = org.sikuli.script::Pattern.new(filename).similar(similarity)
|
14
16
|
@java_obj.exists(pattern, time)
|
15
17
|
end
|
16
18
|
alias_method :contains?, :exists?
|
17
19
|
end
|
18
|
-
end
|
20
|
+
end
|
data/lib/sikuli/version.rb
CHANGED
data/spec/sikuli/app_spec.rb
CHANGED
@@ -2,22 +2,21 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Sikuli::Region, "#Clickable" do
|
4
4
|
before(:all) do
|
5
|
-
#open the file 'test_area.jpg' in Preview at zoom level 0
|
6
5
|
@region = setup_test_area
|
7
6
|
end
|
8
|
-
|
7
|
+
|
9
8
|
it "should perform a click at 10, 10" do
|
10
9
|
lambda { @region.click(12, 12) }.should_not raise_error
|
11
10
|
end
|
12
|
-
|
13
|
-
it "should perform a double click 10, 1040" do
|
11
|
+
|
12
|
+
it "should perform a double click 10, 1040" do
|
14
13
|
lambda { @region.doubleClick(12, 491) }.should_not raise_error
|
15
14
|
end
|
16
|
-
|
15
|
+
|
17
16
|
it "should perform a double click on an image" do
|
18
17
|
lambda { @region.doubleClick("smiley_face.png") }.should_not raise_error
|
19
18
|
end
|
20
|
-
|
19
|
+
|
21
20
|
it "should perform a drag and drop" do
|
22
21
|
lambda { @region.dragDrop(12, 12, 491, 491) }.should_not raise_error
|
23
22
|
end
|
@@ -25,8 +24,8 @@ describe Sikuli::Region, "#Clickable" do
|
|
25
24
|
it "should perform a click on an image" do
|
26
25
|
lambda { @region.click("smiley_face.png") }.should_not raise_error
|
27
26
|
end
|
28
|
-
|
27
|
+
|
29
28
|
it "should not perform a click on an image that is outside of the region" do
|
30
29
|
lambda { @region.click("apple.png")}.should raise_error
|
31
30
|
end
|
32
|
-
end
|
31
|
+
end
|
data/spec/sikuli/config_spec.rb
CHANGED
@@ -5,33 +5,43 @@ describe Sikuli::Config do
|
|
5
5
|
Sikuli::Config.image_path = ""
|
6
6
|
java.lang.System.getProperty("SIKULI_IMAGE_PATH").should == ""
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it "should allow a path to be added" do
|
10
10
|
Sikuli::Config.run do |config|
|
11
11
|
config.image_path = '/Users/images/'
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
java.lang.System.getProperty("SIKULI_IMAGE_PATH").should == '/Users/images/'
|
15
15
|
Sikuli::Config.image_path.should == '/Users/images/'
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "should allow logging to be turned on" do
|
19
19
|
Sikuli::Config.run do |config|
|
20
20
|
config.logging = true
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
org.sikuli.script::Settings.InfoLogs.should be_true
|
24
24
|
org.sikuli.script::Settings.ActionLogs.should be_true
|
25
25
|
org.sikuli.script::Settings.DebugLogs.should be_true
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it "should allow logging to be turned off" do
|
29
29
|
Sikuli::Config.run do |config|
|
30
30
|
config.logging = false
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
org.sikuli.script::Settings.InfoLogs.should be_false
|
34
34
|
org.sikuli.script::Settings.ActionLogs.should be_false
|
35
35
|
org.sikuli.script::Settings.DebugLogs.should be_false
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
|
+
it "should allow us to turn off highlighting on find" do
|
39
|
+
Sikuli::Config.highlight_on_find = false
|
40
|
+
Sikuli::Config.highlight_on_find.should be_false
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should allow us to turn on highlighting on find" do
|
44
|
+
Sikuli::Config.highlight_on_find = true
|
45
|
+
Sikuli::Config.highlight_on_find.should be_true
|
46
|
+
end
|
47
|
+
end
|
data/spec/sikuli/screen_spec.rb
CHANGED
@@ -2,9 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Sikuli::Screen, 'when initialized' do
|
4
4
|
subject { Sikuli::Screen.new }
|
5
|
-
|
5
|
+
|
6
6
|
its(:x) { should == 0 }
|
7
7
|
its(:y) { should == 0 }
|
8
|
-
its(:width) { should
|
9
|
-
its(:
|
10
|
-
|
8
|
+
its(:width) { should > 0 } # screen's resolution
|
9
|
+
its(:width) { should be_instance_of Fixnum }
|
10
|
+
its(:height) { should > 0 } # screen's resolution
|
11
|
+
its(:height) { should be_instance_of Fixnum }
|
12
|
+
end
|
@@ -2,31 +2,30 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Sikuli::Region, "#Searchable" do
|
4
4
|
before(:all) do
|
5
|
-
#open the file 'test_area.jpg' in Preview at zoom level 0
|
6
5
|
@region = setup_test_area
|
7
6
|
end
|
8
|
-
|
7
|
+
|
9
8
|
it "should find an image within the region" do
|
10
9
|
@region.find("smiley_face.png").should_not be_nil
|
11
10
|
end
|
12
|
-
|
11
|
+
|
13
12
|
it "should return a region containing the found image" do
|
14
13
|
@region.find("smiley_face.png").should be_an_instance_of Sikuli::Region
|
15
14
|
end
|
16
|
-
|
15
|
+
|
17
16
|
it "should not find an image that is not in the region" do
|
18
17
|
lambda { @region.find("apple.png") }.should raise_error
|
19
18
|
end
|
20
|
-
|
19
|
+
|
21
20
|
it "should return true if the image is found" do
|
22
21
|
@region.exists?("smiley_face.png").should be_true
|
23
22
|
end
|
24
|
-
|
23
|
+
|
25
24
|
it "should allow you to call contains?" do
|
26
25
|
@region.contains?("smiley_face.png").should be_true
|
27
26
|
end
|
28
|
-
|
27
|
+
|
29
28
|
it "should return false if the image is not found" do
|
30
29
|
@region.exists?("apple.png").should be_false
|
31
30
|
end
|
32
|
-
end
|
31
|
+
end
|
@@ -2,25 +2,23 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Sikuli::Region, "#Typeable" do
|
4
4
|
before(:all) do
|
5
|
-
app = Sikuli::App.new("
|
5
|
+
app = Sikuli::App.new("TextEdit")
|
6
6
|
app.focus
|
7
|
-
@region = app.window
|
7
|
+
@region = app.window
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
context "modifying text input with" do
|
11
11
|
it "apple key" do
|
12
12
|
@region.type("n", Sikuli::KEY_CMD)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
it "shift key" do
|
16
16
|
@region.type("this should be lower case")
|
17
17
|
@region.type("this should be upper case", Sikuli::KEY_SHIFT)
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
context "unicode characters" do
|
22
|
-
# tell JRuby to run in 1.9 mode
|
23
|
-
# http://stackoverflow.com/questions/4755900/how-to-make-jruby-1-6-default-to-ruby-1-9
|
24
22
|
it("backspace") { @region.type(Sikuli::KEY_BACKSPACE * 50) }
|
25
23
|
it("return") { @region.type(Sikuli::KEY_RETURN) }
|
26
24
|
xit("up arrow") { @region.type(Sikuli::UP_ARROW) }
|
@@ -28,4 +26,4 @@ describe Sikuli::Region, "#Typeable" do
|
|
28
26
|
it("down arrow") { @region.type(Sikuli::DOWN_ARROW) }
|
29
27
|
it("right arrow") { @region.type(Sikuli::RIGHT_ARROW) }
|
30
28
|
end
|
31
|
-
end
|
29
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,9 +11,9 @@ def setup_test_area
|
|
11
11
|
app = Sikuli::App.new('Preview')
|
12
12
|
app.focus()
|
13
13
|
center = screen.find("#{Dir.pwd}/spec/support/images/smiley_face.png")
|
14
|
-
|
14
|
+
|
15
15
|
test_area = Sikuli::Region.new(center.x - 212, center.y - 212, 503, 503)
|
16
16
|
test_area.highlight
|
17
|
-
|
17
|
+
|
18
18
|
test_area
|
19
|
-
end
|
19
|
+
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.4
|
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-
|
13
|
+
date: 2011-07-28 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -58,7 +58,6 @@ files:
|
|
58
58
|
- spec/sikuli/searchable_spec.rb
|
59
59
|
- spec/sikuli/typeable_spec.rb
|
60
60
|
- spec/spec_helper.rb
|
61
|
-
- spec/support/images/.DS_Store
|
62
61
|
- spec/support/images/apple.png
|
63
62
|
- spec/support/images/smiley_face.png
|
64
63
|
- spec/support/images/test_area.jpg
|
@@ -99,7 +98,6 @@ test_files:
|
|
99
98
|
- spec/sikuli/searchable_spec.rb
|
100
99
|
- spec/sikuli/typeable_spec.rb
|
101
100
|
- spec/spec_helper.rb
|
102
|
-
- spec/support/images/.DS_Store
|
103
101
|
- spec/support/images/apple.png
|
104
102
|
- spec/support/images/smiley_face.png
|
105
103
|
- spec/support/images/test_area.jpg
|
Binary file
|