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.
You can see the full example in this gist. I’ve also added it to the QCIntegration Examples.
8 thoughts on “Executing Tests in Quality Center using the OTA API”
Tried your example, However get an unhandled exception at Line od start execution
TSScheduler scheduler = testSet.StartExecution(“”);
System.Runtime.InteropServices.COMException was unhandled
Message=Class not registered(Exception from HResult: 0x80040154 (REGB_E_CLASSNOTREG))
at TDAPIOLELib.ITestSet2.StartExecution(String ServerName)
Am I missing any required add-ins? What is the server name variable that we should use? Can this be altered by giving the host Name
I’m not sure.
First question: 1) what version of the API do you have? – I tried with version 9.
I’m not exactly sure about the servername parameter. If you’d like, I could try to help you debug in your environment, since I don’t currently have access to a Quality Center setup.
Nice example. Could you explain please how you execute a single test as well? The above example shows the execution of a test set.
I’m not sure, but I don’t think it is possible to execute a single test outside the context of a test set. But you can filter your test set to only include the test you want. Just add the test id as a parameter to Scheduler.Run(“test_id”). You can also specify more than one test id by passing a comma separated list. Scheduler.Run(“test_1,test_2,etc”)
Thanks for the reply.
Oddly enough, the Scheduler.Run() acts like it’s expecting an integer. When I pass it a string of the test id, I get a COM error. When you say ‘filter down to the test you want’, what exactly do you mean? I’ve seen a few articles out there where devs are filtering the TSTestFactory instance that they have. For example:
dynamic value = xxtsFactory.Filter
value.Filter[“TC_TESTCYCL_ID] = “.
But even when I’ve done this, it treats the assigned value as a string and I get the above mentioned COM error. It’s all very curious to me.
I really appreciate any suggestions you may have. I’m a web dev stuck in the UFT/ALM world for now.
The above line formatted weird. It was supposed to be: