RWebSpec::TestWisePlugin

Public Instance Methods

connect_to_testwise(message_type, body) click to toggle source
# File lib/rwebspec/testwise_plugin.rb, line 69
def connect_to_testwise (message_type, body)
  Thread.pass
  begin
    the_message = message_type + "|" + body
    if @last_message == the_message then # ignore the message same as preivous one

      return
    end
    itest_port = $ITEST2_TRACE_PORT || 7025
    itest_socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
    itest_socket.connect(Socket.pack_sockaddr_in(itest_port, '127.0.0.1'))
    itest_socket.puts(the_message)
    @last_message = the_message
    itest_socket.close
  rescue => e
  end
end
debug(message) click to toggle source
# File lib/rwebspec/testwise_plugin.rb, line 6
def debug(message)
  Thread.pass
  connect_to_testwise(" DEBUG", message.to_s + "\r\n") if $RUN_IN_TESTWISE && message
end
dump_caller_stack() click to toggle source

find out the line (and file) the execution is on, and notify iTest via Socket

# File lib/rwebspec/testwise_plugin.rb, line 37
def dump_caller_stack
  return unless $ITEST2_TRACE_EXECUTION
  begin
    trace_lines = []
    trace_file = nil
    found_first_spec_reference = false
    caller.each_with_index do |position, idx|
      next unless position =~ /\A(.*?):(\d+)/
      trace_file = $1
      if trace_file =~ /(_spec|_test|_rwebspec)\.rb\s*$/
        found_first_spec_reference = true
        trace_lines << position
        break
      end
      trace_lines << position
      break if trace_file =~ /example\/example_methods\.rb$/ or trace_file =~ /example\/example_group_methods\.rb$/
      break if trace_lines.size > 10
      # TODO: send multiple trace to be parse with pages.rb

      # break if trace_file =~ /example\/example_methods\.rb$/ or trace_file =~ /example\/example_group_methods\.rb$/ or trace_file =~ /driver\.rb$/ or trace_file =~ /timeout\.rb$/ # don't include rspec or ruby trace

    end

    #  (trace_file.include?("_spec.rb") || trace_file.include?("_rwebspec.rb") || trace_file.include?("_test.rb") || trace_file.include?("_cmd.rb"))

    if !trace_lines.empty?
      connect_to_testwise(" TRACE", trace_lines.reverse.join("|"))
    end

  rescue => e
    puts "failed to capture log: #{e}"
  end
end
notify_screenshot_location(image_file_path) click to toggle source
# File lib/rwebspec/testwise_plugin.rb, line 32
def notify_screenshot_location(image_file_path)
  connect_to_testwise("  SHOT", image_file_path)
end
operation_delay() click to toggle source

Support of iTest to ajust the intervals between keystroke/mouse operations

# File lib/rwebspec/testwise_plugin.rb, line 13
def operation_delay
  begin
    if $ITEST2_OPERATION_DELAY && $ITEST2_OPERATION_DELAY > 0 &&
            $ITEST2_OPERATION_DELAY && $ITEST2_OPERATION_DELAY < 30000  then # max 30 seconds

      Thread.pass
      sleep($ITEST2_OPERATION_DELAY / 1000)
    end

    while $ITEST2_PAUSE
      Thread.pass
      debug("Paused, waiting ...")
      sleep 1
    end
  rescue => e
    puts "Error on delaying: #{e}"
    # ignore

  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.