Class: TestStarter

Inherits:
Object
  • Object
show all
Includes:
AutoTest
Defined in:
lib/test_starter.rb

Constant Summary

Constants included from AutoTest

AutoTest::VERSION

Instance Method Summary collapse

Methods included from AutoTest

configure

Methods included from AutoTest::Test

action_path, add_to_action_path, add_to_sessions_array, always_present, check_invariants, fixtures, get_always_present, get_depth, get_fixtures, get_inputs, get_links_to_exclude, get_max_depth, get_max_number_of_session_links, get_number_of_sessions, get_number_of_test_runs, get_object_dependencies, get_sessions, get_sessions_array, inc_depth, init_action_path, init_always_present, init_auth, init_depth, init_fixtures, init_hash_sessions, init_inputs, init_links, init_number_of_test_runs, init_object_dependencies, init_ready, init_sessions, init_sessions_array, init_stop, init_stop_at_first_error, initialize_test, iterations, iterations=, link_counter, link_counter=, links_to_exclude, no_auth, paths, paths=, ready, ready?, run, run=, sessions, set_input, set_max_depth, set_max_number_of_session_links, set_no_auth, set_number_of_sessions, set_number_of_test_runs, set_object_dependency, stop!, stop?, stop_at_first_error, stop_at_first_error?, use_fixtures, use_fixtures?, users_logged_in, users_logged_in=

Methods included from AutoTest::Dsl

always_present, get_users_from_db, links_to_exclude, set_input, set_login_attribute_names, set_login_button, set_login_data, set_login_path, set_logout_path, set_max_depth, set_max_number_of_session_links, set_no_auth, set_number_of_sessions, set_number_of_test_runs, set_object_dependency, set_unique_login_attribute_name, stop_at_first_error

Methods included from AutoTest::Authentication

get_login_attributes, get_login_button, get_login_data, get_login_fields, get_login_names, get_login_path, get_logout_path, get_unique_login_attribute_name, get_user_data, get_users, get_users_from_db, init_login_data, init_users, login, logout, set_login_attribute_names, set_login_button, set_login_data, set_login_fields, set_login_names, set_login_path, set_logout_path, set_unique_login_attribute_name, set_user_data, use_db_users, user_class

Methods included from AutoTest::Error

get_error, get_error_messages, inc_error, init_error, print_errors

Methods included from AutoTest::Page

all_inputs, all_links, all_selects, all_submits, check_for_error_code, choose_checkbox, choose_radio, fill_in_forms, go_back, handle_alert, handle_excluded_links, handle_forms, run_session, select_option

Instance Method Details

#testObject

method to start the test and handle errors



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
30
31
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
58
59
60
61
62
63
64
# File 'lib/test_starter.rb', line 4

def test
  for j in 1..Test.get_number_of_test_runs do
    Test.run = j
    if !Test.stop?
      # initialization
      number_of_sessions = Test.get_number_of_sessions
      Test.init_sessions_array
      Test.init_sessions
      Test.init_ready
      for i in 0..number_of_sessions-1 do
        # Session instantiation
        sess = Capybara::Session.new(:rack_test,Rails.application)
        # session variable initialization
        Test.add_to_sessions_array sess
        Test.init_hash_sessions(i, Hash.new)
        Test.sessions(i,"depth", 0)
        Test.sessions(i,"iterations", 0)
        if !Test.no_auth then
          user = Authentication.get_users[rand(Authentication.get_users.size)]
          Test.sessions(i,"user", user) 
          Test.add_to_action_path "#{i}:#{user.id}ID"
          Test.sessions(i,"current_user", 0) 
        end
        Test.sessions(i,"ready", false) 
        Test.sessions(i,"iteration", 0) 
        Test.sessions(i,"current_depth", 0) 
        Test.sessions(i,"paths", Hash.new)
      end
      Error.init_error
      puts
      Test.link_counter = 0
      Test.users_logged_in = 1
      if Test.no_auth then
        Test.users_logged_in = 0
      end
      # Console output
      STDOUT.write("\r#{Test.run}. run: \t#{Test.link_counter} links clicked, \t#{Test.users_logged_in} users logged in, \t#{Error.get_error} Errors")
      while !Test.stop? && !Test.ready? do
        # get a random session
        session = rand(number_of_sessions)
        # let the session test a random number of times, max the number given by the tester
        for i in 0..rand(Test.get_max_number_of_session_links) do
          Page.run_session(session)
        end
      end
    end
  end
  Test.check_invariants
  if !Test.stop? then Test.users_logged_in = Test.users_logged_in + 1 end
  # save the action path to a file
  f = File.new("#{Rails.root}/log/paths.log", "w")
  f.puts(Test.action_path)
  f.close
  puts
  # print and save the errors
  Error.print_errors
  f = File.new("#{Rails.root}/log/errors.log", "w")
  f.puts(Error.get_error)
  f.puts(Error.get_error_messages)
  f.close
end