Class: RSpec::Jasmine::SeleniumDriver

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(browser, options = {}) ⇒ SeleniumDriver

Returns a new instance of SeleniumDriver.



9
10
11
12
# File 'lib/rspec/jasmine/selenium_driver.rb', line 9

def initialize(browser, options = {})
  @options = options
  @browser = browser
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



7
8
9
# File 'lib/rspec/jasmine/selenium_driver.rb', line 7

def address
  @address
end

#browserObject (readonly)

Returns the value of attribute browser.



7
8
9
# File 'lib/rspec/jasmine/selenium_driver.rb', line 7

def browser
  @browser
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/rspec/jasmine/selenium_driver.rb', line 7

def options
  @options
end

Instance Method Details

#connect(address) ⇒ Object



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

def connect(address)
  driver.navigate.to(address)
end

#disconnectObject



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

def disconnect
  driver.quit
end

#driverObject



22
23
24
25
26
27
28
# File 'lib/rspec/jasmine/selenium_driver.rb', line 22

def driver
  @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
end

#eval_js(script) ⇒ Object



42
43
44
45
# File 'lib/rspec/jasmine/selenium_driver.rb', line 42

def eval_js(script)
  result = x(script)
  JSON.parse("{\"result\":#{result}}", :max_nesting => false)["result"]
end

#json_generate(obj) ⇒ Object



47
48
49
# File 'lib/rspec/jasmine/selenium_driver.rb', line 47

def json_generate(obj)
  JSON.generate(obj)
end

#selenium_serverObject



14
15
16
17
18
19
20
# File 'lib/rspec/jasmine/selenium_driver.rb', line 14

def selenium_server
  @selenium_server = if ENV['SELENIUM_SERVER']
    ENV['SELENIUM_SERVER']
  elsif ENV['SELENIUM_SERVER_PORT']
    "http://localhost:#{ENV['SELENIUM_SERVER_PORT']}/wd/hub"
  end
end

#tests_finished?Boolean

Returns:

  • (Boolean)


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

def tests_finished?
  x("return jsApiReporter.finished") == 'true'
end

#x(script) ⇒ Object



51
52
53
# File 'lib/rspec/jasmine/selenium_driver.rb', line 51

def x(script)
  driver.execute_script(script)
end