In the last post we looked at using cURL for interacting with the API, including retrieving information and making POST requests.
As a brief follow up, we are going to look at how we can upload files.
Automated test results
Enterprise Tester supports the importing of automated test results via the Duette plugin, for this example we are going to upload the results of a test with JUnit results.
First, in the UI we create our automated test within a script package (you can do this via the API As well, but we won’t be covering it in this example):
Next we drag and drop the automated test into an execution package, creating an automated test assignment.
If we then click on the automated test assignment we will see a message like this on screen:
If we clicked “Yes” here we would be prompted to upload the results of the automated test via a dialog. Instead what we want to do is grab the unique identifier of this automated test assignment, which is available in URL:
cdf4a2fc-5386-42b6-85b1-a0ca009255b1
With this information we can then craft a URI to upload the results, via the Automated Test Assignment Runs collection resource.
The automated test assignments runs collection resource allows you to perform a POST, using what’s called a mime/multipart request, which allows one or more distinct “parts” to be included in the request, with those parts potentially being files, encoded forms etc.
If you look at the help topic linked above, you will see that the automated test assignment runs resource has the following URI template:
/api/automatedtestassignment/{id}/runs
Notice the {id} – this is a value substitution, and is what we will replace with our automated test assignment ID discovered earlier.
At this point we are now ready to remotely uplod our test results via cURL, to do this we will need to do a few things:
- Set the content-type header to multipart/mixed.
- Set the fileupload for the form to be @JUnit.xml (corresponding to our JUnit results on disk) – and also setting the mime type of the JUnitĀ file to be text/xml.
- Configure basic auth credentials.
- Add our crafted URL.
curl -i --header "Content-Type: multipart/mixed"--form "fileupload=@JUnit.xml;type=text/xml" -u apiuser:apipassword http://localhost/EnterpriseTester/api/automatedtestassignment/cdf4a2fc-5386-42b6-85b1-a0ca009255b1/runs
The result of executing this curl request is:
HTTP/1.1 202 Accepted
Date: Tue, 11 Sep 2012 21:37:21 GMT
X-AspNet-Version: 4.0.30319
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Content-Type: application/json; charset=utf-8
Content-Length: 362
Connection: Close
{
"Complete": false,
"TotalElements": 0,
"ProcessedElements": 0,
"StartedAt": "2012-09-11T21:37:21Z",
"ProgressInPercent": 0.0,
"Id": "automatedtestimport_b65fbdff-bbed-44ca-b8a3-865b35ce57c1",
"Message": null,
"Self": "http://localhost/EnterpriseTester/api/backgroundtask/automatedtestimport_b65fbdff-bbed-44ca-b8a3-865b35ce57c1"
}
As you can see, importing automated test results is also done asynchronously (note the 202 Accepted response status) – if we want to confirm everything worked OK, we can use the “self” url from the response:
curl-u apiuser:apipassword http://localhost:8092/EnterpriseTester/api/backgroundtask/automatedtestimport_b65fbdff-bbed-44ca-b8a3-865b35ce57c1
Which returns a response like this – if something had gone wrong during the import, additional error information and a descriptive message would also be included.
{
"Complete": true,
"StartedAt": "2012-09-11T21:37:21Z",
"FinishedAt": "2012-09-11T21:37:21Z",
"ProgressInPercent": 1.0,
"Id": "automatedtestimport_b65fbdff-bbed-44ca-b8a3-865b35ce57c1",
"Message": "Completed",
"Self": "http://localhost:8092/EnterpriseTester/api/backgroundtask/automatedtestimport_b65fbdff-bbed-44ca-b8a3-865b35ce57c1"
}
And now in the UI, double clicking on the automated test assignment again confirms we have uploaded a set of results:
So with some simple tools we are now able to start uploading the results of executing automated tests on a remote server (such as a continuous integration server) back into Enterprise Tester.
Multiple files
Importing multiple result files through the API is not currently supported – but thankfully Duette is smart enough to handle zip files, so if you wish to upload a set of test results, you can achieve this by first zipping up all the result files using a command line zip application, and then uploading the resulting zip file via cURL – here’s an example of a batch file to do just that (this should work just as well in a *nix shell as well).
zip -r output.zip *.xml curl -i --header "Content-Type: multipart/mixed"--form "fileupload=@output.zip;type=application/zip" -u apiuser:apipassword http://localhost/EnterpriseTester/api/automatedtestassignment/cdf4a2fc-5386-42b6-85b1-a0ca009255b1/runs
- The first step will recursively find any file with the extension .xml, and add them to the zip file called “output.zip”.
- The second step uploads the zip file of run results, note that the type of the file is changed to application/zip as well.
This is all too hard!
This post is written to whet your appetite for ways in which to use the API to automate common Enterprise Tester tasks, but this is certainly not what our long term goals for automated testing integration is.
As a company we value simplicity, and are definitely looking at providing simple (yet powerful) command line tools for publishing automated tool results, as well as integration with common continuous integration servers such as Bamboo, Jenkins, Team City etc.


