I’ve had several requests recently for more examples using the OTA API. So I thought I’d pull some examples out of the comments section of this post https://fijiaaron.wordpress.com/2011/11/17/updating-test-results-in-qc-using-the-qc-ota-api-explained/ and give them their own space.
The first example is executing tests. In order to execute a Test, you first need to get a TestSet. This corresponds to a specific TestSet in a TestLab.
Start off by opening a connection to Quality Center:
var connection = new TDConnection(); connection.InitConnectionEx(qcUrl); connection.ConnectProjectEx(qcDomain, qcProject, qcLoginName, qcPassword);
Get a TestSetFactory and TestSetManager from to the Connection to find a TestSet.
TestSetFactory testSetFactory = connection.TestSetFactory; TestSetTreeManager testSetTreeManager = connection.TestSetTreeManager;
Then search a specified path (starting with “ROOT/”) to for TestSets that match a given name. You can actually retrieve multiple TestSets if you specify part of a name, or all test sets in a folder and subfolders if you pass an empty string. If you’re pretty sure you have an exact match — you can just get the first result from the list.
TestSetFolder testSetFolder = (TestSetFolder) testSetTreeManager.NodeByPath[testSetPath]; List testSetList = testSetFolder.FindTestSets(testSetName); TestSet testSet = testSetList;
It’s probably worth noting that the TDOLEAPI has it’s own concept of a list. It was written before C# with generic collections exists, so it takes a little work to convert a TDOLEAPI.List to a generic List. I won’t go into that now. Just treat it like an array, and iterate over it with an index.
Once you have a TestSet, you can run it by calling the scheduler.
TSScheduler scheduler = testSet.StartExecution(""); scheduler.RunAllLocally = true; scheduler.Run();
And that’s all there is to it.
The empty string passed to StartExecution() is a server name, but as you can see, we want to run them locally in this example, so it’s blank. Run() can optionally take an object containing test data.