sikulirc 0.0.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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sikulirc.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Sikulirc
2
+
3
+ Ruby wrapped client API of sikuli server
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sikulirc'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sikulirc
18
+
19
+ ## Usage
20
+
21
+ require 'sikulirc'
22
+
23
+ rs = Sikulirc::RemoteScreen.new("127.0.0.1")
24
+ rs.click "D:\\1.png"
25
+ rs.app_focus "title"
26
+ rs.type_in_field "D:\\field.png", "content"
27
+ rs.page_down
28
+ rs.wait "D:\\field.png"
29
+ rs.find "D:\\field.png"
30
+ rs.set_min_similarity 0.9
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,47 @@
1
+ require 'net/http'
2
+
3
+ module Sikulirc
4
+ module Command
5
+
6
+ COMMANDS = {}
7
+
8
+ def self.load
9
+ Dir.foreach(File.expand_path("../commands/", __FILE__)) do |file_name|
10
+ if file_name == ".." or file_name == "."
11
+ next
12
+ end
13
+ cmd = {}
14
+ File.open(File.expand_path("../commands/#{file_name}", __FILE__)).each_with_index do |line, index|
15
+ cmd["cmd#{index}"] = line.tr("\n", '')
16
+ end
17
+ COMMANDS[file_name] = cmd
18
+ end
19
+ end
20
+
21
+ load
22
+
23
+ def execute_command(uri, cmd_name, args_hash=nil, &block)
24
+ req = Net::HTTP::Post.new(uri.path)
25
+ req.set_form_data(args_hash.nil? ? {"type"=> "sikuli"}.merge(COMMANDS.fetch(cmd_name)) : {"type"=> "sikuli"}.merge(COMMANDS.fetch(cmd_name)).merge(build_arg(args_hash)))
26
+ res = Net::HTTP.start(uri.hostname, uri.port) do |http|
27
+ http.request(req)
28
+ end
29
+ if block_given?
30
+ yield res.body
31
+ else
32
+ res.body
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def build_arg(args_hash)
39
+ arg = Hash['args' => '|']
40
+ args_hash.each do |k, v|
41
+ arg['args'] = arg['args'] + "#{k}=#{v}|"
42
+ end
43
+ arg
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,2 @@
1
+ from sikuli.Sikuli import App
2
+ App.focus(content)
@@ -0,0 +1,4 @@
1
+ from sikuli.Sikuli import Screen
2
+ scr = Screen()
3
+ scr.wait(psc, int(timeout))
4
+ scr.click(psc)
@@ -0,0 +1,3 @@
1
+ from sikuli.Sikuli import Screen
2
+ scr = Screen()
3
+ scr.find(psc)
@@ -0,0 +1,5 @@
1
+ from sikuli.Sikuli import Screen, Key
2
+ import time
3
+ scr=Screen()
4
+ time.sleep(3)
5
+ scr.type(Key.PAGE_DOWN)
@@ -0,0 +1,2 @@
1
+ from sikuli.Sikuli import Settings
2
+ Settings.MinSimilarity=float(similarity)
@@ -0,0 +1,5 @@
1
+ from sikuli.Sikuli import Screen, KEY_CTRL, Key
2
+ scr = Screen()
3
+ scr.type(psc, 'a', KEY_CTRL)
4
+ scr.type(Key.BACKSPACE)
5
+ scr.paste(psc, content)
@@ -0,0 +1,3 @@
1
+ from sikuli.Sikuli import Screen
2
+ scr = Screen()
3
+ scr.wait(psc, int(timeout))
@@ -0,0 +1,7 @@
1
+ module Sikulirc
2
+
3
+ class ImageNotFound < StandardError; end
4
+
5
+ class CommandError < StandardError; end
6
+
7
+ end
@@ -0,0 +1,61 @@
1
+ # require "sikulirc/command"
2
+
3
+ require "rexml/document"
4
+ require "uri"
5
+
6
+ module Sikulirc
7
+ class RemoteScreen
8
+ include Command
9
+ include REXML
10
+
11
+ def initialize(server, port="9000")
12
+ @serv = URI("http://#{server}:#{port}/script.do")
13
+ end
14
+
15
+ def app_focus(app)
16
+ execute_command(@serv, 'set_min_similarity', :content => app)
17
+ end
18
+
19
+ def page_down
20
+ execute_command(@serv, "page_down")
21
+ end
22
+
23
+ def set_min_similarity(similarity = 0.7)
24
+ execute_command(@serv, 'set_min_similarity', :content => similarity)
25
+ end
26
+
27
+ def click(psc, timeout = 10)
28
+ execute_command(@serv, "click", :psc => psc, :timeout => timeout) { |xml_dump| process_result(xml_dump, psc) }
29
+ end
30
+
31
+ def find(psc)
32
+ execute_command(@serv, 'find', :psc => psc) { |xml_dump| process_result(xml_dump, psc) }
33
+ end
34
+
35
+ def type_in_field(psc, content)
36
+ execute_command(@serv, 'type_in_field', :psc => psc, :content => content) { |xml_dump| process_result(xml_dump, psc) }
37
+ end
38
+
39
+ def wait(psc, timeout = 30)
40
+ execute_command(@serv, "wait", :psc => psc, :timeout => timeout) { |xml_dump| process_result(xml_dump, psc) }
41
+ end
42
+
43
+ private
44
+
45
+ def raise_exception(exception_message, psc)
46
+ if exception_message.include? "FindFailed: can not find"
47
+ raise Sikulirc::ImageNotFound, "The image '#{psc}' does not exist."
48
+ else
49
+ raise Sikulirc::CommandError, "somthing wrong of the command "
50
+ end
51
+ end
52
+
53
+ def process_result(xml_dump, psc)
54
+ doc = Document.new(xml_dump)
55
+ if doc.elements["/script/status"].text == "FAIL"
56
+ raise_exception(doc.elements["//message"].text, psc)
57
+ end
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Sikulirc
2
+ VERSION = "0.0.1"
3
+ end
data/lib/sikulirc.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "sikulirc/version"
2
+
3
+ require "sikulirc/command"
4
+ require "sikulirc/exception"
5
+ require "sikulirc/remote_screen"
6
+
7
+ module Sikulirc
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sikulirc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Enix Shen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-01 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Allows you to call sikuli remote server.
15
+ email:
16
+ - enix12enix@hotmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/sikulirc/command.rb
22
+ - lib/sikulirc/commands/app_focus
23
+ - lib/sikulirc/commands/click
24
+ - lib/sikulirc/commands/find
25
+ - lib/sikulirc/commands/page_down
26
+ - lib/sikulirc/commands/set_min_similarity
27
+ - lib/sikulirc/commands/type_in_field
28
+ - lib/sikulirc/commands/wait
29
+ - lib/sikulirc/exception.rb
30
+ - lib/sikulirc/remote_screen.rb
31
+ - lib/sikulirc/version.rb
32
+ - lib/sikulirc.rb
33
+ - Gemfile
34
+ - LICENSE
35
+ - Rakefile
36
+ - README.md
37
+ homepage: http://github.com/enix12enix/sikulirc
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.8.24
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Ruby wrapped for sikuli remote server client api
61
+ test_files: []