Find tests under a test plan folder using OTA API

In this post, we will discuss how to find tests under a test plan folder using OTA API. We will use C#.

For finding tests under a test plan folder we will use the following classes

  1. TreeManager : For finding the folder under test plan
  2. TestFactory : For finding tests under the test plan folder

First, we will get the test Folder object using the below code

TDAPIOLELib.TreeManager OTManager = tDConnection.TreeManager;
var OTFolder = OTManager.get_NodeByPath(folderPath);

Where tDConnection is the ALM Connection object. You can read about it here.

once we have the test folder object then we will get the testfactory object from it

TDAPIOLELib.TestFactory OTFactory = OTFolder.TestFactory;

After this, we will just have to call the NewList function to get the test objects.

OTFactory.NewList("");

Complete code is below

public TDAPIOLELib.List GetTests(String folderPath)
{
TDAPIOLELib.TreeManager OTManager = tDConnection.TreeManager;
var OTFolder = OTManager.get_NodeByPath(folderPath);
TDAPIOLELib.TestFactory OTFactory = OTFolder.TestFactory;
return OTFactory.NewList("");
}

If you want to find the list of tests under “Subject\Dummy1\Dummy2” folder then you can call the GetTests function like this

TDAPIOLELib.List Tdlist = GetTests("Subject\\Dummy1\\Dummy2");
foreach (TDAPIOLELib.Test test in Tdlist)
{
Console.WriteLine("Test Found under Subject\\Dummy1\\Dummy2 : " + test.Name);
}

Let me know if you have any questions in Comments.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s