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

Server side scripts for automation


I was reading and trying out the automated test runs referring to this page -

I could do with adding the “Start Tests” button. However, I am a bit confused about where to put the server side PHP script. The page says - The trigger script (trigger.php) needs to be placed into TestRail’s installation directory on the web server next to TestRail’s index.php file.

I am not exactly clear where to copy this file. I am using a testrail hosted trial (which I soon plan to convert to subscription).

Do I need my own webserver?
If yes then I guess it will have to be allowed by the firewall. My PC is behind the company’s firewall and can’t have a public web server running without an authenticated log-in.

Can someone please guide?



Hello Gopal,

Thanks for your posting. You would also be able to use the trigger example/approach with a TestRail Hosted (cloud) account. You would simply place the server-side trigger script on the server where you would like to execute/run the tests on (usually on your private network). TestRail would not need to be able to connect to your server, as the connection/glue is made via the UI script in TestRail and via your web browser. You can also write the server-side script in any other programming language and our script is only an example.

That said, most customers trigger their automated tests outside of TestRail either manually, scheduled or via a continuous integration system. They then use TestRail’s API to submit the test results to TestRail.



Thank you tgurock for a quick reply.

I would initially like to go with the example scripts and then develop my own scripts in other scripting language.

So the steps to do this are:

  1. Run a web server on my PC (Could be using apache, XAMPP or like).
  2. Place the trigger.php in the web server folder (usually where the index.php is)
  3. Now I think I need to modify the trigger.ui to give the path of my server (for e.g. Is that correct?

Since the trigger.ui is executing via web browser, it will find the trigger.php on the same PC or even if it is a different PC as long as it has access to that.



Tried that and it looks that it is reaching the server. Not sure really but now it shows a dialog

[color=blue]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.[/color]

But actually nothing happens. I have modified the trigger.php to include the address of my testrail and correct username and password.
When I directly run the trigger.php from web browser with a test run id, it does update the status of test results in that test run. For e.g. this works:

What can be wrong? Is it the trigger.ui that needs some update. The trigger.ui currently has path


Hello Gopal,

Thanks for your reply. You would also need to modify the UI script slightly as invoking the trigger script as background JavaScript/Ajax call would no longer work. The reason for this is that browsers do not allow cross-site JavaScript requests. You would need to change this into a regular link, for example. That said, we usually recommend triggering outside of TestRail (e.g. using standard CI tools or as part of your build process) and that’s the easiest and most flexible way to integrate your automated tests.



Thanks tgurock.
Can you please advise me or point to any link about what changes I need in the trigger.ui?
I would simply love to have this feature of running tests from the testrail UI.
Additionally I can always do the off-line runs by a CI tool and upload the results.



Hello Gopal,

The exact changes depend on your trigger script but you would usually need to replace the JavaScript/Ajax call with a regular link (in order to work around the cross-site restrictions). Do you have a developer on your team who could help with this?



Thanks Tobias.
No as of now I don’t have a core software person in my team. I will keep exploring how this can be done.

Meanwhile, just as a suggestion - it may be worthwhile for you to add any such example as well.

Thanks a lot.



You probably need to enable Cross-Origin Resource Sharing on your XAMPP installation (so that your server tells your browser it’s OK to make requests to it from a different domain, and the browser doesn’t block it).
There must be plenty of tutorials on how to enable CORS on Apache.

For example, try placing this on the top of your PHP code:

and see if it does the trick (the more secure way would be replacing the “*” with the actual address of your TestRail installation)


Gopal, a good first goal to get things going is to try and get the TestRail button to run a simple batch or shell script on your test machine. From there your goal is to pass a parameter from a TestRail test run to your batch script. Once you can do that, then you need to create a batch/shell script which can accept a parameter specifying a test and then run that test, and so on. Keep adding layers of complexity until you begin to understand how the system can work.

It’s difficult because there are so many possible ways you could do it, but also very flexible. I created a new field in the test cases on TestRail to hold the test name for that test. My trigger.php grabs this and feeds it as an argument to my batch script which in turns runs it as a Maven command. The console output it then collected and sent back to TestRail via the api as a test result. My system is not very elegant on the inside, but works fine on the outside! :wink:

For reasons I don’t understand, however, PHP appears to be very slow when running system commands via the ‘exec’ command, but I digress.

Start very simple and let us know how it goes, and I’d be happy to share code with you, although I’m not sure how clear it will be.


Hi Tobias,

On triggering the tests from test rail, I would like to know in trigger.php script how to mention in send_command function a command(.exe file) with arguments which is available on Linux?

We have a file called RunPhenix.exe once opened requires arguments like Workspace, ETS name etc…

Any example will be of great help.



Hello Venkata,

You can execute commands and start external tools from PHP with the exec function and also pass command line arguments:

The output of this command and result code is returned via the additional function parameters.

I hope this helps!



Hi Tobias,

Thanks for the input. I am not that familiar with php, any input will be of help to me to start this

I am trying to start tests from test rail and external tool is running Linux, below function sending the command to initiate the tests on the external tool, what should be mentioned below for $url and $response?

In my case, location of application runPhenixs.exe is /home/phenix/ and arguments to it are workspace_name, ETS_name and ATG_name, how to represent below using exec command?

public function send_command($method, $uri, $data = null)
$url = $this->_address . “index.php?api/v2/$uri”;
$response = $this->_send_request($method, $url, $data, $status_code);

                    $obj = null; 
                    if ($response && is_string($response)) 
                                $obj = json_decode($response); 

                    if ($status_code != 200) 
                                throw new TestRailException( 
                                            'HTTP status code: ' . $status_code 

                    return $obj; 


Hello Venkata,

Thanks for your reply. I would recommend asking a developer on your team to customize this or help with this as this would be difficult to implement if you don’t have PHP experience. The example trigger script contains a placeholder for the actual test execution (execute_test ) but sending the result to TestRail’s API can be reused and you wouldn’t usually need to modify the TestRail_api class or send_command function.