44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/robo/robo.rb', line 44
def Robo.actions(c)
return if c[:actions].empty?
return if c[:args].empty?
br = c[:browser]
actions = c[:args].dup
if c[:args].shift == "task"
task = c[:args].shift || 'default'
actions = c[:tasks][task.to_sym][:actions]
end
actions.each do |act|
action = act.to_sym
opts = c[:actions][action]
case action.to_s
when "stop"
Robo::stop(c)
when "pry"
binding.pry
when "wait"
puts "#{action} #{opts}"
sleep(opts)
next
end
if opts.has_key?(:use)
win = br.windows.find{ |w| w.title =~ /#{opts[:use]}/ }
win.use
puts "#{action} use #{win.inspect}"
end
if opts.has_key?(:goto)
br.goto opts[:goto]
puts "#{action} goto #{opts[:goto]}"
end
opts[:timeout].each do |xpath,opts|
puts "#{action} wait #{xpath}"
begin
br.wait_until{br.element(:xpath,xpath.to_s).exists?}
rescue Exception => ex
STDERR.puts ex.inspect
binding.pry
end
end if opts.has_key?(:timeout)
opts[:assert].each do |xpath,opts|
puts "#{action} assert #{xpath}"
assert(br.element(:xpath,xpath.to_s).exists?)
end if opts.has_key?(:assert)
opts[:xpath].each do |xpath,cmds|
elem = br.element(:xpath=>xpath.to_s).to_subtype
puts "#{action} type => #{elem.inspect}"
cmds.each do |cmd,val|
puts "#{action} #{cmd} => #{val}"
begin
case cmd.to_s
when "flash"
val.times {elem.flash}
when "wait"
br.wait_until{br.element(:xpath,xpath.to_s).exists?}
else
elem.when_present.send cmd,val
end
rescue Exception => ex
STDERR.puts ex
binding.pry
end
end
end if opts.has_key?(:xpath)
opts[:elem].each do |elem,cmds|
path = cmds.shift
cmd = cmds.shift
puts "#{action} #{elem} => #{path} => #{cmd}"
try = 0
begin
try += 1
_elem = br.send elem,path[0],/#{path[1]}/
puts _elem.inspect
_cmd,_val = cmd
_elem.when_present(3).send _cmd,_val
rescue Exception => ex
retry if try < 3
STDERR.puts ex.inspect
binding.pry
end
end if opts.has_key?(:elem)
br.windows.find{|w| w.title =~ /#{opts[:close]}/}.close if opts.has_key?(:close)
end
end
|