Class: Jasmine::SeleniumDriver
- Inherits:
-
Object
- Object
- Jasmine::SeleniumDriver
- Defined in:
- lib/jasmine/selenium_driver.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
- #eval_js(script) ⇒ Object
-
#initialize(selenium_host, selenium_port, selenium_browser_start_command, http_address) ⇒ SeleniumDriver
constructor
A new instance of SeleniumDriver.
- #run ⇒ Object
- #tests_have_finished? ⇒ Boolean
Constructor Details
#initialize(selenium_host, selenium_port, selenium_browser_start_command, http_address) ⇒ SeleniumDriver
Returns a new instance of SeleniumDriver.
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/jasmine/selenium_driver.rb', line 3 def initialize(selenium_host, selenium_port, selenium_browser_start_command, http_address) require 'selenium/client' @driver = Selenium::Client::Driver.new( selenium_host, selenium_port, selenium_browser_start_command, http_address ) @http_address = http_address end |
Instance Method Details
#connect ⇒ Object
18 19 20 21 |
# File 'lib/jasmine/selenium_driver.rb', line 18 def connect @driver.start @driver.open("/") end |
#disconnect ⇒ Object
23 24 25 |
# File 'lib/jasmine/selenium_driver.rb', line 23 def disconnect @driver.stop end |
#eval_js(script) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/jasmine/selenium_driver.rb', line 37 def eval_js(script) escaped_script = "'" + script.gsub(/(['\\])/) { '\\' + $1 } + "'" result = @driver.get_eval(" try { eval(#{escaped_script}, window); } catch(err) { window.eval(#{escaped_script}); }") JSON.parse("[#{result}]")[0] end |
#run ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/jasmine/selenium_driver.rb', line 27 def run until tests_have_finished? do sleep 0.1 end puts @driver.get_eval("window.results()") failed_count = @driver.get_eval("window.jasmine.getEnv().currentRunner.results().failedCount").to_i failed_count == 0 end |
#tests_have_finished? ⇒ Boolean
14 15 16 |
# File 'lib/jasmine/selenium_driver.rb', line 14 def tests_have_finished? @driver.get_eval("window.jasmine.getEnv().currentRunner.finished") == "true" end |