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

[UI Scripts] Getting test case type ID from view page


#1

When viewing a test case, I want to replace the type text by a link if it’s a specific type.

The UI script I have right now currently appends a link to every test case in viewing mode:

js:
$(document).ready(
function() {
         $('#cell_type_id').append(
		'[ <a tabindex="-1" href="https://testrail.myorg.com/identify_code.php">View code</a> ]');
}
);

I’m having trouble getting the type_id.

If I do,

var test_case_type = $('#cell_type_id').text()

I get something long in text format that I cannot use in an equality statement.

If I do,

 var test_case_type = $('#cell_type_id').val()

I get a blank value.

Ideally, it would be something like this:

js:
$(document).ready(
function() {
         var test_case_type = $('#cell_type_id').val()

        if (test_case_type == 1) {
         $('#cell_type_id').replace(
		'[ <a tabindex="-1" href="https://testrail.myorg.com/identify_code.php">Functionality</a> ]');
}
);

Thank you in advance for your help :slight_smile:


#2

Answered my own question :wink: I ended up doing something very hacky. Developers would look down at me if they saw my code :wink:

js:
$(document).ready(
function() {
         var test_case_type = $('#cell_type_id').html()

            if (test_case_type.indexOf("Automated") != -1) {
                  $('#cell_type_id').html(
			'<label class=io-label>Type</label><a tabindex="-1" href="https://testrail.myorg.com/identify_code.php">Automated</a>');
	    }
	}
);

#3

Nevermind this scrpit. I just broke TestRail with this. You can no longer edit test cases after you add this UI script -_- Silly me.


#4

Hi Adron,

Thanks for your post! While it may generally be possible to create a UI script for this functionality, we haven’t tested this type of script and don’t have any similar examples to provide. In general, we wouldn’t be able to troubleshoot specific code within custom UI scripts, and you might want to try posting your question on a general programming Q&A website such as Stack Overflow as this can usually be more helpful in providing specific assistance for this type of request.

Regards,
Marco


#5

Thanks here’s my newest code anyway that seems to make it work. All I had to do is to include the view page in the “includes:”. Found that by searching the forum :wink:

name: Adron test link for automation
description: Shows a link if the tc type is automated
author: Adron
version: 1.0
includes: ^cases/(view)    # <-- Important, or it will break the edit page.
excludes: 

js:
$(document).ready(
function() {
        var test_case_type = $('#cell_type_id').html()

        if (test_case_type.indexOf("Automated") != -1) {
              $('#cell_type_id').html(
    			'<label class=io-label>Type</label><a tabindex="-1" href="https://testrail.myorg.com/identify_code.php">Automated</a>');
	    }
	}
);

#6

Hey Adron,

Thank you for posting your findings. Definitely helps and should be good for any other customers that happen upon this post.