Class: SeleniumRails::ServersRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium_rails/servers_runner.rb

Class Method Summary collapse

Class Method Details

.run_with_servers(&block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/selenium_rails/servers_runner.rb', line 6

def self.run_with_servers(&block)
  begin
    rails_server_process = IO.popen("mongrel_rails start --chdir=#{RAILS_ROOT} --port=3001 --environment=test")
    selenium_server = Selenium::SeleniumServer.new
    unless selenium_server.running?
      IO.popen("selenium")
    end

    yield

    Selenium::SeleniumDriverManager.stop_drivers
  rescue Exception => e
    puts e
    raise e
  ensure
    puts "Killing rails server process at pid #{rails_server_process.pid}"
    Process.kill(9,rails_server_process.pid)
    puts "Killing selenium server"
    selenium_server.stop
  end
end