<div id="completion-percent" class="state-{% if test is defined %}{{test.state}}{% endif %}">
    <h2 class="info"><i id="completion-percent-state-icon" class="{{ state_icon }}"></i>
        <span id="completion-percent-state-label">{{ state_label }}</span>        
    </h2>
    <div class="progress progress-striped active">
        <div id="completion-percent-bar" class="bar" style="width:{{ completion_percent }}%;"></div>
    </div>            
    <div id="completion-time-remaining">&nbsp;</div>

    {% if test.state == 'crawling' %}
    <form id="cancel-crawl-form" method="post" action="{{ path('test_cancel_crawl', {'test_id':test.testId, 'website':test.website}) }}">
        <button type="submit" class="btn btn-warning">Stop finding URLs, start testing</button>
    </form> 
    {% endif %}

</div> 
<div id="completion-percent" class="state-{% if test is defined %}{{test.state}}{% endif %}">
    <h2 class="info"><i id="completion-percent-state-icon" class="{{ state_icon }}"></i>
        <span id="completion-percent-state-label">{{ state_label }}</span>        
    </h2>
    <div class="progress progress-striped active">
        <div id="completion-percent-bar" class="bar" style="width:{{ completion_percent }}%;"></div>
    </div>            
    <div id="completion-time-remaining">&nbsp;</div>

    {% if test is defined and test.state == 'crawling' %}
    <form id="cancel-crawl-form" method="post" action="{{ path('test_cancel_crawl', {'test_id':test.testId, 'website':test.website}) }}">
        <button type="submit" class="btn btn-warning">Stop finding URLs, start testing</button>
    </form> 
    {% endif %}

</div> 
Check test is defined before checking state
Check test is defined before checking state
