Class: Jasmine::SeleniumDriver

Inherits:
Object
  • Object
show all
Defined in:
lib/jasmine/selenium_driver.rb

Instance Method Summary collapse

Constructor Details

#initialize(browser, http_address) ⇒ SeleniumDriver

Returns a new instance of SeleniumDriver.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jasmine/selenium_driver.rb', line 4

def initialize(browser, http_address)
  require 'selenium-webdriver'
  selenium_server = if ENV['SELENIUM_SERVER']
    ENV['SELENIUM_SERVER']
  elsif ENV['SELENIUM_SERVER_PORT']
    "http://localhost:#{ENV['SELENIUM_SERVER_PORT']}/wd/hub"
  end
  options = if browser == "firefox" && ENV["JASMINE_FIREBUG"]
              require File.join(File.dirname(__FILE__), "firebug/firebug")
              profile = Selenium::WebDriver::Firefox::Profile.new
              profile.enable_firebug
              {:profile => profile}
            end || {}
  @driver = if selenium_server
    Selenium::WebDriver.for :remote, :url => selenium_server, :desired_capabilities => browser.to_sym
  else
    Selenium::WebDriver.for browser.to_sym, options
  end
  @http_address = http_address
end

Instance Method Details

#connectObject



25
26
27
# File 'lib/jasmine/selenium_driver.rb', line 25

def connect
  @driver.navigate.to @http_address
end

#disconnectObject



29
30
31
# File 'lib/jasmine/selenium_driver.rb', line 29

def disconnect
  @driver.quit
end

#eval_js(script) ⇒ Object



33
34
35
36
# File 'lib/jasmine/selenium_driver.rb', line 33

def eval_js(script)
  result = @driver.execute_script(script)
  MultiJson.load("{\"result\":#{result}}", :max_nesting => false)["result"]
end

#json_generate(obj) ⇒ Object



38
39
40
# File 'lib/jasmine/selenium_driver.rb', line 38

def json_generate(obj)
  MultiJson.dump(obj)
end