Time Management Help Index Languages

Can I report my automation tool test results to Testuff?

Yep! It allows your automation to update test results in Testuff, using the API.

Which tools are currently supported?

Testuff API enable us to integrate any tool that supports HTTP requests from a script, so we can integrate with virtually any tool on the market.

We have already successfuly integrated Testuff with the following leading automation tools:

How does it work?

Via HTTP POST over SSL. Your Testuff login details are used for identification. Each test has a unique ID. Test results are POSTed to the relevant API URL and include as parameters the test ID, lab name, and test result. Following the request, Testuff updates the test result accordingly.

How do I set it up?

The API url can be found in the Settings link at the top of the Testuff window. Just add to it run/ to report test results. To retrieve the Test IDs simply right click the relevant suite or tests that are automated, and select Show IDs.

Create your automation scripts. See examples below. Scripts need to send HTTP POSTs with the following parameters:

  • test_id – the relevant test ID for which the result is reported.
  • status – test execution status, should be passed, maybe, or failed.
  • steps_failed – (optional) list of failed steps. Example “1,3,5″.
  • steps_passed – (optional) list of passed steps.
  • steps_maybe – (optional) list of maybe steps.
  • branch_name – (optional) the name of the branch where the test result should appear.
  • lab_name – (optional) the name of the lab where the test result should appear.
  • run_configuration – (optional) specifies the run configuration used for the test.
  • comment – (optional) add a free text comment to the execution.
  • version – (optional) specifies the version used for the test.

The result header should include a Location result, which is the URI for the newly created run.

Make sure you receive an HTTP 201 response when sending the POSTs. Otherwise something has gone wrong. If something has indeed gone wrong, there should be information in the HTTP response as to the trouble.

As usual, feel free to contact us if you have any issues or questions.

What happens to the tests when creating a new branch?

When copying a branch we keep the test IDs for automation. If you want to run the tests in the new branch, just change the branch_name parameter in the scripts.

How do I look up tests by their IDs?

Just enter the ID in the search box at the top right and press enter.

What about some code examples?

Make sure to use basic authentication, with your Testuff username and password.

Python

import urllib2
import base64
 
xml = """\
<?xml version='1.0' encoding='utf-8'?>
<object>
<test_id>TEST_ID</test_id>
<status>failed</status>
</object>
"""

username = "TESTUFF_LOGIN"
password = "PASSWORD"
url = "https://serviceX.testuff.com/api/v0/run/"

opener = urllib2.build_opener()

request = urllib2.Request(url)
request.add_header("Content-Type", "application/xml")
request.add_header("Accept", "application/xml")
encoded = base64.encodestring("%s:%s" % (username, password))[:-1]
request.add_header("Authorization", "Basic %s" % encoded)

response = opener.open(request, xml)
print response.headers

PERL

Please install the Crypt::SSLeay module beforehand.

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;

my $req = POST 'https://serviceX.testuff.com/api/v0/run/',
[
lab_name=> 'sanity',
test_id=> 'abcdefghijklmnop',
status=> 'failed',
steps_failed=> '1,4',
comment=> 'comment text'
];

$ua = LWP::UserAgent->new;
print $ua->request($req)->as_string;

VBA

Make sure all parameters are URLEncoded, for example by using the URLEncode function.


call Main()

Sub Main()
    Dim strXML            'XML request string
    Dim strJSON           'JSON request string
    Dim strUserName       'user name to connect to the Web API service
    Dim strUserPassword   'password for the user to connect to the Web API service
    Dim strWebAPIURL      'Web API service URL
    Dim s_test_id, s_expected_status, s_steps_failed, s_comment
	
    ' set Web API connectivity parameters
    ' replace email, password and serviceX with your account details
    strUserName = "your_testuff_login"
    strUserPassword = "your_testuff_password"
    strWebAPIURL = "https://serviceX.testuff.com/api/v0/run/"
	
    ' set test scenario parameters
    s_test_id = "uhpermbpkq7gh75s3x4mwuc46janat2g"
    s_status = "failed"
    s_steps_passed = "3"
    s_steps_failed = "2,4"
    s_comment = "additional info"
	
    'prepare Web API call data
    strXML = "<?xml version='1.0' encoding='utf-8'?>" & _
		"<object>" & _
		"<test_id>" & s_test_id & "</test_id>" & _
		"<status>" & s_status & "</status>" & _
		"<steps_failed>" & s_steps_failed & "</steps_failed>" & _
		"<steps_passed>" & s_steps_passed & "</steps_passed>" & _
		"<comment>" & s_comment & "</comment>" & _
        "</object>"

    strJSON = "{" & _
        EmbraceInQuotes("test_id") & ":" & EmbraceInQuotes(s_test_id) & "," & _
	EmbraceInQuotes("status") & ":" & EmbraceInQuotes(s_status) & "," & _
        EmbraceInQuotes("steps_failed") & ":" & EmbraceInQuotes(s_steps_failed) & "," & _
        EmbraceInQuotes("steps_passed") & ":" & EmbraceInQuotes(s_steps_passed) & ","  & _
        EmbraceInQuotes("comment") & ":" & EmbraceInQuotes(s_comment) & _
        "}"
    
    ' Try XML Request
    '---------------------------------
    strResult = GetDataFromURL(strWebAPIURL, strUserName, strUserPassword, "POST", "application/xml", strXML)
    MsgBox "XML input, " & strResult
	
    ' Try JSON Request
    '---------------------------------
    strResult = GetDataFromURL(strWebAPIURL, strUserName, strUserPassword, "POST", "application/json", strJSON)
    MsgBox "JSON input, " & strResult
End Sub

Function EmbraceInQuotes(str)
    Dim res
    res = Chr(34) & str & Chr(34)
    EmbraceInQuotes = res
End Function

Function GetDataFromURL(strURL, strLogin, strPassword, strMethod, strContentType, strPostData)
	Dim lngTimeout
	Dim intSslErrorIgnoreFlags
	Dim blnEnableRedirects
	Dim blnEnableHttpsToHttpRedirects
	Dim strHostOverride
	Dim strResponseText
	Dim objWinHttp

    Const CREDENTIALS_FOR_SERVER = 0
  
	lngTimeout = 59000
	intSslErrorIgnoreFlags = 13056 ' 13056: ignore all err, 0: accept no err
	blnEnableRedirects = True
	blnEnableHttpsToHttpRedirects = True
	strHostOverride = ""

	Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
	objWinHttp.SetTimeouts lngTimeout, lngTimeout, lngTimeout, lngTimeout
	objWinHttp.Open strMethod, strURL
	If strMethod = "POST" Then
		objWinHttp.setRequestHeader "Content-type", strContentType
	End If
	If strHostOverride <> "" Then
		objWinHttp.SetRequestHeader "Host", strHostOverride
	End If
	objWinHttp.Option(4) = intSslErrorIgnoreFlags
	objWinHttp.Option(6) = blnEnableRedirects
	objWinHttp.Option(12) = blnEnableHttpsToHttpRedirects
    objWinHttp.SetCredentials strLogin, strPassword, CREDENTIALS_FOR_SERVER
	On Error Resume Next
	objWinHttp.Send(strPostData)
	If Err.Number = 0 Then
		If objWinHttp.Status = "201" Then
			GetDataFromURL = "Created: " & objWinHttp.GetResponseHeader("Location")
		Else
			GetDataFromURL = "Error: " & objWinHttp.ResponseText
		End If
	Else
		GetDataFromURL = "Error " & Err.Number & " " & Err.Source & " " & Err.Description
	End If
	On Error GoTo 0
	Set objWinHttp = Nothing
End Function 

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
using System.Collections.Specialized;

namespace WebAPIConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // set Web API connectivity parameters
            // replace email, password and serviceX with your account details
            string s_username = "your_testuff_login";
            string s_password = "your_testuff_password";
            string s_url = "https://serviceX.testuff.com/api/v0/run/";

            // set test scenario parameters
            string s_test_id = "uhpermbpkq7gh75s3x4mwuc46janat2g";
            string s_status = "failed";
            string s_steps_failed = "1,4";
            string s_comment = "my comment";
            string s_XML = "<?xml version='1.0' encoding='utf-8'?>" +
                    "<object>" +
                    "<test_id>" + s_test_id + "</test_id>" +
                    "<status>" + s_status + "</status>" +
                    "<steps_failed>" + s_steps_failed + "</steps_failed>" +
                    "<comment>" + s_comment + "</comment>" +
                    "</object>";

            string res = "";
            try
            {
                // System.Net.HttpWebRequest adds the header 'HTTP header "Expect: 100-Continue"' to every request by default
                System.Net.ServicePointManager.Expect100Continue = false;
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(s_url);
                req.Credentials = new NetworkCredential(s_username, s_password); //This line ensures the request is processed through Basic Authentication

                req.ContentType = "application/xml";
                req.Method = "POST";

                req.KeepAlive = true;
                req.Timeout = 50000;
                req.AllowAutoRedirect = false;
                req.ContentLength = s_XML.Length;

                Stream s = req.GetRequestStream();
                s.Write(System.Text.Encoding.ASCII.GetBytes(s_XML), 0, s_XML.Length);
                s.Close();

                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                res = "Created: " + resp.Headers["Location"];
            }
            catch (Exception e)
            {
                res = "Error: " + e.Message ;
            }

            Console.WriteLine(res);

        }

    }
}

Ruby

require 'net/http'
require 'net/https'

# Replace host name with values from Testuff API settings screen
http = Net::HTTP.new('serviceX.testuff.com', 443)
http.use_ssl = true
path = '/api/v0/run/'
req = Net::HTTP::Post.new(path)
# Replace email and password with your account details
req.basic_auth 'email@address.com', 'password'
# edit the parameters below to fit with your data and format
req.add_field 'Content-Type', 'application/json'
data = '{"test_id": "ea87af9928ebc981284", "status": "failed"}'
req.body = data
resp, data = http.request(req)
# Output response code to the screen (we should get 201)
puts 'Code = ' + resp.code
puts 'Message = ' + resp.message
puts 'resource uri = ' + resp['location']

Time Management Help Index Languages