Seapine Labs

TestTrack SOAP SDK Tutorial - Perl

From Seapine Labs

Jump to: navigation, search


This article includes everything you ever wanted to know about writing TestTrack SDK applications in Perl! Don't like Perl? We have tutorials for a variety of languages. Be sure to check out the TestTrack SDK Help pages for more information.

Want Seapine to write your SOAP app for you? Email us for more information.

Contents

[edit] Getting Started

You must install the TestTrack SDK as part of your server installation. If you haven't done this, you'll need to run the TestTrack installer for the version you have installed. Once installed, there are 2 files of interest.

  • http://yourserver/cgi-bin/ttsoapcgi.exe - CGI Executable that all TestTrack SDK commands go through. It's not important to understand CGI, just know where this file was installed.
  • http://server/ttsoapcgi.wsdl - The WSDL file that defines the language you use when talking to the CGI executable. Anyone that uses the TestTrack SDK uses this wsdl, there is no need to generate a specific wsdl for your installation. Everything is genericized so that, no matter how you customize TestTrack, this one wsdl file will handle it.
  • Once you've installed the TestTrack SDK, you'll need to create the Perl stub code module (ttsoapcgi.pm) to use with your script. Just run the following command:
perl {path to perl}/bin/stubmaker.pl http://hostname/scripts/ttsoapcgi.wsdl

After you've created the ttsoapcgi.pm module, you'll need to add the following function to it as well:

sub ttpro {
  my $self = shift;
  my $schema = 'http://www.w3.org/2001/XMLSchema';

  $self->xmlschema($schema)->readable(1);
  return $self;
}

[edit] Create a Connection

The TestTrack SDK requires authentication before you can retrieve and save data.

use strict;

use SOAP::Lite; #+trace => 'debug';  #uncomment for debugging output

# The FindBin module will locate our generated ttprocgi module
use FindBin;
use lib $FindBin::RealBin;
use ttsoapcgi;

import SOAP::Data qw/ name value /;

my $soap = ttsoapcgi->new->ttpro;   # create a new SOAP object.

my $username = 'administrator';
my $password = '';

# Fetch a list of projects you have access to.
my $projectList = $soap->getProjectList($username, $password);

# Login
my $cookie = $soap->ProjectLogon($projectList->[0], $username, $password);

   ...do some stuff...

# When you're finished, log off.
$soap->DatabaseLogoff($cookie);

Things to Know:

  • You cannot logon via the TestTrack SDK if you are already logged in via one of the TestTrack clients. It's best to use a dedicated account for your SDK scripting, this ensures you'll always be able to login.
  • If you do not explicitly call DatabaseLogoff, your user will remain logged in until the TestTrack SDK times out. This could present a problem if you try to re-run the script inside that timeframe. It's important to use try/catch exception handling to ensure that an exception in your program doesn't skip logging you off.
  • The CProjectDataOption array governs what licenses you use and functionality you have access to. For example, you can't use a TestTrack TCM license if you don't specify one in the CProjectDataOption array.

[edit] Query Objects

There are two ways to retrieve data through the TestTrack SDK. You can explicitly call a getObject method or you can call the getRecordListForTable method.

[edit] getObject

Calling the get method on an object is useful when you know exactly which object you need. For performance reasons, this is not recommended when you want to extract data from multiple objects of the same type.


[edit] getRecordListForTable

If you'd rather query multiple objects of the same type, similar to a SELECT statement in SQL, use getRecordListForTable. This method allows you to specify what data you want to retrieve and apply a filter to the results.


When calling getRecordListForTable you must specify the object type you want to query. Optionally, you can also specify an array of fields you want to retrieve and a filter that you've pre-configured in TestTrack.

Things to Know:

  • TableColumn elements use the field's Short Label value.
  • Pretty much anything you can view in a list view column within the GUI clients, you can retrieve through getRecordListForTable.

[edit] Create Object

Adding an object is simply a matter of creating a new instance and calling the addObject method.

For example, to create a defect:

#this is code fragments, not a complete program!!!

#create the attachmentlist
push(@attachments, name( item => \SOAP::Data->value(
                name(  'm-pFileData' => encode_base64($buf, '')),
                name( 'm-strFileName' => $part->head->recommended_filename )
              ))->type('ttns:CFileAttachment'));


$attachlist = name( attachmentlist => [ \SOAP::Data->value( @attachments ) ] )->type('ttns:CArrayOfFileAttachments') ;

my $reported = name(
    reportedbylist => [
      name( item => \SOAP::Data->value(
        name( comments => $body )->type("xsd:string"),
        name( foundby => $foundby ),
        name( showorder => 0 )->type('xsd:short'),
        $attachlist
      ))->type('ttns:CReportedByRecord')
    ]
);

my @dvalues = (
    name( summary   => 'Summary of the defect') ),
    name( enteredby => 'Soap, User'),
    name( 'type'         => $req_type ),
    $reported,
);

   my $method;
   my @parameters;
   my $soapReturnVal;

   $method = name( 'addDefect' )->prefix('ttns')->uri('urn:testtrack-interface');
   @parameters = (
                  name( 'cookie'    => $cookie ),
                  name( 'pDefect' => \SOAP::Data->value(@dvalues) )->type('ttns:CDefect')
                );
   
   ## perform addTestCase
   CheckForError($soapReturnVal = $soap->call($method => @parameters));


$soap->DatabaseLogoff($cookie);

Things to Know:

  • When setting drop-down list values, you must match exactly (case-sensitive) with an existing value in the drop-down list.
  • When setting date/time values, you must also set the set{FieldName} value to true.

[edit] Update Object

Before updating an object, you must first lock it for editing by calling editObject.


Things to Know:

  • You cannot edit an object that is being edited by another user. For example, if someone else had defect #11 open for edit in their client, the example above would fail.
  • If you successfully lock a defect for edit, that lock remains until you save it, cancel the save or logout. You should use try/catch exception handling to ensure that you release the lock as soon as possible.

[edit] Update Custom Field


Things to Know:

  • The customfieldlist array holds the base-class CField objects, which must be casted as appropriate before you can set a value. In the example, 'My Custom' is a text field so we casted to CStringField. See the TestTrack SDK Types page for a full list of supported field types.

[edit] Update Workflow State

TestTrack calculates state based on event history. This means you can't simply set a value to change state. Instead, you have to apply the necessary events to move the object into the desired state.

// Lock the defect for edit.

// Create the Fix event.

// Populate custom field

// Add the event to defect's eventlist.

// Save our changes.

[edit] Add File Attachment

// Lock the defect for edit.

// Create the file attachment.

// Add the attachment to the defect.

// Save our changes.

[edit] Promote User/Customer

At times you may need to turn a local user or customer into a global account. There are essentially two ways to do this. You can promote them as a new global user, or you can link them to an existing global user.


In the examples below, John Bark is a local user in our TestTrack project, Sarah Kaiser is a global user in the Seapine License Server.




Note: The name parameters are searched based on your user settings in TT. So if you have names setup to display as 'lname, fname', then that's the format you should use when passing them to the call. If you passed them exactly as shown in the examples above (fname lname), they won't be found and the promote will fail.

[edit] Adding Drop-down Values

The basic process is very easy, you just create a value object and add it to the field.


For a complete listing of the tables and fields available, you can run this:

my $tableList = $soap->getTableList($cookie);

for my $tbl (@$tableList)
{
   my $tableName = $tbl->{name};

   my $fields = $soap->getDropdownFieldForTable($cookie, $tableName);

   for my $fld (@$fieldName)
   {
      my $fldName = $fld->{name};
   }
}

[edit] Run Report

In the example below, we'll run a report by name and fetch the results.


[edit] Troubleshooting

With Perl, using the TestTrack SDK will likely require some debugging tools and liberal use of temporary output statements.

  • To turn on debug trace messages for SOAP, replace "use SOAP::Lite;" with "use SOAP::Lite +trace => 'debug';"
  • You can perform error handling by using a couple of SOAP calls:
if ($soap->call->fault) {
    my $faultstring = $soap->call->faultstring;
    $soap->DatabaseLogoff($cookie);
    die "$0: TestTrack error: $faultstring\n";
}
  • MS SOAP Toolkit - This is a small Microsoft application that helps you trace SOAP requests. Start a formatted trace, point your SOAP client toward the tool's listening port, then have the tool redirect to the real web server port. With that configured, you can intercept the response/request loop and see exactly what is being communicated to the TestTrack Server.
  • soap UI - A free tool that lets you send raw SOAP envelopes. We sometimes use this internally to debug issues, since you can control the data being sent.
  • If you're not sure what a function or object looks like, use the wsdl output functions to find that information.

[edit] Downloads














Issue Management Software | Source Code Control Software | Test Case Management | Requirements Management Software