Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

Required if != Pass


#1

Hi,
I wonder whether I am able to write a script that turns the following fields into mandatory if, and only if, the test result is != “Passed”

@Test Result screen:

Comment*
Version*
Assign To -> Set current user as default*
device_name (Custom field) *
Defects (Jira Plugin)*

Thank you very much,

Bruno.


#2

Done! :lol:

name: Mandatory
version: 1.0
author: Bruno Trentini
includes:
    excludes:

    js:
    $(document).ready(
        function() {
            $.subscribe('result_dialog.loaded', 'uiscript_require_elapsed', function(o) {
                $('#addResultElapsed').prev().append(' <span class="form-required">*</span>');
                $('#addResultVersion').prev().append(' <span class="form-required">*</span>');
                $('#addResultAssignTo').prev().append(' <span class="form-required">*</span>');
                $('#addResultDefects').prev().append(' <span class="form-required">*</span>');
                $('#addResultComment').parent().parent().prev('label').append(' <span class="required"><font color="#CF1B5D">*</font></span>');
                $('#custom_device_dropdown').prev().append(' <span class="form-required">*</span>');

            });

            $.subscribe('result_dialog.validate', 'uiscript_require_elapsed', function(o) {

                var ass_to = $("#addResultAssignTo option:selected").text();
                var dvc_sel = $("#custom_device_dropdown option:selected").text();
                var defeito = $.trim(o.values.defects)

                if ($.trim(o.values.status_id) != 1) {
                    if ($.trim(o.values.comment) == '') {

                        $('#addResultErrors').append('ATTENTION: Please insert a rich and detailed comment');
                        $('#addResultErrors').show();
                        $('#addResultComment').parent().parent().prev('label').append(' <span class="required"><font color="#CF1B5D"> ADD A COMMENT! </font></span>');

                        o.event.stopPropagation();
                        return;
                    }
                    if ($.trim(o.values.elapsed) == '') {
                        $('#addResultErrors').append("ATTENTION: Elapsed is mandatory!");
                        $('#addResultErrors').show();
                        $('#addResultElapsed').prev().append(' <span class="required"><font color="#CF1B5D"> Add an estimate! </font></span>');
                        o.event.stopPropagation();
                        return;
                    }
                    if ($.trim(o.values.version) == '') {
                        $('#addResultErrors').append("ATTENTION: Version is mandatory!");
                        $('#addResultErrors').show();
                        $('#addResultVersion').prev().append(' <span class="required"><font color="#CF1B5D"> Add your version! </font></span>');
                        o.event.stopPropagation();
                        return;
                    }
                    if (ass_to == '') {
                        $('#addResultErrors').append("ATTENTION: ASSIGN TO YOURSELF!");
                        $('#addResultErrors').show();
                        $('#addResultAssignTo').prev().append(' <span class="required"><font color="#CF1B5D"> Assign to yourself! </font></span>');
                        o.event.stopPropagation();
                        return;
                    }
                    if (dvc_sel == '') {
                        $('#addResultErrors').append("ATTENTION: Select an Operating System!");
                        $('#addResultErrors').show();
                        $('#custom_device_dropdown').prev().append(' <span class="required"><font color="#CF1B5D"> Select an OS! </font></span>');
                        o.event.stopPropagation();
                        return;

                    }
                    if (defeito == '') {
                        $('#addResultErrors').append("ATTENTION: PUSH TO JIRA");
                        $('#addResultErrors').show();
                        $('#addResultDefects').prev().append(' <span class="required"><font color="#CF1B5D"> PUSH! </font></span>');
                        o.event.stopPropagation();
                        return;
                    }

                }
            });
        }
    );

Request: UI script making it required to attach a file if testcase fails
#3

Hello Bruno,

Thanks for your posting. Yes, comparing the status_id is the recommended approach for this. Good to hear that you found this already. :slight_smile:

Regards,
Tobias


#4

Hi there,

I’m fairly new to this so this may be a question with an obvious answer, but I have a similar request and I’m not entirely sure how to adjust the script above to achieve what I want.

I’d like any test that is set to Failed to require a Comment and Defect, and any test that is Blocked to just require a comment. Is this something that can be achieved in one script? How would I set that up?

Many thanks,
Chris


#5

Hi Chris,
Off course there’s something you can do about it! :wink:

I assume you’re using JIRA’s plugin to test rail. I’ll do something like:

[code]

   var defeito = $.trim(o.values.defects)
   var result = $.trim(o.values.status_id); //Will get the result select in the result pop up

       if(result == 5)    {

//=======================================================
// COMMENT IS MANDATORY
// In MY CASE, “FAIL” is set to 5. Go to Administration > Manage Customisations
// Then click “FAIL” status and check the URL. Must be something like
// https://XYZ.testrail.com/index.php?/admin/statuses/edit/5*/
//=======================================================
if (.trim(o.values.comment) == '') { (’#addResultErrors’).append(‘ATTENTION: Please insert a rich and detailed comment’);
('#addResultErrors').fadeOut(100).fadeIn(100); (’#addResultComment’).parent().parent().prev(‘label’).empty();
$(’#addResultComment’).parent().parent().prev(‘label’).append(’ ADD A COMMENT! ').fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);

                o.event.stopPropagation();
                return;
            } else {

                $('#addResultComment').parent().parent().prev('label').empty();
                $('#addResultComment').parent().parent().prev('label').append(' <span class="required"><font color="#162B6B"> Ok! </font></span>');


            }

//=======================================================
// PUSH TO JIRA IS MANDATORY
//=======================================================

            if (defeito == '') {

                $('#addResultErrors').append("PUSH TO JIRA!");

$('.column.result-dialog-column-right').find('.form-group').eq(3).addClass('on').css({"border-color":     "#0066FF", 
         "border-width":"2px",
         "padding":"10px", 
         "border-style":"solid"});

        var $pushButton = $('#pushDefectLink').clone();
        var $loadingImg = $('#pushDefectLinkBusy').clone();
        var $newLabelText = $('<span class="required"><font color="#0066FF"> \t Push to Jira!</font></span>');

        $('#addResultDefects').prev().html('').append($newLabelText, $pushButton, $loadingImg);
        $newLabelText.fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);

                o.event.stopPropagation();
                return;

            } else {
        
                $('#addResultDefects').prev().empty();
                $('#addResultDefects').prev().append(' <span class="required"><font color="#162B6B"> Ok! </font></span>');
          
            }

        }

       } //END-IF

if(result == 6)
/*In MY CASE, “BLOCKED” is set to 6.
{
//=======================================================
// COMMENT IS MANDATORY
//=======================================================
if (.trim(o.values.comment) == '') { if (.trim(o.values.comment) == ‘’) {
('#addResultErrors').append('ATTENTION: Please insert a rich and detailed comment'); (’#addResultErrors’).fadeOut(100).fadeIn(100);
('#addResultComment').parent().parent().prev('label').empty(); (’#addResultComment’).parent().parent().prev(‘label’).append(’ ADD A COMMENT! ').fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);

                o.event.stopPropagation();
                return;
            } else {

                $('#addResultComment').parent().parent().prev('label').empty();
                $('#addResultComment').parent().parent().prev('label').append(' <span class="required"><font color="#162B6B"> Ok! </font></span>');

}

       } //END-IF

    });
}

);[/code]


#6

Where exactly would I put this code to achieve these results?


#7

https://<YOUR_URL_COMPANY_NAME>.testrail.com/index.php?/admin/uiscripts/add

I assume you’re familiar with JQuery and with TestRails’ UI Scripts:
http://docs.gurock.com/testrail-custom/uiscripts-introduction

Copying and pasting this code into the link above won’t get you a solution. Can you elaborate a little more about the context in which you intend to use this solution?


#8

Thank you so much for that script! It helps me a lot!