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

[UI Script] Autofilling and validating fields when entering test results


#1

Hi again :slight_smile:

So I’m working on ui scripts… and I have one here that basically auto fills some fields and does some validation… but I need help filling in the blanks

  • Do I have my project context correct? I’m trying to make sure it only happens on project 26
  • Right now I’m setting versions to ‘1’ as a placeholder, what I’d like to do is pull the milestone and put it in that field instead… is that possible? ex: my milestone is 10.2… I want 10.2 to be in the version field when the dialog loads
  • Is it possible to pull the test run name? Ex: if a test run has a name of ‘regression’ then I want my dropdown box to select a specific value

Thanks!

name: Version stuff
version: 1.0
includes: 
excludes: 

js:

if (!uiscripts.context.project || uiscripts.context.project.id != 26) {
	return; // Only apply this UI script to project with ID 26
}
else {
	$(document).ready(
		function() {
				$.subscribe('result_dialog.loaded', 'uiscript_require_elapsed', function(o) {
				$('#custom_dsmversion').val('1');
				$('#custom_dsaversion').val('1');
				$('#custom_dsmversion').prev().append(' <span class="form-required">*</span>');
				$('#custom_dsaversion').prev().append(' <span class="form-required">*</span>');


				if (str.toLowerCase($.trim(o.values.???)).indoxOf("Regression") {
					$('#custom_branch').val('Dropdown list item');
					o.event.stopPropagation();
					return;
				}
		}
	);

	$.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.custom_dsmversion) == '') {
			$('#addResultErrors').append("DSM Version is required");
			$('#addResultErrors').show();
			$('#custom_dsmversion').prev().html('DSM Version <span class="required"><font color="#CF1B5D"> * Fix Me</font></span>');
			o.event.stopPropagation();
			return;
		}

		if ($.trim(o.values.custom_dsmversion).length == '1') {
			$('#addResultErrors').append("DSM Version is too short, did you add the incremental version? ");
			$('#addResultErrors').show();
			$('#custom_dsmversion').prev().html('DSM Version <span class="required"><font color="#CF1B5D"> * Fix Me</font></span>');
			o.event.stopPropagation();
			return;
		}


		if (!$.isNumeric($('#custom_dsmversion').val())) {
			$('#addResultErrors').append("DSM Version can only contain numeric and decimal points");
			$('#addResultErrors').show();
			$('#custom_dsmversion').prev().html('DSM Version <span class="required"><font color="#CF1B5D"> * Fix Me</font></span>');
			o.event.stopPropagation();
			return;
		}
	}
}

#2

Hey there, any UI script guru’s out there? :slight_smile: