Class: JsTestCore::Resources::Runner::Collection

Inherits:
ThinRest::Resource
  • Object
show all
Defined in:
lib/js_test_core/resources/runner.rb

Instance Method Summary collapse

Instance Method Details

#after_initializeObject



15
16
17
18
# File 'lib/js_test_core/resources/runner.rb', line 15

def after_initialize
  super
  self.selenium_browser_start_command = rack_request['selenium_browser_start_command']
end

#postObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/js_test_core/resources/runner.rb', line 20

def post
  spec_url = rack_request['spec_url'].to_s == "" ? full_spec_suite_url : rack_request['spec_url']
  parsed_spec_url = URI.parse(spec_url)
  selenium_host = rack_request['selenium_host'].to_s == "" ? 'localhost' : rack_request['selenium_host'].to_s
  selenium_port = rack_request['selenium_port'].to_s == "" ? 4444 : Integer(rack_request['selenium_port'])
  http_address = "#{parsed_spec_url.scheme}://#{parsed_spec_url.host}:#{parsed_spec_url.port}"
  driver = Selenium::SeleniumDriver.new(
    selenium_host,
    selenium_port,
    selenium_browser_start_command,
    http_address
  )
  begin
    driver.start
  rescue Errno::ECONNREFUSED => e
    raise Errno::ECONNREFUSED, "Cannot connect to Selenium Server at #{http_address}. To start the selenium server, run `selenium`."
  end
  runner = Runner.new(:driver => driver)
  Runner.register(runner)
  Thread.start do
    driver.open("/")
    driver.create_cookie("session_id=#{runner.session_id}")
    driver.open(parsed_spec_url.path)
  end
  connection.send_head
  connection.send_body("session_id=#{runner.session_id}")
end