Skip to content

Instantly share code, notes, and snippets.

@MollsReis
Created February 13, 2012 22:44
Show Gist options
  • Select an option

  • Save MollsReis/1821185 to your computer and use it in GitHub Desktop.

Select an option

Save MollsReis/1821185 to your computer and use it in GitHub Desktop.
Use Sinatra to open a browser window (and close Sinatra when the window closes)
%w[sinatra watir-webdriver].each { |gem| require gem }
class MyApp < Sinatra::Base
get('/') { "hello world" }
end
class AppRunner
def initialize
@browser = nil
end
def browser_start!
@browser = Watir::Browser.start 'http://localhost:4567'
end
def start!
Thread.new { sleep(1) until MyApp.settings.running?; browser_start! }
Thread.new { check_browser while true }
MyApp.run!
end
def check_browser
sleep(1)
begin
@browser.status unless @browser.nil?
rescue Exception
puts "== Sinatra has been led off the stage by AppRunner..."
exit(0)
end
end
end
AppRunner.new.start!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment