
<% next_sort_direction = "ASC" %>
<%
  if @sort_direction
    if @sort_direction == "ASC"
      next_sort_direction = "DESC"
    else
      next_sort_direction = "ASC"
    end
  end
%>

<%  
  build_test_files = @test_files || @build.test_files || []
  the_project_config = @project.config
%>

<% if @build.is_parallel %>
   <% ui_test_duration = 0 %>
    <% build_test_files.each do |bf|
      ui_test_duration += (bf.duration || 0)
    end %>
<% end %>	

  <% if !@build.is_parallel %>
      <% @build_ui_test_count = 0 %>
      <% build_test_files.each { |x| @build_ui_test_count += x.test_cases.size } %>
  <% end %>

  <% if @build_ui_test_count > 0 || @build.is_parallel %>
      <% @step.reload.is_ui_test  rescue nil %>

<div class="<% if @step.nil? || @step.is_ui_test %>section_open<% else %>section_closed<% end %>">
  <div class="section_header" onclick="toggle_section(this.parentNode)">

    <% if @step && @step.is_ui_test %>
      <%= @step.reload.task_name %> <%= I18n.t(:results) %>
    <% else %>
      <%= I18n.t(:test_results) %> 
    <% end %>
    
    <span class="subtitle">( <span style="color:blue"><%= @build_ui_test_count rescue 0 %></span> <%= I18n.t(:tests) %></span> 

	 &nbsp; 
	 <% if  !@build.incomplete? && @build.is_parallel %>
   <i><%= I18n.t(:pass_rate)%>: <b><%= @build.chart_data["pass_rate"] rescue "" %></b></i>
       &nbsp;
 	 <% end %>
	 
      <% if @build.ui_test_status && (@build.ui_test_status == "OK" || @build.ui_test_status == "Failed") %>

			<% if defined?(ui_test_duration) && ui_test_duration && ui_test_duration.to_i > 1 && @build.duration && @build.duration > 1 %>

				<span>took <span style="color:blue"><%= format_seconds(@build.duration) rescue nil %></span></span>

			    <% if @build.is_parallel && !@build.is_load_testing %>
			    <span> on 
						<span style="color: blue;"><%=@build.build_agents.size rescue 1 %></span> 
						agents,
					</span>							
					
					 <span style="font-size: 15px;"> <%= format_seconds(ui_test_duration) rescue nil %></span>
          <% end %>
				
			    <% if @build.is_parallel && !@build.is_load_testing %>
           <span>if one machine</span>
					<% end %>
			  <% end %>
		
			<% end %>
		)
		
    <span class="hidden-print">
    <% if @build.ui_test_status.nil? && @build.incomplete? %>
        <img src="/images/loading.gif"/>
    <% end %>     
	  </span>
  </div>

  <div class="section_content">
						
  	<%if @build.is_performance_testing %>
      <%=  partial(:'builds/performance_test_results', :locals => {:build => @build}) %>					
  	<% end %>
	
  	<div class="pull-right hidden-print" id="export">

  		<div class="dropdown">
  		  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true"  data-bs-toggle="dropdown" aria-expanded="false" style="padding:2px 5px;">
  		    <%= I18n.t(:export)%>
  		    <span class="caret"></span>
  		  </button>
  		  <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu1">
  		    <li><a class="dropdown-item" href="/builds/<%= @build.id %>/export_test_results_excel"> 
  					<label class="dropdown-menu-icon"><i class="fa fa-file-excel-o"></i></label>   Excel</a></li>
  				<li><a class="dropdown-item" href="/builds/<%= @build.id %>/export_ui_test_results">
  					<label class="dropdown-menu-icon"><i class="fa fa-file-text-o"></i></label>  CSV</a></li>
  				<li><hr class="dropdown-divider"></li>								 
  				<li><a  class="dropdown-item" href="javascript:window.print();"> 
  					<label class="dropdown-menu-icon"><i class="fa fa-print"></i></label> <%= I18n.t(:print_to_pdf) %></a></li>
  		  </ul>
  		</div>
  	</div>
					
		<% unless @build.incomplete? %>
    
    <div class="row no-gutters">
        <div class="col-md-9 col-sm-8" style="padding: 0px;">
          	<input type="search" class="form-control border-right-0 rounded-0" id="searchTextbox" placeholder="<%= I18n.t(:placeholder_filter_test)%>" onkeyup="onSearch()" style=" border: 1px solid #ced4da;"/>

        </div>
        <div class="col-md-2"  style="padding: 0px; margin-left: -1px;">
            <button class="btn btn-outline-secondary border-left-0 rounded-0 rounded-right" type="button" style="border: 1px solid #ced4da;" onclick="onSearch();">
                <i class="fa fa-search"></i>
            </button>
        </div>
    </div>
    
<!--    
		<div style="margin-bottom: 7px;" class="hidden-print">
			<div class="row" style="height: 32px;">
				<div class="col-md-9 col-sm-8">
					<input type="text" class="form-control" id="searchTextbox" placeholder="<%= I18n.t(:placeholder_filter_test)%>" onkeyup="onSearch()" style="padding-top:4px; padding-bottom:4px;"/>
				</div>
				<div class="col-md-2" style="padding-top: 7px;">
						<span id="search_spinner" style="display:none;"><i class="fa fa-spinner fa-spin fa-lg fa-fw"></i></span>
						<span id="match_results_count" class="match_results"></span>
				</div>
			</div>
		</div>
-->       
		<% end %>
					
		<% troubled_test_files =  @build.test_files.select{|x| x.test_cases.size == 0 && x.result == "OK" } %>
		<% if troubled_test_files.any?  %>
		<div id="troubled_test_files" class="alert alert-warning" style="margin-top: 10px;">	
			<p>No results returned (from agents) for the following test scripts:</p>
			<ul>
				<% troubled_test_files.each do |x| %>
				<li><a href="#file_<%= File.basename(x.filename).parameterize %>"><%= x.filename %></a></li>
				<% end %>
			</ul>
		</div>
		<% end %>

  <table class="table table-bordered table-hover" border="0" cellspacing="0" align="center" id="test_results_table">
    <thead class="">
			<tr>
        <% if @build.is_parallel && !@build.incomplete? %>
        <th>
          <a <% if @sort_column == "assigned_at" %>class="sorted_column" <% end %>
             href="/builds/<%= @build.id %>?sort=assigned_at&amp;sort_direction=<%= next_sort_direction %>"><i class="fa fa-clock-o" aria-hidden="true" style="font-size: 1.15em;" ></i></a>		
          <% if @sort_column == "assigned_at" %><i class="fa <%= @sort_direction.downcase == "asc"  ? 'fa-sort-asc' : 'fa-sort-desc' %>" aria-hidden="true"></i><% end %>
        </th>
        <% end %>
    <% if @build.is_parallel %>
        <th width="10%"  nowrap="true">
          <% if @build.incomplete? %>
            <%= I18n.t(:agent) %>
          <% else %>
          
          <a <% if @sort_column == "agent" %>class="sorted_column"<% end %>
href="/builds/<%= @build.id %>?sort=agent&amp;sort_direction=<%= next_sort_direction %>"><%= t(:agent) %></a>
          <% if @sort_column == "agent" %><i class="fa <%= @sort_direction.downcase == "asc"  ? 'fa-sort-asc' : 'fa-sort-desc' %>" aria-hidden="true"></i><% end %>
          <% end %>
        </th>
    <% else %>
      <th width="10%"  nowrap="true">				  
        <a <% if @sort_column == "last_modified" %>class="sorted_column" <% end %>
           href="/builds/<%= @build.id %>?sort=last_modified&amp;sort_direction=<%= next_sort_direction %>"><i class="fa fa-clock-o" aria-hidden="true"></i></a>					 
        <% if @sort_column == "last_modified" %><i class="fa <%= @sort_direction.downcase == "asc"   ? 'fa-sort-asc' : 'fa-sort-desc' %>" aria-hidden="true"></i><% end %>
			</th>
    <% end %>
    <th width="80%">
      <% if @build.incomplete? %>
       <%= I18n.t(:test_file)%>  <i class="" style="font-weight: 400; text-transform: lowercase">(<%= @build_ui_test_count rescue 0 %> <%= I18n.t(:test_cases) %>  in <%= @build.test_files.size %> <%= I18n.t(:test_script_files) %>)</i>
      <% else %>
      
      <a <% if @sort_column == "filename" %>class="sorted_column" <% end %> href="/builds/<%= @build.id %>?sort=filename&amp;sort_direction=<%= next_sort_direction %>"><%= I18n.t(:test_file)%></a>

<% if @sort_column == "filename" %><i class="fa <%= @sort_direction.downcase == "asc" ? 'fa-sort-asc' : 'fa-sort-desc' %>" aria-hidden="true"></i><% end %>

			<span class="subtitle-small hidden-print" >
			&nbsp;(
        <%= @build_ui_test_count rescue 0 %>
        <a href="#" onclick="show_test_case_results(); return false;"><%= I18n.t(:test_cases) %></a>
        <% if !@build.incomplete? %> in <%= @build.test_files.size %> <a href="#" onclick="show_test_file_results(); return false;"><%= I18n.t(:test_script_files) %></a> <% end %>)</span>
        <% end %>
    </th>
    <th width="5%" nowrap="true">
      <% if  @build.incomplete? %>
        <%= I18n.t(:time_heading) %>
      <% else %>
       <a  <% if @sort_column == "duration" %>class="sorted_column"  <% end %>
    href="/builds/<%= @build.id %>?sort=duration&amp;sort_direction=<%= next_sort_direction %>"><%= I18n.t(:time_heading) %></a>
      <% end %>
<% if @sort_column == "duration" %><i class="fa <%= @sort_direction.downcase == "asc"   ? 'fa-sort-asc' : 'fa-sort-desc' %>" aria-hidden="true"></i><% end %>
    </th>
    <th width="5%"  nowrap="true">
      <% if @build.incomplete? %>
        <%= I18n.t(:result) %>
      <% else %>
      <a <% if @sort_column == "successful" %>class="sorted_column" <% end %> href="/builds/<%= @build.id %>?sort=successful&amp;sort_direction=<%= next_sort_direction %>"><%= I18n.t(:result) %></a>
      <% end %>
  <% if @sort_column == "successful" %><i class="fa <%= @sort_direction.downcase == "asc"   ? 'fa-sort-asc' : 'fa-sort-desc' %>" aria-hidden="true"></i><% end %>      
    </th>

  <% if @build.is_parallel %>
    <th width="5%" nowrap="true" style="text-align: center; padding-left: 10px; padding-right: 10px;">
      <% if  @build.incomplete? %>
				<i class="fa fa-sort-amount-desc fa-lg" aria-hidden="true" style="font-size: 1.15em;"></i>
      <% else %>
		<a data-toggle='tooltip' data-placement='top' title='<%= I18n.t(:sort_by_priority)%>'
    	<% if @sort_column == "priority" %>class="sorted_column" <% end %>
			href="/builds/<%= @build.id %>?sort=priority&amp;sort_direction=<%= next_sort_direction %>">

			<% if @sort_column == "priority" && @sort_direction.downcase == "asc"  %>
				<i class="fa fa-sort-amount-asc" aria-hidden="true" style="font-size: 1.15em;"></i>
		  <% else %>
				<i class="fa fa-sort-amount-desc fa-lg" aria-hidden="true" style="font-size: 1.15em;"></i>
		  <% end %>
		</a>
    <% end %>
    </th>
  <% end %>

	<th class="test_execution"  <% unless @session_test_execution_enabled %>style="display:none;"<% end %>>	
		<a href="#" data-toggle="tooltip" data-placement="bottom" title="<%= I18n.t(:execute_test_on_server_hint)%>"> <i class="fa fa-question-circle-o" aria-hidden="true"></i></a>
	</th>
</thead>

<tbody>
  <% count = 0 %>
  <% build_test_files.each_with_index do |test_file, fidx| %>
		<% test_file_id =  test_file.id || fidx  %>
    <tr class="test_file_row test_file_row_striped" id="test_file_<%= test_file_id %>">
      <% if @build.is_parallel && !@build.incomplete? %>
      <td><%= test_file.assigned_at.localtime.strftime("%H:%M:%S") rescue nil %></td>
      <% end %>

    <% if @build.is_parallel %>
      <td class="first_column" valign="top" nowrap="true">
        <% if @build.incomplete? &&  test_file.is_assigned? && test_file.result.nil?   %><img id="running_<%= test_file_id %>" src="/images/tiny_red.gif"/><% end %>
        <%= test_file.agent %><br/>
        <% if test_file.past_agents %><% if test_file.is_assigned? && test_file.result.nil? %>&nbsp;&nbsp;<% end %>
          <span class="failed_agent">(<i><%= test_file.past_agents %></i>)</span>
        <% end %>
      </td>
	  <% else %>
      <td class="first_column" valign="top" nowrap="true"><%= test_file.last_modified.localtime.strftime("%m-%d %H:%M") rescue nil%></td>
	  <% end %>

    <td <% unless @build.is_parallel %>class="first_column" <% end %> valign="top">
      <span class="test_file_name">
        <% if test_file_id %>
          <% if test_file.test_cases.size == 0 && test_file.result == "OK" %><i class="fa fa-warning orange" aria-hidden="true"></i><% end %>

          <a name="file_<%= File.basename(test_file.filename).parameterize %>"  class="test-history-link"  href="javascript:void(0);" onclick="$.getScript('/test_files/<%= test_file_id %>/history');" data-toggle="tooltip" data-placement="bottom" title="<%= I18n.t(:show_execution_history)%>"><%= File.basename(test_file.filename) rescue nil %></a>
        <% else  %>
          <%= File.basename(test_file.filename) rescue nil %>
        <% end %>
			</span>

		<% if @build.is_parallel || !@build.incomplete? %>
		  <% unless @build.test_framework == "JUnit"%>
        <a class="test-file-link hidden-print" data-id="<%= test_file_id %>" data-name="<%= File.basename(test_file.filename) %>"><i class="fa fa-file-text-o" aria-hidden="true" data-toggle="tooltip" data-placement="bottom" title="<%= I18n.t(:show_test_script)%>"></i></a>
		  <% end %>
		<% end %>

      <% if @build.is_parallel && test_file && test_file.browser %><%= raw browser_image(test_file.browser) %><% end %>

			<% if test_file && !test_file.stdout.blank? %>&nbsp;
        <a class="test-stdout-link" data-id="<%= test_file_id %>" data-name="<%= File.basename(test_file.filename) %>" href="javascript:void(0);" onclick="$('#test_<%=test_file_id%>_stdout').toggle();"><%= I18n.t(:stdout)  %></a>
			<% end %>

			<% if test_file && !test_file.stderr.blank? %>&nbsp;
        <a class="test-stderr-link" data-id="<%= test_file_id %>" data-name="<%= File.basename(test_file.filename) %>" href="javascript:void(0);" onclick="$('#test_<%=test_file_id%>_stderr').toggle();"><%= I18n.t(:stderr)  %></a>
			<% end %>

      <% if settings.testwise_integration %>
      <div style="float:right"><a href="testwise://<%= test_file.local_source_path(@build) %>"><i class="fa fa-share-square-o"></i></a></div>
      <% end %>
<% test_file_comments =  test_file.comments %>
      <% if test_file_comments && (test_file.result == "Error" || (test_file_comments.downcase.start_with?("error") || test_file_comments.downcase.include?("failed") )) %>
          <br><code><%= test_file_comments %></code>
      <% end %>

			<% if test_file && !test_file.stdout.blank? %>										
			<div class="test-case-stdout" id="test_<%=test_file_id%>_stdout" style="display:none;">
        <button type="button" class="btn btn-dark btn-clipboard" onclick="copyToClipboard('test_<%=test_file_id%>_stdout_content');" >Copy to Clipboard</button>
				<pre class="script" id="test_<%=test_file_id%>_stdout_content"><% if the_project_config && the_project_config.highlight_test_output%><code class="xml"><%= test_file.stdout.strip %></code><% else%><%= test_file.stdout.strip %><% end %></pre>
			</div> 
			<% end %>

			<% if test_file && !test_file.stderr.blank? %>										
			<div class="test-case-stderr" id="test_<%=test_file_id%>_stderr" style="display:none;">
				<pre class="script"><% if the_project_config && the_project_config.highlight_test_output%><code class="xml"><%= test_file.stderr.strip %></code><% else%><%= test_file.stderr.strip %><% end %></pre>
			</div> 
			<% end %>

    </td>
    <td nowrap="true" valign="top" align="right">
      <% if test_file.duration %><b><%= test_file.safe_duration %></b>
      <% elsif test_file.elpased_time > 300 %><span class="long_test"><%= sprintf('%.1f', test_file.elpased_time) %> ...</span>
      <% end %></td>
    <td align="center" nowrap="true">
      <% if @build.is_parallel && @build.incomplete? %>
        <% if test_file.is_assigned? || !test_file.past_agents.blank? %>
          <% if test_file.result == "Failed" || test_file.elpased_time > 30 %>
            <a id="rerun_<%= test_file_id %>" href="javascript:void(0);" data-id="<%= test_file_id %>" onclick="$.getScript('/test_files/<%= test_file_id %>/rerun');" class=" <% if test_file.result == 'OK'%>rerun_unnecessary<% end %>" href="javascript:void(0);" data-url="/test_files/<%= test_file_id %>/rerun"><%= I18n.t(:rerun)%></a>
          <% end %>
        <% end %>
      <% elsif @build.is_parallel && test_file.test_cases.size == 0 %>
        <% if @build.status && @build.status == "cancelled" %>
        <% else %> <span class="red"><%= I18n.t(:no_tests) %></span>
        <% end %>

      <% elsif test_file.result == "Error"%> <span class="red"><%= I18n.t(:error) %></span>
      <% else %> <span class="test_file_result <% if test_file.failed? %>failed<% end %>" style="display:none;"><%= test_file.failed? ? I18n.t(:failed) : "OK" %></span>
      <% end %>
    </td>
    
  <% if @build.is_parallel %>
      <td style="text-align:center;">&nbsp;<% if @build.incomplete? %><a href="javascript:void(0);" onclick="update_test_file_priority('<%= test_file.filename %>', <%= test_file_id %>, <%= test_file.priority %> );" id="test_file_<%= test_file_id %>_priority"><%= test_file.priority %></a><% else %><%= test_file.priority %><% end %></td>
  <% end %>

		<td class="test_execution" <% unless @session_test_execution_enabled %>style="display:none;"<% end %>>
			<% if test_file && test_file.test_cases.size  > 0 %>
			<button <% if @building_in_progress %>disabled="true"<% end %> id="execute_test_file_<%= test_file_id%>" onclick="execute_test_file(<%= test_file_id %>)" class="btn btn-default btn-xs"><%= I18n.t(:execute)%></button>
			<i id="execute_test_file_spin_<%= test_file_id%>" class="fa fa-spinner fa-spin fa-lg fa-fw" style="display:none;"></i>
			<% end %>
		</td>
  </tr>

  <% test_cases_in_file = test_file.test_cases %>
  <% test_cases_in_file.each_with_index do |test_case, idx| %>
    <% if RACK_ENV == "showcase"%> <% test_case.name = "Test Case ##{test_case.id} - hidden in ShowCase mode"%><% end %>
    <% count += 1 %>
    <tr id="test_case_<%= test_case.id || ''%>"  <% if idx % 2 == 0 %>class="odd test_case_row" <% end %> class="test_case_row">                 
    <% if @build.is_parallel && !@build.incomplete? %><td>&nbsp;</td><% end%>                  
      <td class="first_column" valign="top">&nbsp;</td>
      <td <% unless @build.is_parallel %>class="first_column"<% end %>  valign="top">
&nbsp; &nbsp; - <%= test_case.name %></td>
      <td nowrap="true" valign="top" align="right"><%= test_case.safe_duration %></td>
      <td align="center">
        <% if test_case.failure %>
          <span class="result-failure"><a href='javascript:void(0);' onclick='show_test_failure_output("<%= h test_file.filename %>", "<%= h escape_quotes(test_case.name) %>", <%= count %>, "<%=  test_case.screenshot %>")' data-id='<%= count %>' test-case-id="<%= test_case.id %>"><% if !@build.is_parallel && test_case.screenshot %><i class="fa fa-warning" aria-hidden="true" style="margin-right: 0.5em;"></i><% else%><%= I18n.t(:failure) %><% end %></a></span>
        <% elsif test_case.error %><span class="result-error"><%= I18n.t(:error) %></span>
        <% else %><span class="result-ok">OK</span>
        <% end %>

				<% if !@build.is_parallel && test_case.screenshot %>
					<a href='javascript:void(0);' onclick='show_test_failure_screenshot("<%= h test_file.filename %>", "<%= h escape_quotes(test_case.name) %>", <%= count %>, "<%=  test_case.screenshot %>")' data-id='<%= count %>' test-case-id="<%= test_case.id %>"><i class="fa fa-camera" aria-hidden="true" style="color: #222;"></i></a>
				<% end %>
      </td>
    <% if @build.is_parallel %>
        <td align="center">
					<% if test_case.screenshot %>
						<a href='javascript:void(0);' onclick='show_test_failure_screenshot("<%= h test_file.filename %>", "<%= h escape_quotes(test_case.name) %>", <%= count %>, "<%=  test_case.screenshot %>")' data-id='<%= count %>' test-case-id="<%= test_case.id %>"><i class="fa fa-camera" aria-hidden="true" style="color: #222;"></i></a>
					<% else %>&nbsp;
					<% end %>
				</td>
    <% end %>
				<td class="test_execution" <% unless @session_test_execution_enabled %>style="display:none;"<% end %>>        
					<% if ".rb" == File.extname(test_file.filename) %>             
            <% test_case_has_wildcards =  test_case.spec_behaviour.wildcards rescue nil %>
            <% if test_case_has_wildcards && test_case_has_wildcards.count > 0 %>
              <button <% if @building_in_progress %>disabled="true"<% end %> id="execute_test_case_<%= test_case.id%>" onclick="show_test_case_execution_modal(<%= test_case.id %>)" class="btn btn-light btn-xs"><%= I18n.t(:execute)%></button>
							<i id="execute_test_case_spin_<%= test_case.id%>" class="fa fa-spinner fa-spin fa-lg fa-fw" style="display:none;"></i>		
            <% else %>
              <button <% if @building_in_progress %>disabled="true"<% end %> id="execute_test_case_<%= test_case.id%>" onclick="execute_test_case(<%= test_case.id %>)" class="btn btn-light btn-xs"><%= I18n.t(:execute)%></button>
							<i id="execute_test_case_spin_<%= test_case.id%>" class="fa fa-spinner fa-spin fa-lg fa-fw" style="display:none;"></i>		
            <% end %>
          <% end %>
				</td>
      </tr>

      <tr id="test_details_<%= count %>" style="display: none; font-size: 11px;">
        <td colspan="4" class="first_column">
          <% if test_case.failure %><pre id="test_error_details_<%= count %>" style="width: 96%;"><%= h test_case.failure %></pre><% end %>&nbsp;
          <% if test_case.error %><pre id="test_error_details_<%= count %>"><%= h test_case.error %></pre><% end %>
        </td>
        <% if @build.is_parallel %><td></td><% end %>
      </tr>

                <% end %>
            <% end %>
						</tbody>
          </table>
        </div>
      </div>
  <% end %>
  
	
<script type="text/javascript">
 
	$.fn.scrollTo = function (speed) {
	    if (typeof(speed) === 'undefined')
	        speed = 1000;

	    $('html, body').animate({
	        scrollTop: parseInt($(this).offset().top)
	    }, speed);
	};
	
  function highlight(elementId){
      $('#' + elementId).addClass("highlight");
      setTimeout(function () {
            $('#' + elementId).removeClass('highlight');
      }, 2000);
  }
  
  function copyToClipboard(elementId){ 
    let elementText = document.getElementById(elementId).innerHTML;    
    
    if (navigator.clipboard) {
      // works locally and with HTTPS, but not the server    
      navigator.clipboard.writeText(elementText).then(() => {
        console.log('Content copied to clipboard');
        highlight(elementId);
        /* Resolved - text copied to clipboard successfully */
      },() => {
        console.error('Failed to copy');
        /* Rejected - text failed to copy to the clipboard */
      });
    } else {
      console.log("failed because navigator.clipboard is not accessible. ")
      alert("Copy to clipboard failed due to navigator.clipboard permissions.")     
    }
  }
  
  $(document).ready(function () {
    
		var pointer = 0;
		var elemXpath = 'span.result-failure';
		var elemCount = 0;
		
		document.addEventListener('keyup', function (event) {
	    if (event.defaultPrevented) {
	        return;
	    }
			
			var focused = $(document.activeElement);
			if (focused.length > 0 && focused[0].tagName != "BODY") {
				// if focus on an element, e.g. input, don't worry about scrolling
				return;
			}
			
	    var key = event.key || event.keyCode;
	    if (key === 'Escape' || key === 'Esc' || key === 27) {
	      // ();
				console.log("press Esc");
	    } else if (key === "e") {
				elemXpath = 'span.result-failure';
				elemCount = $(elemXpath).length;
				if (elemCount > 0) { 
					pointer = 0;
					var elem = $(elemXpath)[pointer];
					if (elem) { 					
						$(elem).scrollTo();
					}
				}
	    } else if (key === "n") { // next
				elemCount = $(elemXpath).length;
				pointer += 1;
				if (pointer >= elemCount) {
					pointer = 0;
				}
				var elem = $(elemXpath)[pointer];
				if (elem) { 
					$(elem).scrollTo();
				}
	    }
			
		});
		
	});
	
</script>