Module: RWebSpec::WebDriver::LoadTestHelper

Includes:
Assert, Driver, Utils
Defined in:
lib/rwebspec-webdriver/load_test_helper.rb

Constant Summary collapse

MAX_VU =
1000

Constants included from Utils

Utils::WORDS

Instance Method Summary collapse

Methods included from Assert

#assert_button_not_present, #assert_button_not_present_with_text, #assert_button_present, #assert_button_present_with_text, #assert_checkbox_not_selected, #assert_checkbox_selected, #assert_disabled, #assert_enabled, #assert_equals, #assert_exists, #assert_hidden, #assert_link_not_present_with_text, #assert_link_present_with_text, #assert_nil, #assert_not, #assert_not_exists, #assert_not_nil, #assert_option_equals, #assert_option_not_present, #assert_option_present, #assert_option_value_equals, #assert_option_value_not_present, #assert_option_value_present, #assert_radio_option_not_present, #assert_radio_option_not_selected, #assert_radio_option_present, #assert_radio_option_selected, #assert_text_field_value, #assert_text_in_element, #assert_text_in_page_source, #assert_text_not_in_page_source, #assert_text_not_present, #assert_text_not_present_in_table, #assert_text_present, #assert_text_present_in_table, #assert_title_equals, #assert_visible, #fail

Methods included from Driver

#absolutify_url, #absolutize_page, #absolutize_page_hpricot, #ajax_wait_for_element, #attach_browser, #basic_authentication, #basic_authentication_celerity, #basic_authentication_firefox, #basic_authentication_ie, #begin_at, #browser, #cell_with_id, #check_ie_version, #choose_file_dialog, #clear_popup, #click_button_with_image_src_contains, #close_all_browsers, #close_browser, #contains, #contains_text, #context, #default_dump_dir, #dump_response, #element_by_id, #element_text, #ends_with?, #enter_text_with_id, #expect_page, #find_element, #find_elements, #firefox, #goto_page, #goto_url, #ie, #is_firefox?, #is_htmlunit?, #is_ie?, #is_linux?, #is_mac?, #is_windows?, #label_with_id, #new_popup_window, #page_source, #page_text, #page_title, #perform_operation, #quit, #save_current_page, #select_file_for_upload, #span_with_id, #substitute_relative_path_in_src_line, #support_utf8, #use_current_browser, #wait_for_element, #wait_until

Methods included from Popup

#check_for_popups, #check_for_security_alerts, #click_button_in_javascript_popup, #click_button_in_popup_after, #click_button_in_security_alert_popup, #click_button_in_security_information_popup, #click_popup_window, #ie_popup_clicker, #prepare_to_click_button_in_popup, #start_checking_js_dialog, #verify_alert

Methods included from TestWisePlugin

#connect_to_testwise, #debug, #dump_caller_stack, #notify_screenshot_location, #operation_delay

Methods included from Utils

#allow, #days_before, #days_from_now, #failsafe, #interpret_value, #on, #paragraphs, #random_boolean, #random_char, #random_digit, #random_number, #random_str, #random_string_in, #repeat_try, #sentences, #shall_not_allow, #symbol_to_sequence, #take_screenshot, #today, #tomorrow, #try, #try_until, #value_in_range, #words, #yesterday

Instance Method Details

#log_time(msg, &block) ⇒ Object

monitor current execution using

Usage

log_time { browser.click_button('Confirm') }


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
# File 'lib/rwebspec-webdriver/load_test_helper.rb', line 24

def log_time(msg, &block)
  start_time = Time.now
  yield
  end_time = Time.now

  Thread.current[:log] ||= []
  Thread.current[:log] << {:file => File.basename(__FILE__),
    :message => msg,
    :start_time => Time.now,
  :duration => Time.now - start_time}

  if $LOADWISE_MONITOR
    begin
      require 'java'
      puts "Calling Java 1"
      java_import com.loadwise.db.MemoryDatabase
      #puts "Calling Java 2: #{MemoryDatabase.count}"
      MemoryDatabase.addEntry(1, "zdfa01", "a_spec.rb", msg, start_time, end_time);
      puts "Calling Java Ok: #{MemoryDatabase.count}"
    rescue NameError => ne
      puts "Name Error: #{ne}"
      # failed to load Java class
    rescue => e
      puts "Failed to calling Java: #{e.class.name}"
    end
  end
  # How to notify LoadWise at real time
  # LoadWise to collect CPU
end

#open_browser(base_url, options = {}) ⇒ Object

only support firefox or Celerity



13
14
15
16
17
18
# File 'lib/rwebspec-webdriver/load_test_helper.rb', line 13

def open_browser(base_url, options = {})
  options[:browser] ||= (ENV['LOADWISE_PREVIEW'] || $LOADWISE_PREVIEW)        
  default_options = {:browser => :htmlunit , :go => true}
  options = default_options.merge(options)        
  @web_browser = WebBrowser.new(base_url, nil, options)
end

#run_with_virtual_users(virtual_user_count = 2, preview = false, &block) ⇒ Object



54
55
56
57
58
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
# File 'lib/rwebspec-webdriver/load_test_helper.rb', line 54

def run_with_virtual_users(virtual_user_count = 2, preview = false, &block)
  raise "too many virtual users" if virtual_user_count > MAX_VU

  begin
    if defined?(LOADWISE_PREVIEW)
      preview = LOADWISE_PREVIEW
    end
  rescue => e1
  end

  if preview
    virtual_user_count = 1
    $LOADWISE_PREVIEW = true
  end

  if (virtual_user_count <= 1)
    yield
  else
    threads = []
    vu_reports = {}
    virtual_user_count.times do |idx|
      threads[idx] = Thread.new do
        start_time = Time.now
        vu_reports[idx] ||= []
        begin
          yield
          vu_reports[idx] =  Thread.current[:log]
        rescue => e
          vu_reports[idx] =  Thread.current[:log]
          vu_reports[idx] ||= []
          vu_reports[idx] << { :error => e }
        end
        vu_reports[idx] ||= []
        vu_reports[idx] << { :message => "Total Duration", :duration => Time.now - start_time }
        puts "VU[#{idx+1}] #{Time.now - start_time}s"
      end
    end

    threads.each {|t| t.join; }
    vu_reports.each do |key, value|
      value.each do |entry|
        if entry[:error] then
          puts "Error: #{entry[:error]}"
        else
          puts "[#{key}] #{entry[:message]}, #{entry[:duration]}"
        end
      end
    end

    return vu_reports
  end
end