sikulinewrc 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 +4 -0
- data/LICENSE +22 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/lib/sikulirc.rb +9 -0
- data/lib/sikulirc/command.rb +47 -0
- data/lib/sikulirc/commands/app_focus +2 -0
- data/lib/sikulirc/commands/click +4 -0
- data/lib/sikulirc/commands/drag_drop +5 -0
- data/lib/sikulirc/commands/find +3 -0
- data/lib/sikulirc/commands/page_down +5 -0
- data/lib/sikulirc/commands/set_min_similarity +2 -0
- data/lib/sikulirc/commands/type_in_field +5 -0
- data/lib/sikulirc/commands/wait +3 -0
- data/lib/sikulirc/exception.rb +7 -0
- data/lib/sikulirc/remote_screen.rb +65 -0
- data/lib/sikulirc/version.rb +3 -0
- data/sikulinewrc.gemspec +18 -0
- metadata +63 -0
data/Gemfile
ADDED
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,40 @@
|
|
1
|
+
# Sikulirc
|
2
|
+
|
3
|
+
Ruby wrapped client API of sikuli server
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
To get Sikuli Server, Please go to http://github.com/enix12enix/sikuli-remote-control and follow instruction
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'sikulirc', :git => 'git://github.com/powerkx/sikulirc.git'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install sikulirc
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
require 'sikulirc'
|
24
|
+
|
25
|
+
rs = Sikulirc::RemoteScreen.new("127.0.0.1")
|
26
|
+
rs.click "D:\\1.png"
|
27
|
+
rs.app_focus "title"
|
28
|
+
rs.type_in_field "D:\\field.png", "content"
|
29
|
+
rs.page_down
|
30
|
+
rs.wait "D:\\field.png"
|
31
|
+
rs.find "D:\\field.png"
|
32
|
+
rs.set_min_similarity 0.9
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/sikulirc.rb
ADDED
@@ -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,65 @@
|
|
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', :similarity => similarity)
|
25
|
+
end
|
26
|
+
|
27
|
+
def click(psc, timeout = 120)
|
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 = 120)
|
40
|
+
execute_command(@serv, "wait", :psc => psc, :timeout => timeout) { |xml_dump| process_result(xml_dump, psc) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def drag_drop(psc, xoffset, yoffset)
|
44
|
+
execute_command(@serv, "drag_drop", :psc => psc, :xoffset => xoffset, :yoffset => yoffset)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def raise_exception(exception_message, psc)
|
50
|
+
if exception_message.include? "FindFailed: can not find"
|
51
|
+
raise Sikulirc::ImageNotFound, "The image '#{psc}' does not exist."
|
52
|
+
else
|
53
|
+
raise Sikulirc::CommandError, "Something wrong with the command.\n\n#{exception_message}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def process_result(xml_dump, psc)
|
58
|
+
doc = Document.new(xml_dump)
|
59
|
+
if doc.elements["/script/status"].text == "FAIL"
|
60
|
+
raise_exception(doc.elements["//message"].text, psc)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
data/sikulinewrc.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
$:.push File.expand_path("../lib", __FILE__)
|
5
|
+
require "sikulirc/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.authors = ["David Wang"]
|
9
|
+
gem.email = ["davidwangm@hotmail.com"]
|
10
|
+
gem.description = %q{Allows you to call sikuli remote server.}
|
11
|
+
gem.summary = %q{Ruby wrapped for sikuli remote server client api}
|
12
|
+
gem.homepage = "http://github.com/powerkx/sikulinewrc"
|
13
|
+
|
14
|
+
gem.files = FileList['lib/**/*', 'bin/*', '[A-Z]*', 'test/**/*'].to_a
|
15
|
+
gem.name = "sikulinewrc"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = Sikulirc::VERSION
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sikulinewrc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David Wang
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-17 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Allows you to call sikuli remote server.
|
15
|
+
email:
|
16
|
+
- davidwangm@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/drag_drop
|
25
|
+
- lib/sikulirc/commands/find
|
26
|
+
- lib/sikulirc/commands/page_down
|
27
|
+
- lib/sikulirc/commands/set_min_similarity
|
28
|
+
- lib/sikulirc/commands/type_in_field
|
29
|
+
- lib/sikulirc/commands/wait
|
30
|
+
- lib/sikulirc/exception.rb
|
31
|
+
- lib/sikulirc/remote_screen.rb
|
32
|
+
- lib/sikulirc/version.rb
|
33
|
+
- lib/sikulirc.rb
|
34
|
+
- Gemfile
|
35
|
+
- LICENSE
|
36
|
+
- Rakefile
|
37
|
+
- README.md
|
38
|
+
- sikulinewrc.gemspec
|
39
|
+
homepage: http://github.com/powerkx/sikulinewrc
|
40
|
+
licenses: []
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.8.28
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Ruby wrapped for sikuli remote server client api
|
63
|
+
test_files: []
|