sikuli 0.1.0

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sikuli_ruby.gemspec
4
+ gemspec
@@ -0,0 +1,32 @@
1
+ Sikuli Ruby
2
+ ===========
3
+
4
+ [Sikuli](http://sikuli.org/) allows you to interact with your application's user interface using image based search to automate user actions.
5
+
6
+ Requirements
7
+ ------------
8
+
9
+ * JRuby (rvm install jruby)
10
+ * [Sikuli X 1.0rc2](http://sikuli.org/)
11
+ * OSX
12
+
13
+ Installation
14
+ ------------
15
+
16
+ gem install sikuli
17
+
18
+ Usage
19
+ -----
20
+
21
+ require 'java'
22
+ require 'sikuli'
23
+
24
+ screen = Sikuli::Screen.new
25
+ screen.click(10, 10) # should open your apple menu
26
+
27
+ app = Sikuli::App.new("iPhone Simulator")
28
+ app.window.click('ui_element.png')
29
+
30
+ if !app.window.exists?('other_ui_element.png')
31
+ raise "Error!"
32
+ end
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,27 @@
1
+ require "sikuli/sikuli-script.jar"
2
+ require "sikuli/version"
3
+
4
+ require "sikuli/app"
5
+ require "sikuli/region"
6
+ require "sikuli/screen"
7
+
8
+ module Sikuli
9
+ def self.getImagePath
10
+ paths = java.lang.System.getProperty("SIKULI_IMAGE_PATH") || ""
11
+ paths.split(":")
12
+ end
13
+
14
+ def self.addImagePath(path)
15
+ paths = self.getImagePath
16
+ paths << path
17
+
18
+ java.lang.System.setProperty("SIKULI_IMAGE_PATH", paths.join(':'))
19
+ end
20
+
21
+ def self.logging=(boolean)
22
+ return unless [TrueClass, FalseClass].include? boolean.class
23
+ org.sikuli.script::Settings.InfoLogs = boolean
24
+ org.sikuli.script::Settings.ActionLogs = boolean
25
+ org.sikuli.script::Settings.DebugLogs = boolean
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ module Sikuli
2
+ class App
3
+ def initialize(app_name)
4
+ @java_obj = org.sikuli.script::App.new(app_name)
5
+ end
6
+
7
+ def focus
8
+ @java_obj.focus()
9
+ end
10
+
11
+ def window
12
+ Region.new(@java_obj.window())
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,49 @@
1
+ module Sikuli
2
+ module Clickable
3
+ def click(*args)
4
+ case args.length
5
+ when 1 then click_image(args[0])
6
+ when 2 then click_point(args[0], args[1])
7
+ else raise ArgumentError
8
+ end
9
+ end
10
+
11
+ def doubleClick(*args)
12
+ case args.length
13
+ when 1 then click_image(args[0], { :double => true })
14
+ when 2 then click_point(args[0], args[1], {:double => true })
15
+ else raise ArgumentError
16
+ end
17
+ end
18
+
19
+ def dragDrop(start_x, start_y, end_x, end_y)
20
+ @java_obj.dragDrop(
21
+ org.sikuli.script::Location.new(start_x, start_y).offset(x(), y()),
22
+ org.sikuli.script::Location.new(end_x, end_y).offset(x(), y()),
23
+ 0
24
+ )
25
+ end
26
+
27
+ private
28
+
29
+ def click_image(filename, opts = {})
30
+ begin
31
+ if opts[:double]
32
+ @java_obj.doubleClick(filename, 0)
33
+ else
34
+ @java_obj.click(filename, 0)
35
+ end
36
+ rescue
37
+ raise "File Not Found: #{filename}"
38
+ end
39
+ end
40
+
41
+ def click_point(x, y, opts = {})
42
+ if opts[:double]
43
+ @java_obj.doubleClick(org.sikuli.script::Location.new(x, y).offset(x(), y()), 0)
44
+ else
45
+ @java_obj.click(org.sikuli.script::Location.new(x, y).offset(x(), y()), 0)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,35 @@
1
+ require "sikuli/clickable"
2
+ require "sikuli/typeable"
3
+ require "sikuli/searchable"
4
+
5
+ module Sikuli
6
+ class Region
7
+ include Clickable
8
+ include Typeable
9
+ include Searchable
10
+
11
+ def initialize(*args)
12
+ @java_obj = org.sikuli.script::Region.new(*args)
13
+ end
14
+
15
+ def highlight(seconds = 1)
16
+ @java_obj.highlight(seconds)
17
+ end
18
+
19
+ def x
20
+ @java_obj.x()
21
+ end
22
+
23
+ def y
24
+ @java_obj.y()
25
+ end
26
+
27
+ def width
28
+ @java_obj.w()
29
+ end
30
+
31
+ def height
32
+ @java_obj.h()
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ module Sikuli
2
+ class Screen < Region
3
+ def initialize
4
+ @java_obj = org.sikuli.script::Screen.new()
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module Sikuli
2
+ module Searchable
3
+ def find(filename, similarity = 0.9)
4
+ begin
5
+ pattern = org.sikuli.script::Pattern.new(filename).similar(similarity)
6
+ Region.new(@java_obj.find(pattern))
7
+ rescue
8
+ raise "File Not Found: #{filename}"
9
+ end
10
+ end
11
+
12
+ def exists?(filename, similarity = 0.9, time = 0.5)
13
+ pattern = org.sikuli.script::Pattern.new(filename).similar(similarity)
14
+ @java_obj.exists(pattern, time)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module Sikuli
2
+ module Typeable
3
+ def type(text)
4
+ @java_obj.type(nil, text, 0)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Sikuli
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sikuli/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.add_development_dependency "rspec"
7
+ s.name = "sikuli"
8
+ s.version = Sikuli::VERSION
9
+ s.authors = ["Chas Lemley"]
10
+ s.email = ["chas.lemley@gmail.com"]
11
+ s.homepage = "https://github.com/chaslemley/sikuli_ruby"
12
+ s.summary = %q{Ruby wrapper for Sikuli GUI automation library}
13
+ s.description = %q{Sikuli allows you to interact with your application's user interface using image based search to automate user actions.}
14
+
15
+ s.rubyforge_project = "sikuli"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sikuli::App do
4
+ subject { Sikuli::App.new('Finder') }
5
+
6
+ its(:window) { should be_an_instance_of Sikuli::Region }
7
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sikuli::Region, 'when initialized with a rectangle' do
4
+ subject { Sikuli::Region.new(10, 15, 250, 400) }
5
+ its(:x) { should == 10 }
6
+ its(:y) { should == 15 }
7
+ its(:width) { should == 250 }
8
+ its(:height) { should == 400 }
9
+ end
10
+
11
+ describe Sikuli::Region, 'when initialzed with a sikuli region' do
12
+ subject { Sikuli::Region.new org.sikuli.script::Region.new(11, 16, 251, 401) }
13
+ its(:x) { should == 11 }
14
+ its(:y) { should == 16 }
15
+ its(:width) { should == 251 }
16
+ its(:height) { should == 401 }
17
+ end
18
+
19
+ describe Sikuli::Region, "#Clickable" do
20
+ before(:all) do
21
+ #open the file 'test_area.jpg' in Preview at zoom level 0
22
+ @region = setup_test_area
23
+ end
24
+
25
+ it "should perform a click at 10, 10" do
26
+ lambda { @region.click(12, 12) }.should_not raise_error
27
+ end
28
+
29
+ it "should perform a double click 10, 1040" do
30
+ lambda { @region.doubleClick(12, 491) }.should_not raise_error
31
+ end
32
+
33
+ it "should perform a double click on an image" do
34
+ lambda { @region.doubleClick("smiley_face.png") }.should_not raise_error
35
+ end
36
+
37
+ it "should perform a drag and drop" do
38
+ lambda { @region.dragDrop(12, 12, 491, 491) }.should_not raise_error
39
+ end
40
+
41
+ it "should perform a click on an image" do
42
+ lambda { @region.click("smiley_face.png") }.should_not raise_error
43
+ end
44
+
45
+ it "should not perform a click on an image that is outside of the region" do
46
+ lambda { @region.click("apple.png")}.should raise_error
47
+ end
48
+ end
49
+
50
+ describe Sikuli::Region, "#Searchable" do
51
+ before(:all) do
52
+ #open the file 'test_area.jpg' in Preview at zoom level 0
53
+ @region = setup_test_area
54
+ end
55
+
56
+ it "should find an image within the region" do
57
+ @region.find("smiley_face.png").should_not be_nil
58
+ end
59
+
60
+ it "should return a region containing the found image" do
61
+ @region.find("smiley_face.png").should be_an_instance_of Sikuli::Region
62
+ end
63
+
64
+ it "should not find an image that is not in the region" do
65
+ lambda { @region.find("apple.png") }.should raise_error
66
+ end
67
+
68
+ it "should return true if the image is found" do
69
+ @region.exists?("smiley_face.png").should be_true
70
+ end
71
+
72
+ it "should return false if the image is not found" do
73
+ @region.exists?("apple.png").should be_false
74
+ end
75
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sikuli::Screen, 'when initialized' do
4
+ subject { Sikuli::Screen.new }
5
+
6
+ its(:x) { should == 0 }
7
+ its(:y) { should == 0 }
8
+ its(:width) { should == 1680 } # screen's resolution
9
+ its(:height) { should == 1050 } # screen's resolution
10
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sikuli, "image path" do
4
+ it "should retain a list of directories to search in for images" do
5
+ Sikuli.getImagePath().should == []
6
+ end
7
+
8
+ it "should allow a path to be added" do
9
+ Sikuli.addImagePath('/Users/images/')
10
+ Sikuli.getImagePath().should == ['/Users/images/']
11
+ end
12
+
13
+ it "should allow logging to be turned off" do
14
+ Sikuli.logging = false
15
+
16
+ org.sikuli.script::Settings.InfoLogs.should be_false
17
+ org.sikuli.script::Settings.ActionLogs.should be_false
18
+ org.sikuli.script::Settings.DebugLogs.should be_false
19
+ end
20
+
21
+ it "should allow logging to be turned on" do
22
+ Sikuli.logging = true
23
+
24
+ org.sikuli.script::Settings.InfoLogs.should be_true
25
+ org.sikuli.script::Settings.ActionLogs.should be_true
26
+ org.sikuli.script::Settings.DebugLogs.should be_true
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ require 'java'
2
+
3
+ require 'rspec'
4
+ require 'sikuli'
5
+
6
+ Sikuli.logging = false
7
+
8
+ def setup_test_area
9
+ Sikuli.addImagePath("#{Dir.pwd}/spec/support/images/")
10
+ screen = Sikuli::Screen.new
11
+ app = Sikuli::App.new('Preview')
12
+ app.focus()
13
+ center = screen.find("#{Dir.pwd}/spec/support/images/smiley_face.png")
14
+
15
+ test_area = Sikuli::Region.new(center.x - 212, center.y - 212, 503, 503)
16
+ test_area.highlight
17
+
18
+ test_area
19
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sikuli
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Chas Lemley
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-24 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
27
+ 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
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ 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/region.rb
45
+ - lib/sikuli/screen.rb
46
+ - lib/sikuli/searchable.rb
47
+ - lib/sikuli/sikuli-script.jar
48
+ - lib/sikuli/typeable.rb
49
+ - lib/sikuli/version.rb
50
+ - sikuli.gemspec
51
+ - spec/sikuli/app_spec.rb
52
+ - spec/sikuli/region_spec.rb
53
+ - spec/sikuli/screen_spec.rb
54
+ - spec/sikuli_spec.rb
55
+ - spec/spec_helper.rb
56
+ - spec/support/images/.DS_Store
57
+ - spec/support/images/apple.png
58
+ - spec/support/images/smiley_face.png
59
+ - spec/support/images/test_area.jpg
60
+ has_rdoc: true
61
+ homepage: https://github.com/chaslemley/sikuli_ruby
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project: sikuli
84
+ rubygems_version: 1.5.1
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Ruby wrapper for Sikuli GUI automation library
88
+ test_files:
89
+ - spec/sikuli/app_spec.rb
90
+ - spec/sikuli/region_spec.rb
91
+ - spec/sikuli/screen_spec.rb
92
+ - spec/sikuli_spec.rb
93
+ - spec/spec_helper.rb
94
+ - spec/support/images/.DS_Store
95
+ - spec/support/images/apple.png
96
+ - spec/support/images/smiley_face.png
97
+ - spec/support/images/test_area.jpg