开发者

Quality Center OTA API: Return just the first-level of child TestSets in a TestSetFolder

The HP QC OTA API appears to provide two methods for returning the list of TestSets within a specified TestSetFolder. However both methods are recursive and return all the tests sets for every single sub-folder further down the hierarchy. I want to be able to return just the immediate child test sets of any given test set folder. I realise this can be achieved using a very simple SQL query using the Command object but this is not an option in my scenario due to the QC permissions required.

Consider the following c# code sample below. This uses the standard QC sample project to illustrate the problem. Using the folder path of "Root\Mercury Tours Web Site\Functionality And UI" the 3 test sets are returned correctly in all cases. However specifying the path of "Root\Mercury Tours Web Site" returns 5 test sets as the sample contains 2 sub folders of 3 and 2 test sets respectively. The SQL correctly does not return any test sets in this case.

// where 'tdc' is a valid TDConnection object logged in to DEFAULT.QualityCenter_Demo
// string testSetFolderPath = @"Root\Mercury Tours Web Site";                          // 0 test sets (Method 1 and 2 return 5)
string testSetFolderPath = @"Root\Mercury Tours Web Site\Functionality And 开发者_C百科UI";     // 3 test sets

// Method 1: TestSetFolder.FindTestSets()
var testSetTreeManager = (TestSetTreeManager)tdc.TestSetTreeManager;
var testSetFolder = (TestSetFolder)testSetTreeManager.get_NodeByPath(testSetFolderPath);
var testSets = testSetFolder.FindTestSets("", false, "");
Console.WriteLine("Folder {0} contains {1} testsets", testSetFolderPath, testSets.Count);

// Method 2: NewList() with filter
var testSetFactory = (TestSetFactory)tdc.TestSetFactory;
var filter = (TDFilter)testSetFactory.Filter;
filter["CY_FOLDER_ID"] = "^" + testSetFolderPath + "^";
testSets = (List)testSetFactory.NewList(filter.Text);
Console.WriteLine("Folder {0} contains {1} testsets", testSetFolderPath, testSets.Count);

// Method 3: SQL Query using Command object
var command = tdc.Command;
command.CommandText = "select CY_CYCLE as TestSet from CYCLE where CY_FOLDER_ID = " + testSetFolder.NodeID;
Recordset records = command.Execute();
Console.WriteLine("Folder {0} contains {1} testsets", testSetFolderPath, records.RecordCount);

It is possible to iterate through the test sets returned to check that the TestSetFolder path property matches the current folder. However, this results in a major performance overhead, especially for large QC projects and/or over a slow network connection.

There must be some way in QC to do this since both QC web UI and QCExplorer tool load test sets progressively as you expand the nodes in the test set tree.

Any ideas? Thanks!


It turns out that the use of the caret (^) symbols on the CY_FOLDER_ID is actually used to enforce a recursive search. If these are removed and replaced with double-quotes then testsets in sub-folders are not returned. So Method 2 in the example can be modified to:

// Method 2: NewList() with filter
var testSetFactory = (TestSetFactory)tdc.TestSetFactory;
var filter = (TDFilter)testSetFactory.Filter;
filter["CY_FOLDER_ID"] = "\"" + testSetFolderPath + "\"";    
testSets = (List)testSetFactory.NewList(filter.Text);
if (testSets == null)
    Console.WriteLine("Folder {0} does not contain any testsets", testSetFolderPath);
else
    Console.WriteLine("Folder {0} contains {1} testsets", testSetFolderPath, testSets.Count);

Thank-you to Christian Grzelka who answered my post on SQAForums.


filter["CY_FOLDER_ID"] = "\"" + testSetFolderPath + "\"";

The above code is not valid from ALM 11. It will throw an error "not an integer value".

You will have to use get_NodebyPath method over a Test Set Tree Manager.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜