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

Get field value from case at test view


#1

Hi,

for a UI script I need to read a value from a test case at the ^tests/view/

I want to display a button at the top-bar (this part is already working)
depending of a boolean value which is stored at the original case (not the test)

Any sugestions?

Thanks for help in advance.


#2

Hello Jonathan,

Thanks for your posting. Some fields are already exposed via the UI script context but this only includes system fields currently:

http://docs.gurock.com/testrail-custom/uiscripts-introduction#context_information

You can always use TestRail’s get_case/get_test API to query additional details if needed (via JavaScript) and you can use TestRail’s session-based authentication in this case (can be enabled under Administration > Site Settings > API):

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

I hope this helps!

Cheers,
Tobias


#3

Hi Tobias,

Thanks for the answer.
I just combined some of your script to create the script I needed:

js:
$(document).ready(
	function() {
	        
			$.ajax(
			{
				url: 'index.php?api/v2/get_case/' + uiscripts.context.case.id,
				dataType: 'json',
				beforeSend: function(xhr, settings)
    {
        xhr.setRequestHeader("Content-Type", "application/json");
    },
    success: function(data, status, xhr)
    {
				if(data.YOUR_FIELD > 0)
				{
					/* Do Someting */
				}
        console.log(status);
        console.log(data);
    },
    error: function(xhr, status, error)
    {
        console.log(error);
    }
			});

	}
);`

#4

Hi Jonathan,

Thanks for sharing this here! It’s also planned to add a full JS example to our API page so it would be easier to develop custom scripts based on this.

Cheers,
Tobias