browser_test.rb 2.85 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
require 'rubygems'
gem "minitest"
require 'watir-webdriver'
require 'test/unit'
require "minitest/autorun"
require 'minitest/ci'
if ENV['HEADLESS']
  require 'headless'
end
load 'vidjil_browser.rb'

include Test::Unit::Assertions
MiniTest.autorun

#browser test suite
class BrowserTest < MiniTest::Test

  def self.test_order
    :alpha
  end

  def setup
    if ENV['HEADLESS'] and not defined? $headless
      $headless = Headless.new
      $headless.start
    end
  end

  def set_browser(vidjil_file, analysis_file=nil)
30
    folder_path = File.expand_path(File.dirname(__FILE__))
31
    folder_path.sub! '/browser/test/functional', ''
32 33
    index_path = 'file://' + folder_path + '/browser/index.html'
    data_path = folder_path + vidjil_file
34
    analysis_path = nil
35 36 37 38 39 40 41 42
    if analysis_file != nil
      analysis_path = folder_path + analysis_file
    end

    if ENV['LIVE_SERVER']
      index_path = ENV['LIVE_SERVER'] + '/?data='
    end
      
43
    print "Open browser\n"
44
    $b = VidjilBrowser.new
45 46

    print "Resize\n"
47
    $b.window.resize_to(1500, 800)
48 49

    print "Testing Vidjil browser at " + index_path + "\n"
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    $b.goto index_path

    # check that the browser loaded correctly
    if not $b.div(:id => 'logo').present?
      print "Loading of Vidjil browser failed. Do not execute remaining tests."
      exit
    end

    print "Vidjil browser loaded, launching tests.\n"
    
    # A live server can be configured with a database.
    # The welcome popup should not be tested.
    
    if not ENV['LIVE_SERVER']

65 66
      print "Welcome popup.\n"

67 68
      # wait for the welcoming popup
      $b.div(:class => 'popup_msg').wait_until_present(2)
69 70 71 72 73
    
      # close the welcoming popup
      $b.div(:class => 'popup_msg').button(:text => 'ok').click
      assert (not $b.div(:class => 'popup_msg').present?), "Popup message still present after trying to close it"
    end
74 75

    print "Import data.\n"
76 77
    
    # check the 'import data' menu element, and click on it
78 79
    assert ($b.div(:id => 'demo_file_menu').present?), "File menu is not present"
    # $b.div(:id => 'demo_file_menu').hover
80
    $b.div(:id => 'demo_file_menu').click
81
    assert ($b.div(:id => 'demo_file_menu').a(:id => 'import_data_anchor').present?), "'import data' not present"
82 83 84
    $b.div(:id => 'demo_file_menu').a(:id => 'import_data_anchor').click
    
    # select data file
85
    print "  data:     " + data_path + "\n"
86
    $b.div(:id => 'file_menu').file_field(:name,"json").set(data_path)
87 88 89

    # select analysis file
    if analysis_path != nil
90
      print "  analysis: " + analysis_path + "\n"
91 92 93 94 95
      $b.div(:id => 'file_menu').file_field(:name, "pref").set(analysis_path)
    end

    $b.div(:id => 'file_menu').button(:text => 'start').click

96 97 98 99 100 101 102 103 104 105 106 107 108
  end

  def close_everything
    if defined? $b
      print "\nTests finished, closing browser.\n"
      $b.close
      if ENV['HEADLESS']
        $headless.destroy
      end
    end
  end

end