Module: RWebSpec::TestWisePlugin
- Included in:
- Driver
- Defined in:
- lib/plugins/testwise_plugin.rb
Instance Method Summary collapse
- #check_for_pause ⇒ Object
- #connect_to_testwise(message_type, body) ⇒ Object
- #debugging? ⇒ Boolean
-
#dump_caller_stack ⇒ Object
find out the line (and file) the execution is on, and notify iTest via Socket.
- #fetch_debug_server_status ⇒ Object
- #notify_screenshot_location(image_file_path) ⇒ Object
-
#operation_delay ⇒ Object
Support of TestWise to ajust the intervals between keystroke/mouse operations.
- #write_to_console(message) ⇒ Object (also: #debug)
Instance Method Details
#check_for_pause ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/plugins/testwise_plugin.rb', line 113 def check_for_pause json_data = fetch_debug_server_status if json_data["testwise_ready_to_pause"] # Already executed the the line immedately above, # give some buffer time for TW to set $TESTWISE_PAUSE flag sleep 0.5 end # If the executed line no change, ignore while json_data["testwise_pause"] || $TESTWISE_PAUSE Thread.pass write_to_console("[rwebspec] Paused, waiting ...") sleep 1 json_data = fetch_debug_server_status end end |
#connect_to_testwise(message_type, body) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/plugins/testwise_plugin.rb', line 91 def connect_to_testwise(, body) Thread.pass testwise_port = $TESTWISE_TRACE_PORT || ENV["TESTWISE_TRACE_PORT"].to_i || 7025 testwise_socket = nil begin = + "|" + body if @last_message == then # ignore the message same as preivous one return end testwise_socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) testwise_socket.connect(Socket.pack_sockaddr_in(testwise_port, '127.0.0.1')) testwise_socket.puts() @last_message = rescue => e puts "Failed to connect to TestWise on port #{testwise_port}, #{e}, #{e.backtrace}" ensure if testwise_socket testwise_socket.close(); end end end |
#debugging? ⇒ Boolean
10 11 12 13 14 15 |
# File 'lib/plugins/testwise_plugin.rb', line 10 def debugging? if ENV["TESTWISE_DEBUGGING"].to_s == "true" && ENV["TESTWISE_RUNNING_AS"] == "test_case" return true end return $TESTWISE_DEBUGGING && $TESTWISE_RUNNING_AS == "test_case" end |
#dump_caller_stack ⇒ Object
find out the line (and file) the execution is on, and notify iTest via Socket
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 |
# File 'lib/plugins/testwise_plugin.rb', line 59 def dump_caller_stack return unless (ENV["TESTWISE_TRACE_EXECUTION"].to_s == "true" || $TESTWISE_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*$/ || trace_file =~ /\.feature$/ 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 |
#fetch_debug_server_status ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/plugins/testwise_plugin.rb', line 133 def fetch_debug_server_status testwise_debug_server_port = ENV["TESTWISE_DEBUG_PORT"].to_i || $TESTWISE_DEBUG_PORT || 7035 if testwise_debug_server_port puts "debug server port: #{testwise_debug_server_port}" server = TCPSocket.open("127.0.0.1", testwise_debug_server_port) server.puts("debug_status") msg = server.gets.chomp server.close json_data = JSON.parse(msg) end end |
#notify_screenshot_location(image_file_path) ⇒ Object
54 55 56 |
# File 'lib/plugins/testwise_plugin.rb', line 54 def notify_screenshot_location(image_file_path) connect_to_testwise(" SHOT", image_file_path) end |
#operation_delay ⇒ Object
Support of TestWise to ajust the intervals between keystroke/mouse operations
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/plugins/testwise_plugin.rb', line 33 def operation_delay begin $TESTWISE_OPERATION_DELAY = ENV["TESTWISE_OPERATION_DELAY"] if ENV["TESTWISE_OPERATION_DELAY"] && ENV["TESTWISE_OPERATION_DELAY"].to_i > 0 if $TESTWISE_OPERATION_DELAY && $TESTWISE_OPERATION_DELAY > 0 && $TESTWISE_OPERATION_DELAY < 30000 then # max 30 seconds Thread.pass sleep($TESTWISE_OPERATION_DELAY / 1000) end while (ENV["TESTWISE_PAUSE"] && ENV["TESTWISE_PAUSE"].to_s == "true") || $TESTWISE_PAUSE Thread.pass debug("Paused, waiting ...") sleep 1 end rescue => e puts "Error on delaying: #{e}" # ignore end end |
#write_to_console(message) ⇒ Object Also known as: debug
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/plugins/testwise_plugin.rb', line 17 def write_to_console() Thread.pass if (ENV["RUN_IN_TESTWISE"] && ENV["RUN_IN_TESTWISE"].to_s == "true" || $RUN_IN_TESTWISE) && the_sent_msg = .to_s if the_sent_msg.size > MAX_MESSAGE_LENGTH the_sent_msg = the_sent_msg[0..MAX_MESSAGE_LENGTH] + "..." end connect_to_testwise(" DEBUG", the_sent_msg + "\r\n") else puts end end |