Class: QunitRunner
- Inherits:
-
Object
- Object
- QunitRunner
- Defined in:
- lib/tuev/tuev_runner.rb
Instance Method Summary collapse
-
#host ⇒ Object
host & path as is needed below …
-
#initialize(path, selenium_conf) ⇒ QunitRunner
constructor
A new instance of QunitRunner.
- #local_file? ⇒ Boolean
- #path ⇒ Object
- #run ⇒ Object
- #run_in_browser(browser_string) {|selenium| ... } ⇒ Object
- #split_url ⇒ Object
Constructor Details
#initialize(path, selenium_conf) ⇒ QunitRunner
Returns a new instance of QunitRunner.
3 4 5 6 7 8 9 10 11 |
# File 'lib/tuev/tuev_runner.rb', line 3 def initialize(path, selenium_conf) @test_file = path if local_file? && !(@test_file =~ /file:\/\//) @test_file = "file://#{File.(@test_file)}" end @selenium_conf = selenium_conf end |
Instance Method Details
#host ⇒ Object
host & path as is needed below …
23 24 25 |
# File 'lib/tuev/tuev_runner.rb', line 23 def host local_file? ? "file://" : split_url[1] end |
#local_file? ⇒ Boolean
13 14 15 16 |
# File 'lib/tuev/tuev_runner.rb', line 13 def local_file? # it's a local file if it has not any protocoll or the file:// protcoll !(@test_file =~ /:\/\//) || !!(@test_file =~ /file:\/\//) end |
#path ⇒ Object
27 28 29 |
# File 'lib/tuev/tuev_runner.rb', line 27 def path local_file? ? @test_file : split_url[2] end |
#run ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/tuev/tuev_runner.rb', line 59 def run num_of_errors = 0 errors = "" @selenium_conf[:browsers].each do |browser_id| run_in_browser(browser_id) do |browser| test_framework = "" browser.open path browser.wait_for_page_to_load "60000" puts "\ntesting on #{browser_id}: #{@test_file}\n\n" 120.times{ if (browser.get_text("id=tyrtle-result") rescue false) test_framework = "tyrtle" break end if (browser.get_text("css=.jasmine_reporter") rescue false) test_framework = "jasmine" break end if (browser.get_text('id=qunit-testresult') != "Running..." rescue false) test_framework = "qunit" break end sleep 1 } sleep 1 output ="" num_of_errors = 0 if test_framework == "qunit" 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 output = browser.get_text('id=qunit-testresult') num_of_errors += browser.get_text("css=#qunit-testresult .failed").to_i else output = browser.get_eval('window.message') junit_output = browser.get_eval('window.junitXML') File.open("junit_results.xml", "w") do |f| f << junit_output end num_of_errors += browser.get_eval('window.isSuccess') ? 0 : 1 end puts output puts num_of_errors 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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/tuev/tuev_runner.rb', line 32 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 => host, :timeout_in_second => 60 ) selenium.start_new_browser_session yield(selenium) selenium.close_current_browser_session end |
#split_url ⇒ Object
18 19 20 |
# File 'lib/tuev/tuev_runner.rb', line 18 def split_url @test_file.match(/(.*:\/\/[^\/]+)(.*)$/) end |