July 1, 2009

TestTrack SDK Helpful Tip - Logging in

Helix ALM
When approaching a programming task using the TestTrack SDK, it is sometimes helpful to first think about how you perform the same task using the TestTrack client. The process is often very similar and can help you understand why things need to be done a certain way when using the SDK. In this post, I will discuss logging in, so think about that process when you log in using the TestTrack client. The process is as follows:
- Open the TestTrack client.
- Select the server to connect to.
- Provide your username.
- Provide your password.
- Connect and get list of projects
- Select the project and log in.
So this same process using pseudo code may look something like this:
//Open the TestTrack client.
ttSoap = new ttsoapcgi
//Select the server to connect to.
ttSoap.URL = http://webserver/scripts/ttsoapcgi.exe

//Provide your username.
//Provide your password.
//Connect and get list of projects

ProjectArray = ttSoap.GetProjectList(username, password)
for each project in ProjectArray
     if project.name = "Sample Project"
          myProject = project
//Select the project and log in.
ttSoap.ProjectLogon(myProject, username, password)
It's worth noting that this is not the only way to log in using the SDK. Instead of looping through all of the available projects for the user, you can build the project object and then pass it to the ProjectLogon() method.  This would look something like this:
ttSoap = new ttsoapcgi//Define soap object
ttSoap.URL = http://webserver/scripts/ttsoapcgi.exe
myProject = new Project
myDatabase = new Database
myDatabase.name = "Sample Project"
//Database options specify the functionality to have available for
//access once logged in.
myDatabaseOps = new DatabaseOptions[2]
myDatabaseOps[0] = "TestTrack Pro"
myDatabaseOps[1] = "TestTrack TCM"
myDatabase.DatabaseOptions = myDatabaseOps
myProject.Database = myDatabase
ttSoap.ProjectLogon(myProject, username, password)
So, which one is better? It really depends on the use case. Here are some things of note in regards to the first method:
  • The projects returned in the array are only those that the user has access to. The obvious benefit is that you do not attempt to log in to a project that the user does not have access to.
  • If the project is set up for TestTrack Pro and TestTrack TCM access, the project object will be returned with both data options. This is regardless of the license access the user has and could potentially cause a problem when you try to log in. An error may be returned if the user does not have a license to log in to either TestTrack Pro or TestTrack TCM. If you know that the user only has a license for one of them, you could reset the data options array to only contain one element. Something like this:
ProjectArray = ttSoap.GetProjectList(username, password)
for each project in ProjectArray
     if project.name = "Sample Project"
          myProject = project

myDatabaseOps = new DatabaseOptions[1]
myDatabaseOps[0] = "TestTrack Pro"
myProject.Database.DatabaseOptions = myDatbaseOps
Here are some things of note in regards to the second method:
  • Make sure the user has access to the project object you are building.
  • This method allows you to specify which data options you want to use (i.e., which license(s) to use).
Whichever way you decide to use, make sure you only grab the licenses that you need. If the application you are writing is only going to work with defects, why grab a TestTrack TCM license?