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

UI script for Test Result Adding customization


#1

Hi Tobias.
I would like to add to our testrail the rule of forcing testers to push/select mandatory a defect when the status is “Failed”. Browsing on this forum, I was able to modify an existing UI script to make the Defect field mandatory, see below:

name: Conditional test result
description: Makes the Elapsed field required on the Add Test Result dialog
author: XXXX
version: 1.0
includes:
excludes:
js:
(document).ready( function() { .subscribe(‘result_dialog.loaded’, ‘uiscript_require_defects’, function(o)
{
('#addResultDefects').prev().append(' <span class="form-required">*</span>'); }); .subscribe(‘result_dialog.validate’, ‘uiscript_require_defects’, function(o)
{
if (.trim(o.values.defects) == '') { (’#addResultErrors’).append(‘Field Defects is a required field.’);
$(’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
});
}
);

Now can you please help me to understand how to modify this UI script to get also the condition for the status=Failed as well ? It has to check status and defect field. I was trying something like that:

name: Conditional test result
description: Makes the Elapsed field required on the Add Test Result dialog
author: XXX
version: 1.0
includes:
excludes:
js:
(document).ready( function() { .subscribe(‘result_dialog.loaded’, ‘uiscript_require_defects’, function(o)
{
('#addResultDefects').prev().append(' <span class="form-required">*</span>'); }); .subscribe(‘result_dialog.validate’, ‘uiscript_require_defects’, function(o)
{
if (.trim(o.values.defects) == '' && .trim(o.values.status) == ‘Failed’)
{
('#addResultErrors').append('Field Defects is a required field.'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
});
}
);

but it doesn’t work, somehow it looks like I should subscribe also to something else for the status.
I look forward to hearing back.

Many thanks,
Giuseppe


#2

Hi Giuseppe,

If you got the event callback working (result_dialog.validate), you can simply log the passed o parameter to the JavaScript Console to see all attributes (via console.log(o)). For example, the status is available via o.values.status_id and this is the numeric ID of the selected status. You can find a list in the API documentation:

http://docs.gurock.com/testrail-api2/reference-statuses

Failed would be ID 5.

I hope this helps!

Cheers,
Tobias


#3

Hi Tobias,
thanks so much for the info for the status_id. With this info I could implement something like that:

name: Conditional test result
description: Makes the field defect mandatory when the status is failed
author: Giuseppe & Giovanni
version: 1.0
includes:
excludes:

js:
(document).ready( function() { .subscribe(‘result_dialog.loaded’, ‘uiscript_require_defects’, function(o)
{
('#addResultDefects').prev().append(' <span class="form-required">*</span>'); }); .subscribe(‘result_dialog.validate’, ‘uiscript_require_defects’, function(o)
{
if (.trim(o.values.defects) == '' && .trim(o.values.status_id) == 5)
{
('#addResultErrors').append('Field Defects is required when the status is Failed'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
});
}
);

The only downside is that now Defect has got the red asteristick anyway, but at least the script does the required job

Many thanks,
Giuseppe


#4

Hi Tobias,
I share here the updated version of the UI script that checks also that if the status is Passed, the field Defects has to be mandatory:

name: Conditional test result
description: Makes the Defects required on the Add Test Result dialog when the status is failed
author: Giuseppe & Giovanni
version: 1.0
includes:
excludes:

js:
(document).ready( function() { .subscribe(‘result_dialog.loaded’, ‘uiscript_require_defects’, function(o)
{
('#addResultDefects').prev().append(' <span class="form-required">*</span>'); }); .subscribe(‘result_dialog.validate’, ‘uiscript_require_defects’, function(o)
{
if (.trim(o.values.defects) == '' && .trim(o.values.status_id) == 5)
{
('#addResultErrors').append('Field Defects is required when the status is Failed'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
if (.trim(o.values.defects) != '' && .trim(o.values.status_id) == 1)
{
('#addResultErrors').append('Field Defects must be empty when the status is Passed'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
});
}
);

Many thanks,
Giuseppe


#5

Hi Giuseppe,

Thanks for sharing this!

Cheers,
Tobias


#6

Hi Tobias,
sorry again to re-open the topic.
I wanted to add also an option to get and error when the Testcase is passed,if the severity is not set to a value “—” that I have added in the costumization. Do you know what is the syntax of THE field severity in terms of API ? I’m adding more and more options, to prevent my tester to write results that don’t make sense ( like having a defect number when the testcase is not failed).
Now I’m stuck with the field severity.
I have tried something like that, but Testrail is again not happy:

name: Conditional test result maximus
description: Makes the Defects required on the Add Test Result dialog when the status is failed
author: Giuseppe & Giovanni
version: 1.0
includes:
excludes:

js:
(document).ready( function() { .subscribe(‘result_dialog.loaded’, ‘uiscript_require_defects’, function(o)
{
('#addResultDefects').prev().append(' <span class="form-required">*</span>'); }); .subscribe(‘result_dialog.validate’, ‘uiscript_require_defects’, function(o)
{
if (.trim(o.values.defects) == '' && .trim(o.values.status_id) == 5)
{
('#addResultErrors').append('Field Defects is required when the status is Failed'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
if (.trim(o.values.defects) != '' && .trim(o.values.status_id) == 1)
{
('#addResultErrors').append('Field Defects must be empty when the status is not Falied'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
if (.trim(o.values.defects) != '' && .trim(o.values.status_id) == 2)
{
('#addResultErrors').append('Field Defects must be empty when the status is not Falied'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
if (.trim(o.values.defects) != '' && .trim(o.values.status_id) == 3)
{
('#addResultErrors').append('Field Defects must be empty when the status is not Falied'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}

});
    $.subscribe('result_dialog.validate', 'uiscript_require_severity', function(o)
{	
					if ($.trim(o.values.status_id) == 5 && $.trim(o.values.severity) != '---' )
					{
						$('#addResultErrors').append('Severity has be ---');
						$('#addResultErrors').show();  
						o.event.stopPropagation();
						return;
					}	
	
});

);

I don’t know if the field for severity is managed correctly. Is it correct to also add a subscribe ?
If you have a chance please let me know.

Many thanks,
Giuseppe


#7

Hi Giuseppe,

You would be able to handle this as part of the same event handler. I would recommend printing the attributes of o to the JavaScript Console to see all attributes:

console.log(o);

It looks like Severity may be a custom field? If so, you can access it as follows:

o.values.custom_severity

I hope this helps!

Cheers,
Tobias


#8

Thanks man !
I have added also a 6th state called “In Progress”. Let me share the final script that is actually working well:

name: Conditional test result new
description: Makes the Defects required on the Add Test Result dialog when the status is failed
author: Giuseppe & Giovanni
version: 1.1
includes:
excludes:

js:
(document).ready( function() { .subscribe(‘result_dialog.loaded’, ‘uiscript_require_defects’, function(o)
{
('#addResultDefects').prev().append(' <span class="form-required">*</span>'); }); .subscribe(‘result_dialog.validate’, ‘uiscript_require_defects’, function(o)
{
if (.trim(o.values.defects) == '' && .trim(o.values.status_id) == 5)
{
('#addResultErrors').append('Field Defects is required when the status is Failed'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
if (.trim(o.values.defects) != '' && .trim(o.values.status_id) == 1)
{
('#addResultErrors').append('Field Defects must be empty when the status is not Falied'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
if (.trim(o.values.defects) != '' && .trim(o.values.status_id) == 2)
{
('#addResultErrors').append('Field Defects must be empty when the status is not Falied'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
if (.trim(o.values.defects) != '' && .trim(o.values.status_id) == 4)
{
('#addResultErrors').append('Field Defects must be empty when the status is not Falied'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
if (.trim(o.values.defects) != '' && .trim(o.values.status_id) == 6)
{
('#addResultErrors').append('Field Defects must be empty when the status is not Falied'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
if (.trim(o.values.custom_severity) != '---' && .trim(o.values.status_id) == 1)
{
('#addResultErrors').append('Field Severity must be --- when the status is not Falied'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
if (.trim(o.values.custom_severity) != '---' && .trim(o.values.status_id) == 2)
{
('#addResultErrors').append('Field Severity must be --- when the status is not Falied'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
if (.trim(o.values.custom_severity) != '---' && .trim(o.values.status_id) == 4)
{
('#addResultErrors').append('Field Severity must be --- when the status is not Falied'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
if (.trim(o.values.custom_severity) != '---' && .trim(o.values.status_id) == 6)
{
('#addResultErrors').append('Field Severity must be --- when the status is not Falied'); (’#addResultErrors’).show();
o.event.stopPropagation();
return;
}

});
}

);

Enjoy.

Many thanks,
Giuseppe


#9

Thanks again for sharing this, Giuseppe!

Cheers,
Tobias


#10

Thanks guys for such nice script :slight_smile: How i can add this script to specific projects only ? What i need to include ?


#11

{
if (!uiscripts.context.project || uiscripts.context.project.id != 52)
if (!uiscripts.context.project || uiscripts.context.project.id != 86)
{
return;

Is the code to be added for specific projects only :slight_smile:


#12

Full code as well.


name: Make Defect field required
description:
author:
version: 1.2
includes:
excludes:

js:
$(document).ready(
function() {
if (!uiscripts.context.project || uiscripts.context.project.id != 52)
if (!uiscripts.context.project || uiscripts.context.project.id != 86)
{

return; // Only apply this UI script to project with ID 23
}
.subscribe('result_dialog.loaded', 'uiscript_require_defects', function(o) { (’#addResultDefects’).prev().append(’ *’);
});
.subscribe('result_dialog.validate', 'uiscript_require_defects', function(o) { if (.trim(o.values.defects) == ‘’ && .trim(o.values.status_id) == 5) { (’#addResultErrors’).append(‘Field Defects is required when the status is Failed’);
('#addResultErrors').show(); o.event.stopPropagation(); return; } if (.trim(o.values.defects) != ‘’ && .trim(o.values.status_id) == 1) { (’#addResultErrors’).append(‘Field Defects must be empty when the status is Passed’);
$(’#addResultErrors’).show();
o.event.stopPropagation();
return;
}
});
}
);


#13

Thanks vilijam, nice contribution !


#14

Hi all,

there is actually way to bypass mandatory field in testrail… as we make things mandatory via UI script there is another way to fail/pass add results.

@tgurock: is there way to disable this button or adding result from here ?

Thanks,
Viljam


#15

@tgurock any ideas ?

Thanks,
Viljam


#16

Hi Viljam,

Thanks for your reply! This would generally be possible via a UI script as this is just a CSS button element on the page. You could use something such as the following to implement this:

name: Remove Add Result And Next button
description: Removes Add Result And Next button on three-pane view
author: Gurock Software
version: 1.0
includes: ^runs/view

css:
#addResultAndNext {
    display: none;
}

#qpane-body > div.button-group.form-buttons > a.link-noline.button.button-droppie.button-left.dropdownLink {
    display: none;
}

That said, this could hinder some productivity by removing this feature as this was designed to increase productivity by streamlining testing in the three-pane view. Hope this helps!

Regards,
Marco


#17

Hi,

can this be configured to work for certain projects ?

V


#18

Hi Viljam,

Thanks for your reply! This script wouldn’t work for a specific project as it’s just included in all test run view pages, and these wouldn’t include any project identifier in the URL when viewing these. That said, this is just an example script and there may be other ways to accomplish this with a UI script for a specific project, however we haven’t tested this specifically and don’t have an example script to share. Hope this helps!

Regards,
Marco


#19

Hi to all,

we had a similar need, to disable “Failed and next” option but to leave “Pass and next” available
Here is the script

name: Hide dropdown options for "& next"
description: Hide dropdown options for “& next” but leave “Pass & next” visible
author: Alston & Nemanja Veskovic
version: 1.0
includes: ^runs/view
excludes:
css:
a.link-noline.button.button-droppie.button-left.dropdownLink {
display:none;
}
.button-droppie-parent {
margin-right: 8px!important;
}

21 AM