Class: RSpec::Jasmine::SeleniumDriver
- Inherits:
-
Object
- Object
- RSpec::Jasmine::SeleniumDriver
- Defined in:
- lib/rspec/jasmine/selenium_driver.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #connect(address) ⇒ Object
- #disconnect ⇒ Object
- #driver ⇒ Object
- #eval_js(script) ⇒ Object
-
#initialize(browser, options = {}) ⇒ SeleniumDriver
constructor
A new instance of SeleniumDriver.
- #json_generate(obj) ⇒ Object
- #selenium_server ⇒ Object
- #tests_finished? ⇒ Boolean
- #x(script) ⇒ Object
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 = @browser = browser end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
7 8 9 |
# File 'lib/rspec/jasmine/selenium_driver.rb', line 7 def address @address end |
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
7 8 9 |
# File 'lib/rspec/jasmine/selenium_driver.rb', line 7 def browser @browser end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/rspec/jasmine/selenium_driver.rb', line 7 def @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 |
#disconnect ⇒ Object
38 39 40 |
# File 'lib/rspec/jasmine/selenium_driver.rb', line 38 def disconnect driver.quit end |
#driver ⇒ Object
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, 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_server ⇒ Object
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
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 |