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

Trigger.ui: How to get run id dynamically in UI script?


#1

Example code provided is using “uiscripts.context.run.id” to get run id. However this is not triggering the php script. When run_id is hard coded we are able to trigger (url: “https://192.168.1.69/dashboard/trigger.php?run_id=10”) php script.

What is the way to get run id dynamically in UI script?


#2

Hello Ashweeja,

Thanks for your posting. uiscripts.context.run.id is the right way to get the current run ID but this is only available on the actual test run page (not on the plan page, for example). Can you post the full example? Maybe there’s something wrong with how uiscripts.context.run.id is accessed or formatted as URL parameter.

Cheers,
Tobias


#3

Hi Tobias,

Thanks for your reply. I’m actually using it from test run page. Below is the UI script I’m using. Could you let me know if I’m missing anything?

name: Trigger tests for run
description: Triggers automated tests for a test run
author: Gurock Software
version: 1.0
includes: ^runs/view
excludes:

js:
(document).ready( function() { /* Create the button */ var button = (‘

Start Tests
’);
	/* Add it to the toolbar */
	$("#content-header .content-header-inner").prepend(button);		

	/* Bind the click event to trigger the automated tests */
	$("a", button).click(
		function()
		{
			$.ajax(
			{
				/*url: "https://192.168.1.69/dashboard/trigger.php?run_id=" + uiscripts.context.run.id,*/
				url: "https://192.168.1.69/dashboard/trigger.php?run_id=15",
				dataType: "json",
				type: "GET",
				success: function()
				{
					location.reload();
				},
				error: function()
				{
					location.reload();
					App.Dialogs.error(
						'An error occurred while trying to trigger the automated tests.'
					);
				}
			});

			App.Dialogs.message(
				'The tests are being processed in the background and the results are automatically posted back to TestRail. This page refreshes once the tests are finished.',
				'Confirmation'
			);
			
			return false;
		}
	);
}

);


#4

I would recommend using your web browser’s debugging tools to see which request is sent, and which response is received. Please note that the trigger script is only a starting point and you would need to adjust it for your needs. That said, in general we wouldn’t recommend using the trigger approach, as it doesn’t add a lot of benefits. We would usually recommend simply triggering your tests outside of TestRail (e.g. via your CI system) and then using TestRail’s API to submit the test results to TestRail:

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

I hope this helps!


#5

Thanks for reply. That really helped me to resolve the issue.

I have modified trigger script according to my needs. Only problem I had is to initiate it with correct run id.


#6

That’s great to hear, Ashweeja, and thanks for the update :slight_smile:

Cheers,
Tobias