Seapine Labs
Personal tools

TestTrack SOAP SDK Tutorial - Visual Basic

From Seapine Labs

Jump to: navigation, search

This article includes everything you ever wanted to know about writing TestTrack SDK applications in VB! Don't like VB? 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.


[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 can pull it into Visual Studio. Within your Visual Studio project, right-click the project and choose Add Web Reference. In the URL field, type in the address to your TestTrack SDK installation, something like:


Click Go. Visual Studio should find one web reference at that address. Change the Web reference name to TTSoap then click Add Reference.

Finally, import the namespace and you're ready to roll.

Imports ProgramNamespace.WebReferenceName
e.g. Imports MyConsoleApp.TTSoap

An alternative method is to generate the stub code manually, from the wsdl. The downside is you'll have to do this again anytime you upgrade to a newer version of TestTrack.

[edit] Create a Connection

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

Dim cgiengine As ttsoapcgi
cgiengine = New ttsoapcgi

' Set the URL, based on your SDK installation.
cgiengine.Url = "http://myserver/cgi-bin/ttsoapcgi.exe"

' Fetch a list of projects you have access to.
Dim aproject() As CProject
aproject = cgiengine.getProjectList( "administrator, "")

' Or, build your own.
Dim project As CProject
project = New CProject
project.database = New CDatabase = "AttachTest1"

Dim aoptions(1) As CProjectDataOption
aoptions(0) = New CProjectDataOption
aoptions(0).name = "TestTrack Pro" // add TTP
aoptions(1) = New CProjectDataOption
aoptions(1).name = "TestTrack TCM" // add TCM
project.options = aoptions

' Login.
Dim lSession As Long
lSession = cgiengine.ProjectLogon(project, "administrator", "") some stuff...

' When you're finished, log off.

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.

' retrieve defect #45, with attachments.
Dim def as CDefect
def = cgiengine.getDefect(lSession, 45, "", true)

' retrieve test case #312, with attachments.
Dim tc as CTestCase
tc = cgiengine.getTestCase(lSession, 312, "", true)

[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.

' #, summary, custom field, product and type
Dim astrFields() As String = {"Number", "Summary", "My Custom", "Product", "Type"}
Dim atc(4) As CTableColumn

Dim i As Integer
For i = 0 To astrFields.Length - 1
   atc(i) = New CTableColumn
   atc(i).name = astrFields(i)
Next i

' fetch all defects
Dim rows As CRecordListSoap
rows = cgiengine.getRecordListForTable( lSession, "Defect", "", atc)

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

All of this information can be hard-coded as shown in the previous example, or dynamically passed as shown below.

' What object types can I query?
Dim adt As CDatabaseTable
adt = cgiengine.getTableList(lSession)

' What field data is available for a given object type?
Dim atc() As CTableColumn
atc = cgiengine.getColumnsForTable( lSession, adt(?))

' What filters are available?
Dim af() As CFilter
af = cgiengine.getFilterList(lSession)

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:

' Create the CDefect object.
Dim def As CDefect
def = New CDefect
def.summary = "This is a new defect"
def.product = "My Product"
def.priority = "Immediate"

' Add the defect to TestTrack.
Dim lNewNum As Long
lNewNum = cgiengine.addDefect(lSession, def)

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.

' Open defect #11 for editing.
Dim def As CDefect
def = cgiengine.editDefect(lSession, 11, "", true)

' Change the Priority.
def.priority = "Immediate"

' Save the defect changes
cgiengine.saveDefect(lSession, def)

' Or, you can release the edit lock w/o saving changes.
cgiengine.cancelSaveDefect(lSession, def.recordid)

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

' Lock the defect for edit.
Dim def As CDefect
def = cgiengine.editDefect(lSession, 1284, "", false)

' Find and update the 'My Custom' custom field.
Dim i As Integer
For i = 0 to def.customFieldList.Length
   If (def.customFieldList(i).name.Equals("My Custom")) Then
      CType(def.customFieldList(i), CStringField).value = "Testing"
   End If
Next i

' Save changes.
cgiengine.saveDefect(lSession, def)

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.
Dim def As CDefect
def = cgiengine.editDefect(lSession, 1284, "", false)

' Create the Fix event.
Dim de As New CDefectEvent = "Fix"
de.resultingstate = "Fixed"
de.user = "System Administrator" = DateTime.Now

' Populate custom field
Dim fldlist(0) As CDropdownField
fldlist(0) = new CDropdownField
fldlist(0).name = "Resolution"
fldlist(0).value = "Code Change"
de.fieldlist = fldlist

' Add the event to defect's eventlist.
If (def.eventlist Is Nothing Or def.eventlist.Length = 0)Then
   ' No events, so we can just create a new list.
   Dim delist(0) As CDefectEvent
   delist(0) = New CDefectEvent
   delist(0) = de
   def.eventlist = delist
   ' Append new event to end of existing list.
   Dim list As New ArrayList
   For i = 0 To def.eventlist.Length - 1
   Next i

   Dim delist(def.eventlist.Length + 1) As CDefectEvent

   For i = 0 To list.Count - 1
      delist(i) = list(i)
   Next i
   delist(def.eventlist.Length) = de
   def.eventlist = delist
End If

' Save our changes.
cgiengine.saveDefect(lSession, def)

[edit] Add File Attachment

' Lock the defect for edit.
Dim def As CDefect
def = cgiengine.editDefect(lSession, 1284, "", false)

' Create the file attachment.
Dim strFile As New String
strFile = "C:\\readme.txt"

Dim file As New CFileAttachment
Dim enc As New System.Text.ASCIIEncoding

Dim reader As System.IO.StreamReader
reader = new System.IO.StreamReader(strFile)

file.mstrFileName = System.IO.Path.GetFileName(strFile)
file.mpFileData = enc.GetBytes(reader.ReadToEnd())

' Add the attachment to the defect.
Dim reprec As CReportedByRecord
reprec = def.reportedbylist(0)
Dim afile() As CFileAttachment
afile = reprec.attachmentlist
If (afile Is Nothing) Then
   Dim attlist(0) As CFileAttachment
   attlist(0) = new CFileAttachment
   attlist(0) = file
   def.reportedbylist(0).attachmentlist = attlist
End If
' should add else here, to handle defects with existing attachments.

' Save our changes.
cgiengine.saveDefect(lSession, def)

[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.

' Promte as new global user
Dim iResult As Integer
iResult = cgiengine.promoteUser(lSession, "John Bark", null, "jbark");

' check that iResult == 0

' Promte to existing global user
Dim iResult As Integer
iResult = cgiengine.promoteUser(lSession, "John Bark", "Sarah Kaiser", null);

' check that iResult == 0

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] Troubleshooting

With VB and Visual Studio, using the TestTrack SDK is pretty simple but it never hurts to have some tools to help with debugging.

  • MS SOAP Toolkit - This is a small app from Microsoft that helps you trace SOAP requests. Start a formatted trace, point your SOAP client toward the tools 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 being sent. Going through VB, you're depending on their parser to translate objects into XML and pass those to the server.

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