Skip to content

Commit

Permalink
for #383 - capture/replay clicks testa
Browse files Browse the repository at this point in the history
* save more info in capture
* need app.replay_event()
  assumes we have shoes_native_move_cursor
  • Loading branch information
Cecil committed Dec 16, 2017
1 parent d25fa42 commit 8e1d885
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 37 deletions.
45 changes: 8 additions & 37 deletions Tests/events/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@
end
flow do
button "Start app and capture" do
$capture = []
@capture = {}
events = []
eval IO.read(@el.text).force_encoding("UTF-8"), TOPLEVEL_BINDING, @el.text
w2 = Shoes.APPS[-1]
x = w2.left
y = w2.top
w2.move x+80, y-40
$base_t = Time.now
$capture << {captured: @el.text, time: $base_t}
base_t = Time.now
@capture[:context] = {app: @el.text, time: base_t}
@capture[:events] = events
w2.event = proc do |evt|
case evt.type
when :click
#$stderr.puts "click handler2 with #{evt.type}"
$capture << { time: (Time.now - $base_t), x: evt.x, y: evt.y}
events << { time: (Time.now - base_t), button: evt.button, x: evt.x, y: evt.y,
modifiers: evt.modifiers, object: evt.object}
evt.accept = true
else
evt.accept = true
Expand All @@ -44,39 +47,7 @@
end
flow do
button "Stop and save" do
File.open(@sv.text, 'w') {|f| YAML.dump($capture, f)}
end
end
flow do
button "Load events" do
@evts = YAML::load_file(@sv.text)
puts @evts
hdr = @evts[0]
script = hdr[:captured]
eval IO.read(script).force_encoding("UTF-8"), TOPLEVEL_BINDING, script
w2 = Shoes.APPS[-1]
x = w2.left
y = w2.top
w2.move x+80, y-40
end
button "Replay" do
w2 = Shoes.APPS[-1]
# Hard part here
#w2.replay_events = proc do
#end
delay = 0
for r in 1..@evts.size
ev = @evts[r]
t = ev[:time]
delay = t if r==1
wait = t - delay
puts wait
th = Thread.new do
sleep wait
th.join
end
delay = t
end
File.open(@sv.text, 'w') {|f| YAML.dump(@capture, f)}
end
end
end
Expand Down
48 changes: 48 additions & 0 deletions Tests/events/replay.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'yaml'
Shoes.app do
stack do
tagline "Replay Clicks for another app"
para "Load events from"
flow do
@sv = edit_line width: 450
@sv.text = "#{DIR}/events.yaml"
button "Change" do
path = ask_file_open
@sv.text = path if path
end
end

flow do
button "Start App" do
evtflhash = YAML::load_file(@sv.text)
hdr = evtflhash[:context]
puts hdr
script = hdr[:app]
eval IO.read(script).force_encoding("UTF-8"), TOPLEVEL_BINDING, script
w2 = Shoes.APPS[-1]
x = w2.left
y = w2.top
w2.move x+80, y-40
@events = evtflhash[:events]
puts @events
end
end
button "Replay Events" do
w2 = Shoes.APPS[-1]
delay = 0
@events.each_index do |r|
ev = @events[r]
t = ev[:time]
delay = t if r == 0
wait = t - delay
timer(wait) do
puts "waited for #{wait}"
puts " move to #{ev[:x]}, #{ev[:y]} and click "
# want to call: w2.replay_event(:click, ev)
# need native move_cursor ability
end
delay = t
end
end
end
end

0 comments on commit 8e1d885

Please sign in to comment.