Class: QunitRunner
- Inherits:
-
Object
- Object
- QunitRunner
- Defined in:
- lib/tuev/tuev_runner.rb
Instance Method Summary collapse
-
#initialize(path, selenium_conf) ⇒ QunitRunner
constructor
A new instance of QunitRunner.
- #run ⇒ Object
- #run_in_browser(browser_string) {|selenium| ... } ⇒ Object
Constructor Details
#initialize(path, selenium_conf) ⇒ QunitRunner
Returns a new instance of QunitRunner.
3 4 5 6 |
# File 'lib/tuev/tuev_runner.rb', line 3 def initialize(path, selenium_conf) @test_file = path @selenium_conf = selenium_conf end |
Instance Method Details
#run ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/tuev/tuev_runner.rb', line 35 def run num_of_errors = 0 errors = "" @selenium_conf[:browsers].each do |browser_id| run_in_browser(browser_id) do |browser| browser.open "file://#{@test_file}" browser.wait_for_page_to_load "60000" puts "\ntesting on #{browser_id}: #{@test_file}\n\n" 60.times{ break if (browser.is_element_present("id=qunit-testresult") rescue false); sleep 1 } sleep 1 if browser.get_eval("typeof(window.results)") == "undefined" $stderr.puts "\tINFO: some lines of javascript will give you detailed testing output. For more info, see:" $stderr.puts "\thttps://github.com/kesselborn/tuev/raw/master/contrib/tuev_qunit.js" $stderr.puts else puts browser.get_eval('window.results.join("\n")') errors += browser.get_eval('window.errors.join("\n")') end 60.times{ break if (browser.get_text('id=qunit-testresult') != "Running..." rescue false); sleep 1 } puts browser.get_text('id=qunit-testresult') puts num_of_errors += browser.get_text("css=#qunit-testresult .failed").to_i end end unless errors == "" puts puts "Finished with these errors:" puts puts errors end num_of_errors end |
#run_in_browser(browser_string) {|selenium| ... } ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tuev/tuev_runner.rb', line 8 def run_in_browser(browser_string) begin Net::HTTP.new(@selenium_conf[:host], @selenium_conf[:port]).get2("/") rescue puts puts "It seems that there is no selenium server listening on '#{@selenium_conf[:host]}:#{@selenium_conf[:port]}'" puts puts "... aborting (try installing the gem 'selenium-server' and execute 'selenium-server' for an easy solution)" puts puts exit(1) end selenium = Selenium::Client::Driver.new( :host => @selenium_conf[:host], :port => @selenium_conf[:port], :browser => browser_string, :url => "file://", :timeout_in_second => 60 ) selenium.start_new_browser_session yield(selenium) selenium.close_current_browser_session end |