Quantcast
Channel: Gurock Software Support Forum
Viewing all articles
Browse latest Browse all 829

[UI Script] Mark test as passed and forward to the next

$
0
0

In our team, we usually don't add any information to test results when the test is successful. Previously, on an individual test page we had to click "Add Test Result", then submit it, and then click one more button to navigate to the next test in the run. To make this a one-click experience I wrote the following script:

name: Mark test as passed and go to next
description: Adds a button to a test page that allows to mark it as passed and proceed to the next test in one click
author: Paul Danyliuk
version: 1.0
includes: ^tests/view
excludes:

js:
var passAndForward = function(onSuccess, onFailure) {
    // Get testId from UI Scripts context (see the doc)
    var testId = uiscripts.context.test.id;

    // Mock the data as collected from the form and passed to App.Tests.addChange as "c" parameter
    var postData = {
        test_id     : testId,
        status_id   : '1',
        is_result   : true,
        comment     : '',
        defect      : '',
        assignedto  : '',
        attachments : '',
        version     : '',
        elapsed     : ''
    };

    // Hook to the "tests.changed" event that fires after request is completed along with visual feedback
    $.subscribe('tests.changed', 'qaextensions', function(data) {
        App.Tests.loadNext(testId);
    });

    // Invoke the "add test result" method from TestRail's client-side JavaScript
    App.Tests.addChange(postData, {
        success : onSuccess,
        error   : onFailure
    });
};

$(document).ready(function() {
    // Create the button
    var passAndForwardButton = $('<a id="passAndForwardButton"><img src="images/icons/accept.png"/> <span>Mark as passed and go to next</span></a>');

    // Define behavior (make button disabled after click etc)
    var onClick = function(button) {
        var $btn = $(button);
        if (!$btn.hasClass('disabled')) {
            $btn.addClass('disabled');
            var cachedSrc = $btn.find('img').attr('src');
            $btn.find('img').attr('src', 'images/animations/progressStandard.gif');
            passAndForward(
                function() {
                    // On success, make the button react (don't re-enable it)
                    $btn.find('img').attr('src', cachedSrc);
                    $btn.find('span').text("Done!");
                    $btn.attr('title', "If redirect doesn't happen, check if this is the last test in this suite");
                },
                function(err) {
                    // On failure - show alert, then re-enable the button
                    alert(err.error);
                    $btn.removeClass('disabled');
                    $btn.find('img').attr('src', cachedSrc);
                }
            );
        }
    };

    // Add event listener to the button
    passAndForwardButton.on('click', function() {
        onClick(this)
    });

    // Add it to the left of Add Test Result button in the bottom
    $('a#addResult').before(passAndForwardButton);
});

Note: This script uses TestRail's client-side code, which can be altered any time unlike REST API, so if/when it's changed, the user script will probably break. But going this way was preferable because it didn't require coding REST handling, and gave the usual animated feedback out of the box.

With best regards,
Paul


Viewing all articles
Browse latest Browse all 829

Trending Articles