Filtering Test from Test Plan using Test ID (TS_TEST_ID) in ALM/QC

Hello Friends,

In this post, we will discuss filtering ALM test using its primary ID(TS_TEST_ID) field.

Filtering Tests from Test Plan using Test ID (TS_TEST_ID)

For filtering tests using Test ID, copy the below code and execute, function will return the ALM test object (TDAPIOLELib.Test).

Details about how to connect to ALM using OTA API is here


public static TDAPIOLELib.Test GetALMTestUsingTestID(String TESTID)

{

TDAPIOLELib.TestFactory OTestFactory = OQConnection.TestFactory as TDAPIOLELib.TestFactory;

TDAPIOLELib.TDFilter OTDFilter = OTestFactory.Filter as TDAPIOLELib.TDFilter;

TDAPIOLELib.List OTestList;

TDAPIOLELib.Test OTest;

try

{

OTDFilter["TS_TEST_ID"] = TESTID;

OTestList = OTestFactory.NewList(OTDFilter.Text);

if (OTestList != null && OTestList.Count == 1)

{

OTest = OTestList[1];

return OTest;

}

else

{

return null;

}

}

catch (Exception ex)

{

Debug.WriteLine("Error occurred while fetching the test object using test ID : " + ex.Message.ToString());

return null;

}

}

How it works?

For finding the test with test id, we will use TDFilter object. First, we will have to cast the TDFilter object using


TDAPIOLELib.TDFilter OTDFilter = OTestFactory.Filter as TDAPIOLELib.TDFilter;

Then we will use this object for setting the filter for the test id field, which will create the filter text


OTDFilter["TS_TEST_ID"] = TESTID;

Once we have the TDFilter populated with the desired filter text, then we will use the TestFactory object to create the list of tests with TS_TEST_ID = TESTID, which is passed to the function using


OTestList = OTestFactory.NewList(OTDFilter.Text);

Now, if the test id passed to the function does not exist or there are any other errors then, OTestList will have null value stored in it otherwise it should have the list of tests having the criteria defined within the filter.

Now, because we are using the filter field as the primary key of the test table, we will only get one test in the results, so to make sure we can check if the count of tests inside the OTestList.Count is 1.

Then we can simply get our test object using


OTest = OTestList[1];

Now, we can use this object for updating any field value.

Let me know, if you need any help, I will try to provide the solutions.

Thanks

Advertisements

2 responses to “Filtering Test from Test Plan using Test ID (TS_TEST_ID) in ALM/QC

  1. If I want to search Test cases with a keyword and find all the matched Test IDs, how can I do that?? Could you please help.

    Like

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s