robotok 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -0
- data/bin/robotok +185 -0
- data/lib/robotok/version.rb +3 -0
- data/lib/robotok.rb +7 -0
- data/robotok.rdoc +5 -0
- metadata +138 -0
data/README.rdoc
ADDED
data/bin/robotok
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'gli'
|
3
|
+
begin # XXX: Remove this begin/rescue before distributing your app
|
4
|
+
require 'robotok'
|
5
|
+
rescue LoadError
|
6
|
+
STDERR.puts "In development, you need to use `bundle exec bin/todo` to run your app"
|
7
|
+
STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
|
8
|
+
STDERR.puts "Feel free to remove this message from bin/todo now"
|
9
|
+
exit 64
|
10
|
+
end
|
11
|
+
|
12
|
+
include GLI::App
|
13
|
+
|
14
|
+
program_desc 'Describe your application here'
|
15
|
+
|
16
|
+
version Robotok::VERSION
|
17
|
+
|
18
|
+
desc 'Describe some switch here'
|
19
|
+
switch [:s,:switch]
|
20
|
+
|
21
|
+
desc 'Describe some flag here'
|
22
|
+
default_value 'robotok.yml'
|
23
|
+
arg_name 'robotok'
|
24
|
+
flag [:c,:config]
|
25
|
+
|
26
|
+
desc 'run'
|
27
|
+
arg_name ''
|
28
|
+
command :run do |c|
|
29
|
+
c.action do |global_options,options,args|
|
30
|
+
puts global_options.inspect
|
31
|
+
puts options.inspect
|
32
|
+
puts args.inspect
|
33
|
+
raise "robotrock" if $config[:robotok].nil?
|
34
|
+
start()
|
35
|
+
actions(args)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
pre do |global,command,options,args|
|
41
|
+
# Pre logic here
|
42
|
+
# Return true to proceed; false to abourt and not call the
|
43
|
+
# chosen command
|
44
|
+
# Use skips_pre before a command to skip this block
|
45
|
+
# on that command only
|
46
|
+
# true
|
47
|
+
# puts global.inspect
|
48
|
+
# puts command.inspect
|
49
|
+
# puts options.inspect
|
50
|
+
# puts args.inspect
|
51
|
+
config = global[:config] || "robotok.yml"
|
52
|
+
begin
|
53
|
+
$config = YAML.load_file config
|
54
|
+
rescue Exception => e
|
55
|
+
STDERR.puts "pre #{e.message}"
|
56
|
+
exit(-1)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
post do |global,command,options,args|
|
62
|
+
# Post logic here
|
63
|
+
# Use skips_post before a command to skip this
|
64
|
+
# block on that command only
|
65
|
+
true
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
on_error do |exception|
|
70
|
+
# Error logic here
|
71
|
+
# return false to skip default error handling
|
72
|
+
true
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def stop(n=1)
|
77
|
+
$driver.quit
|
78
|
+
exit(n)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def start()
|
83
|
+
cfg = $config[:robotok]
|
84
|
+
$driver = Selenium::WebDriver.for cfg[:driver].to_sym
|
85
|
+
$driver.manage().window().maximize()
|
86
|
+
|
87
|
+
stop() if cfg[:actions].nil?
|
88
|
+
|
89
|
+
$driver.navigate.to cfg[:url] if not cfg[:url].nil?
|
90
|
+
# todo connection error
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def data(o)
|
95
|
+
o[:data].each do |k,v|
|
96
|
+
puts "data action: #{k.to_s}"
|
97
|
+
elem = $driver.find_element(:xpath, v[:xpath])
|
98
|
+
|
99
|
+
case
|
100
|
+
when v.has_key?(:fill)
|
101
|
+
elem.clear
|
102
|
+
elem.send_keys v[:fill]
|
103
|
+
|
104
|
+
when v.has_key?(:select)
|
105
|
+
option = Selenium::WebDriver::Support::Select.new(elem)
|
106
|
+
option.select_by(:text, v[:select].to_s)
|
107
|
+
|
108
|
+
when v.has_key?(:option)
|
109
|
+
option = Selenium::WebDriver::Support::Select.new(elem)
|
110
|
+
option.select_by(:value, v[:option].to_s)
|
111
|
+
|
112
|
+
when v.has_key?(:submit)
|
113
|
+
elem.submit()
|
114
|
+
puts "[submit] #{page.to_s}"
|
115
|
+
|
116
|
+
when v.has_key?(:radio)
|
117
|
+
elem.click()
|
118
|
+
|
119
|
+
when v.has_key?(:click)
|
120
|
+
elem.click()
|
121
|
+
|
122
|
+
when v.has_key?(:check)
|
123
|
+
if elem.attribute("checked") then
|
124
|
+
elem.click() if not v[:check]
|
125
|
+
else
|
126
|
+
elem.click() if v[:check]
|
127
|
+
end
|
128
|
+
|
129
|
+
when v.has_key?(:captcha)
|
130
|
+
elem.clear
|
131
|
+
|
132
|
+
else
|
133
|
+
puts "[error] syntax #{k} #{v}"
|
134
|
+
end # case
|
135
|
+
end # data
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
def actions(args)
|
140
|
+
cfg = $config[:robotok]
|
141
|
+
|
142
|
+
$config[:args] = args
|
143
|
+
|
144
|
+
cfg[:actions].each do |action,opts|
|
145
|
+
|
146
|
+
if not $config[:args].nil? then
|
147
|
+
if not $config[:args].include?(action.to_s) then
|
148
|
+
puts "action skip: #{action} #{$config[:args].inspect}"
|
149
|
+
next
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
$driver.navigate.to opts[:url] if not opts[:url].nil?
|
154
|
+
|
155
|
+
if not opts[:timeout].nil? then
|
156
|
+
wait = Selenium::WebDriver::Wait.new(:timeout => opts[:timeout][:sec]) # seconds
|
157
|
+
begin
|
158
|
+
wait.until { $driver.find_element(:xpath => opts[:timeout][:xpath]) }
|
159
|
+
rescue
|
160
|
+
puts "[#{action}] Action timeout for #{opts[:timeout][:xpath]}"
|
161
|
+
stop()
|
162
|
+
end
|
163
|
+
data(opts)
|
164
|
+
end
|
165
|
+
|
166
|
+
end # action
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
def store()
|
171
|
+
cfg = $config[:robotok]
|
172
|
+
|
173
|
+
if not cfg[:mongo].nil? then
|
174
|
+
require 'mongo'
|
175
|
+
mongo = cfg[:mongo]
|
176
|
+
conn = Mongo::Connection.new(mongo[:url], mongo[:port])
|
177
|
+
db = conn.db(mongo[:db])
|
178
|
+
co = db.collection(mongo[:co])
|
179
|
+
co.insert($config.dup) if co.find("robotok.id" => cfg[:id]).count == 0
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
# main
|
185
|
+
exit run(ARGV)
|
data/lib/robotok.rb
ADDED
data/robotok.rdoc
ADDED
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: robotok
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tom Hornos
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: aruba
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: selenium-webdriver
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: gli
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - '='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.0.0
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - '='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.0.0
|
94
|
+
description:
|
95
|
+
email: tom.hornos@gmail.com
|
96
|
+
executables:
|
97
|
+
- robotok
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files:
|
100
|
+
- README.rdoc
|
101
|
+
- robotok.rdoc
|
102
|
+
files:
|
103
|
+
- bin/robotok
|
104
|
+
- lib/robotok/version.rb
|
105
|
+
- lib/robotok.rb
|
106
|
+
- README.rdoc
|
107
|
+
- robotok.rdoc
|
108
|
+
homepage: http://your.website.com
|
109
|
+
licenses: []
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options:
|
112
|
+
- --title
|
113
|
+
- robotok
|
114
|
+
- --main
|
115
|
+
- README.rdoc
|
116
|
+
- -ri
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 1.8.24
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: Robotrock
|
138
|
+
test_files: []
|