|
|
ViewsPersonal toolsTestTrack SOAP SDK Tutorial - PerlFrom Seapine Labs
Want Seapine to write your SOAP app for you? Email us for more information.
[edit] Getting StartedYou 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.
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 ConnectionThe 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:
[edit] Query ObjectsThere 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] getObjectCalling 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] getRecordListForTableIf 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:
[edit] Create ObjectAdding 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:
[edit] Update ObjectBefore updating an object, you must first lock it for editing by calling editObject. Things to Know:
[edit] Update Custom FieldThings to Know:
[edit] Update Workflow StateTestTrack 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/CustomerAt 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.
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 ValuesThe 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 ReportIn the example below, we'll run a report by name and fetch the results. [edit] TroubleshootingWith Perl, using the TestTrack SDK will likely require some debugging tools and liberal use of temporary output statements.
if ($soap->call->fault) {
my $faultstring = $soap->call->faultstring;
$soap->DatabaseLogoff($cookie);
die "$0: TestTrack error: $faultstring\n";
}
[edit] Downloads |
|


