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

Accessing local machine from TestRail UI Scripts


#1

Hello,

We are evaluating TestRail, so that we can procure it for our organization. We have an automation framework which we want to integrate with TestRail. We are calling ajax from UI Scripts as mentioned below.
$.ajax(
{
url: “http://10.193.74.92:8082/TestingProject/?run_id=” + uiscripts.context.run.id,

  • I know this is not a public IP so local machine would be able to communicate with TestRail cloud.

Entire solution is working fine when we deployed TestRail server and automation framework in local environment but same is not working when we use TestRail cloud based solution.

Discussed with our IT team, they told TestRail team will have to permit ICMP on the port where TestRail is running.

Please let me know if it is feasible or there is any other way to communicate with local machine.


#2

Hello,

Thanks for your posting! Browser’s don’t allow cross-site/domain requests for JavaScript and it wouldn’t be possible to implement this directly via JavaScript (this only works if both TestRail and your target server/trigger are located on the machine). Instead, you would implement this slightly differently and as a regular non-JavaScript web request, e.g. as a simple link or a POST request. Do you maybe have a web developer on your team who has experience with this and could help?

Cheers,
Tobias


#3

Hi Tobias,

We tried with the changes you suggested above but still no success. Please find below the code changes we did:
var url=“http://115.114.69.135:8082/TestingProject/”;
var params = “run_id=”+ uiscripts.context.run.id;
request.open(‘POST’, url, true);
request.onreadystatechange = function() {if (request.readyState==4) alert(“It worked!”);};
request.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”);
request.setRequestHeader(“Content-length”, params.length);
request.setRequestHeader(“Connection”, “close”);
request.send(params)

We also tried with exposing our machine to public ip and found that we were able to access our machine from internet but still not able to hit our local tomcat server from the testrail-cloud based server.


#4

one problem i had was that TestRail sends https, but my address was not https configured. Changing this was then making the call successful


#5

Hello!

This still looks like a regular JavaScript request. Accessing your local server directly via JS wouldn’t be really possible due to cross domain restrictions by web browsers, but using a regular link without JS (either via GET or POST) would work fine.

Cheers,
Tobias


#6

This is an excerpt from my script that is working (which again is taken from the TestRail ui script example)

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

I used https://ngrok.com for making my local ip available (for testing purposes).


#7

Hi all!

The latest example would also require cross-domain support/permissions if TestRail and the trigger script are located on different servers. It should be possible to enable cross-domain support on your server as follows: http://stackoverflow.com/questions/17874730/how-to-make-cross-domain-request

Cheers.
Tobias


#8

yes - I needed to add the following to my php script

<?php header('Access-Control-Allow-Origin: https://ourlink.testrail.net');

Thanks for pointing that out :slightly_smiling:


#9

Thanks for sharing that, Andreas!

@bijeshkumar: do you/your IT have the option to look into configuring your local server to support this as well? You should then be able to use regular JS requests just like our trigger example.

Cheers,
Tobias