robo 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/README.rdoc ADDED
@@ -0,0 +1,8 @@
1
+ = robo
2
+
3
+ Watir automator
4
+
5
+ check examples
6
+
7
+ :include:robo.rdoc
8
+
data/bin/robo ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ #begin # XXX: Remove this begin/rescue before distributing your app
4
+ require 'robo'
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 'Watir automator'
15
+
16
+ version Robo::VERSION
17
+
18
+ # desc 'Describe some switch here'
19
+ # switch [:s,:switch]
20
+
21
+ desc 'config'
22
+ default_value 'robo.yml'
23
+ arg_name 'The name of the argument'
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
+ @config[:robo][:args] = args
31
+ Robo::stop if @config[:robo].nil?
32
+ Robo::start(@config[:robo])
33
+ Robo::jsproper(@config[:robo])
34
+ Robo::actions(@config[:robo])
35
+ end
36
+ end
37
+
38
+
39
+ desc 'list'
40
+ arg_name ''
41
+ command :list do |c|
42
+ c.action do |global_options,options,args|
43
+ Robo::list(@config[:robo],args) if not @config[:robo].nil?
44
+ end
45
+ end
46
+
47
+
48
+ pre do |global,command,options,args|
49
+ begin
50
+ @config = YAML.load(ERB.new(File.read(global[:config])).result)
51
+ # @config = YAML.load_file global[:config]
52
+ rescue Exception => e
53
+ STDERR.puts "pre #{e.message}"
54
+ Robo::stop(nil,1)
55
+ end
56
+ end
57
+
58
+
59
+ post do |global,command,options,args|
60
+ # Post logic here
61
+ # Use skips_post before a command to skip this
62
+ # block on that command only
63
+ end
64
+
65
+
66
+ on_error do |exception|
67
+ # Error logic here
68
+ # return false to skip default error handling
69
+ # puts exception.backtrace
70
+ # binding.pry
71
+ # true
72
+ false
73
+ # false
74
+ end
75
+
76
+ exit run(ARGV)
data/lib/robo/robo.rb ADDED
@@ -0,0 +1,150 @@
1
+
2
+ module Robo
3
+ def Robo.stop(c=nil,e=1)
4
+ c[:browser].close if not c.nil?
5
+ puts "STOP"
6
+ exit
7
+ end
8
+
9
+ def Robo.start(c)
10
+ if not c[:driver][:proxy].nil?
11
+ profile = Selenium::WebDriver::Firefox::Profile.new
12
+ profile.proxy = Selenium::WebDriver::Proxy.new :http => c[:driver][:proxy], :ssl => c[:driver][:proxy]
13
+ c[:browser] = Watir::Browser.new c[:driver][:browser],:profile=>profile
14
+ else
15
+ c[:browser] = Watir::Browser.new c[:driver][:browser]
16
+ end
17
+ end
18
+
19
+ def Robo.list(c,a=nil)
20
+ case
21
+ when a[0].nil?
22
+ puts "actions:"
23
+ c[:actions].each do |action,opts|
24
+ puts action.to_s
25
+ end if not c[:actions].empty?
26
+
27
+ when c.has_key?(a[0].to_sym)
28
+ puts "#{a[0].to_s}:"
29
+ c[a[0].to_sym].each do |action,opts|
30
+ puts "#{action.to_s} - #{opts[:info]}"
31
+ puts " #{opts[:actions]}"
32
+ end if not c[a[0].to_sym].empty?
33
+ end
34
+ end
35
+
36
+ def Robo.jsproper(c)
37
+ c[:browser].execute_script("window.alert = function() {}")
38
+ c[:browser].execute_script("window.prompt = function() {return null}")
39
+ c[:browser].execute_script("window.confirm = function() {return true}")
40
+ c[:browser].execute_script("window.confirm = function() {return false}")
41
+ c[:browser].execute_script("window.onbeforeunload = null")
42
+ end
43
+
44
+ def Robo.actions(c)
45
+ return if c[:actions].empty?
46
+ return if c[:args].empty?
47
+
48
+ br = c[:browser]
49
+ actions = c[:args].dup
50
+
51
+ if c[:args].shift == "task"
52
+ task = c[:args].shift || 'default'
53
+ actions = c[:tasks][task.to_sym][:actions]
54
+ end
55
+
56
+ actions.each do |act|
57
+ action = act.to_sym
58
+ opts = c[:actions][action]
59
+ case action.to_s
60
+ when "stop"
61
+ Robo::stop(c)
62
+
63
+ when "pry"
64
+ binding.pry
65
+
66
+ when "wait"
67
+ puts "#{action} #{opts}"
68
+ sleep(opts)
69
+ next
70
+ end
71
+
72
+ # window switch
73
+ if opts.has_key?(:use)
74
+ win = br.windows.find{ |w| w.title =~ /#{opts[:use]}/ }
75
+ win.use
76
+ puts "#{action} use #{win.inspect}"
77
+ end
78
+
79
+ # url goto
80
+ if opts.has_key?(:goto)
81
+ br.goto opts[:goto]
82
+ puts "#{action} goto #{opts[:goto]}"
83
+ end
84
+
85
+ # page timeout
86
+ opts[:timeout].each do |xpath,opts|
87
+ puts "#{action} wait #{xpath}"
88
+ begin
89
+ br.wait_until{br.element(:xpath,xpath.to_s).exists?}
90
+ rescue Exception => ex
91
+ STDERR.puts ex.inspect
92
+ binding.pry
93
+ end
94
+ end if opts.has_key?(:timeout)
95
+
96
+ # assert
97
+ opts[:assert].each do |xpath,opts|
98
+ puts "#{action} assert #{xpath}"
99
+ assert(br.element(:xpath,xpath.to_s).exists?)
100
+ end if opts.has_key?(:assert)
101
+
102
+ # process xpath
103
+ opts[:xpath].each do |xpath,cmds|
104
+ elem = br.element(:xpath=>xpath.to_s).to_subtype
105
+ puts "#{action} type => #{elem.inspect}"
106
+
107
+ cmds.each do |cmd,val|
108
+ puts "#{action} #{cmd} => #{val}"
109
+ begin
110
+ case cmd.to_s
111
+ when "flash"
112
+ val.times {elem.flash}
113
+
114
+ when "wait"
115
+ br.wait_until{br.element(:xpath,xpath.to_s).exists?}
116
+
117
+ else
118
+ elem.when_present.send cmd,val
119
+ end
120
+ rescue Exception => ex
121
+ STDERR.puts ex
122
+ binding.pry
123
+ end
124
+ end
125
+ end if opts.has_key?(:xpath)
126
+
127
+ # process element
128
+ opts[:elem].each do |elem,cmds|
129
+ path = cmds.shift
130
+ cmd = cmds.shift
131
+ puts "#{action} #{elem} => #{path} => #{cmd}"
132
+ try = 0
133
+ begin
134
+ try += 1
135
+ _elem = br.send elem,path[0],/#{path[1]}/
136
+ puts _elem.inspect
137
+ _cmd,_val = cmd
138
+ _elem.when_present(3).send _cmd,_val
139
+ rescue Exception => ex
140
+ retry if try < 3
141
+ STDERR.puts ex.inspect
142
+ binding.pry
143
+ end
144
+ end if opts.has_key?(:elem)
145
+
146
+ # last entry
147
+ br.windows.find{|w| w.title =~ /#{opts[:close]}/}.close if opts.has_key?(:close)
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,3 @@
1
+ module Robo
2
+ VERSION = '0.0.1'
3
+ end
data/lib/robo.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'robo/version.rb'
2
+ require 'robo/robo.rb'
3
+ # Add requires for other files you add to your project here, so
4
+ # you just need to require this one file in your bin file
5
+
6
+ require 'watir-webdriver'
7
+ require 'pry'
data/robo.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = robo
2
+
3
+ Generate this with
4
+ robo rdoc
5
+ After you have described your command line interface
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: robo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Your Name Here
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-29 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: watir-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: pry
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: gli
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - '='
100
+ - !ruby/object:Gem::Version
101
+ version: 2.0.0
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - '='
108
+ - !ruby/object:Gem::Version
109
+ version: 2.0.0
110
+ description:
111
+ email: your@email.address.com
112
+ executables:
113
+ - robo
114
+ extensions: []
115
+ extra_rdoc_files:
116
+ - README.rdoc
117
+ - robo.rdoc
118
+ files:
119
+ - bin/robo
120
+ - lib/robo/version.rb
121
+ - lib/robo/robo.rb
122
+ - lib/robo.rb
123
+ - README.rdoc
124
+ - robo.rdoc
125
+ homepage: http://your.website.com
126
+ licenses: []
127
+ post_install_message:
128
+ rdoc_options:
129
+ - --title
130
+ - robo
131
+ - --main
132
+ - README.rdoc
133
+ - -ri
134
+ require_paths:
135
+ - lib
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 1.8.24
152
+ signing_key:
153
+ specification_version: 3
154
+ summary: A description of your project
155
+ test_files: []