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

UI Script To Change Test Case Field


#1

The test case has a custom field indicating the Status e.g. draft, review, Approved.
When someone edits an Approved Test I need to reset the value back to draft. In the UI scripts how can I obtain current value of a custom field and then reset it while the test is opened for editing. I seem to always get back null values.

includes: ^cases/edit
excludes:

js:
$(document).ready(
function() {
if (uiscripts.context.user.role_id != 1)
{
// Obtain Status field value and check
var editStatus = sessionStorage.getItem(‘Status’);
alert(editStatus); // Always null

		// Change Status field on current editing screen
		alert(uiscripts.context.test);    // Always null
	}
}

);

Is there a UI manual describing the content of the ‘context’ and available fields?
uiscripts.context.test
uiscripts.context.case


#2

Hi Rich,

Thanks for your posting. The UI Script context only includes a limit number of fields and custom fields are not available on the edit/add forms, for example. One option is to use TestRail’s API to request additional details from TestRail’s API but we would usually advise against such complex integrations/scripts (as they will likely break with a future version of TestRail).

A better option is to automate something like this using TestRail’s API. For example, you can write a simple script that is executed once per day and gets the list of updated cases of the day before. If there are any updated/modified cases, you can change the status for those cases back to Draft. The involved API functions would be get_cases to get the list of cases (with an updated_after filter set) and update_case to update the status of your custom field:

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

Cheers,
Tobias