1

I have a script that uses Watir webdriver. However, it takes a long time and I need to stop it occasionally. I'd like to be able to interrupt it and handle the interrupt by performing a few tasks, such as logging out of the website I am on. Then, it would need a way to resume the process. I am using ruby, and, so far, I have tried rescue Interrupt => e as well as Signal.trap("TSTP") do |signo| {...}. In both of these, I cannot perform any closing operations on the browser because it seems that I have lost connection to it. Is there any way I can pause the script by keyboard and perform some exit operations on the Watir browser?

Signal.trap("TSTP") do |signo|
    browser.link(:text=> "Logout").click
    ap "Paused. Press <enter> to continue."
    $stdin.gets
    Process.kill("STOP", Process.pid)
end

After stopping gives me ^Z/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:158:in `rescue in rbuf_fill': Net::ReadTimeout (Net::ReadTimeout).

nikojpapa
  • 660
  • 1
  • 8
  • 16

0 Answers0