Using this application, a user can generate a report of a test case execution from QC (Quality center) into an HTML web page with a fancy pie chart and a tabular format using C# and OTA API expose from QC (Quality Center).
Before jumping to the main point, let me clarify that there would be so many articles available on the internet to generate Test cases execution report using VB.NET but using C# for the same you will find very little information. I have developed this app using C#.NET. In this app, you will get feasibility to generate a report as an HTML web page from QC and the HTML page would contents the pie chart of test cases executed with tabular format along with this you can email this report to your whole team member. Apart from that, you can store the result back to QC location for future use.
What are the New Features I have Provided?
This application is a whole bundle package, just one *.exe runs and the result would be in your inbox.
Using this, you will be able to:
- Generate test cases report.
- Draw Pie chart based on report.
- Store the result in HTML webpage.
- Email this report using any email service provider (like Outlook, etc.)
- Save the result to local hard drive or back to QC location.
- Be an early morning manager ready with the report.
Refer to the below graph for the best explanation:
Fig 1. QC data Puller Diagram
As I am into C# automation and not very good in VB script and in QTP, I thought of using C# for this purpose. There isn't much help available on the internet for OTA of QC for C#.NET and working in a big organization, the people at the top are more interested in data, fancy report irrespective of your oral conversation and they believe more in the report. So I thought of attracting the C# Automation guys also towards QC (Quality center) API reports and finally at one points of time, there would be enough information available on the net.
Last but not least, this is my small effort to achieve this.
What is OTA API?
You will get loads of information available on the net for the same. Just Google it or Bing it, you will get enough information. But still I would prefer to give you some basic information for the same.
- The Open Test Architecture (OTA) API is a COM library that enables you to:
- integrate external applications with Quality Center
- interact with the Quality Center application without having to use the GUI front-end
- interact with the QC databases bypassing DBA
- The API functions are accessible through COM-compatible programming languages, such as Visual Basic, VBScript, C++, C#, etc.
- The API has one entry point -
Fig 2. OTA Object model
I have used C# programming language to achieve my purpose. To talk with the QC, I have included TDAPIOLELib DLL Provided by mercury labs. We have used console application from Visual Studio IDE to develop this application so that we can easily schedule this into Windows scheduler for running at regular time intervals. To store all the settings and inputs values, I have used app.config file to store the configuration value. Overall, I have used a very easy and direct approach to achieve my task so that even the person who is new to C# can understand this.
The HTML report would appear something like this:
Fig 3. HTML web page as report
Using the Code
Part 1: App.config
Before going deep into the code, I would love to explain the App.config file which I have used to store all the inputs settings. So that you will get an idea like prerequisite:
<add key="QCserverURL" value="QCServerURL"/>
<add key="QCdomainName" value="Your Domain Name"/>
<add key="QCprojectName" value="Your project Name"/>
<add key="pwd" value="myPassword"/>
value="Root\Integration Team\Anna-GR-4\ePrint;Root\Integration Team\Anna-GR-4\ SIPs"/>
<add key="ChartTitleForTestCasesReport" value=" eprint ; Sips"/>
<add key="locationToSavePieChartImages" value="C:\QCReportImages\"/>
<add key="TCStatusNames" value="Not Completed;No Run;
<add key="htmlWebPageLocation" value="C:\\QcReportIntegrationTeam.html"/>
Part 2: Main Program
This will be our main idea to put forward to work as per our requirement or how we want to handle the code to work for us.
TDAPIOLELib namespace, follow the below steps:
- Go to your solution explorer
- Click on References
- Select add references
- On opening window clicked on Browser tab
- Go to the location C:\Program Files\Common Files\Mercury Interactive\Quality Center
- Select OTAClient.dll and click on Ok button, if you don’t have OTAClient.dll, then you need to download it from the web.
Refer to the below figure for details:
Fig 4. Adding OTAClient.dll
- Go to your main program, add the namespace as shown in the below figure:
Fig 5. Adding TDAPIOLELib name space.
Now, you ready to use class and function provided by OTA API. We start our programming here after.
We will read all the settings provided in App.config file into our local strings so that we can use it in the program here and there.
string username = ConfigurationSettings.AppSettings["username"].ToString();
string pwd = ConfigurationSettings.AppSettings["pwd"].ToString();
string strTestCaseStatus =
string testSetFolderPath =
string chartTitleTestCasesReport =
string strLocationToSavePieChartImages =
string strServerURL = ConfigurationSettings.AppSettings["QCserverURL"].ToString();
string strDomainName = ConfigurationSettings.AppSettings["QCdomainName"].ToString();
string strProjectName =
string strHtmlWebpageLocation =
Now we are ready with all the input to start our programming.
- First login to the QC.
TDConnection qctd = new TDConnection();
qctd.ConnectProjectEx(strDomainName, strProjectName, username, pwd);
- Go to the Test lab folder from where you have to read the test cases.
- Collect all the test cases and their corresponding status in dataset.
- Using data view the count of various test status like passed, failed, etc.
Fig 6. Class Diagram
The code is as explained below:
TestSetFactory testSetFactory = (TestSetFactory)qctd.TestSetFactory;
TDFilter filter = (TDFilter)testSetFactory.Filter;
string testCasesFolderNames = testSetFolderPath.Split(';');
string arrChartTitleTestCasesReport = chartTitleTestCasesReport.Split(';');
int chartTitleCount = 0;
foreach (string testFoldername in testCasesFolderNames)
filter["CY_FOLDER_ID"] = "\"" +
testFoldername + "\"";
List testSets = (List)testSetFactory.NewList(filter.Text);
if (testSets != null)
string arrValueNames = strTestCaseStatus.Split(';');
DataSet dsTC = new DataSet();
foreach (TDAPIOLELib.TestSet tst in testSets)
string nameOfTestSuit = tst.Name;
TSTestFactory tstf = (TSTestFactory)tst.TSTestFactory;
List ftest = (List)tstf.NewList(" ");
int TCStatus = new int[arrValueNames.Length];
foreach (TDAPIOLELib.TSTest test in ftest)
int totalRow = dsTC.Tables.Rows.Count;
int TSrowValue = 0;
foreach (string TCfilterValue in arrValueNames)
if (TCfilterValue != null)
DataView dvDataTC = new DataView(dsTC.Tables);
dvDataTC.RowFilter = "TestStatus like '" +
TCfilterValue + "'";
TCStatus[TSrowValue] = dvDataTC.Count;
string strImageNames = nameOfTestSuit + "_" +
DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
chartTitle = arrChartTitleTestCasesReport +
" " + nameOfTestSuit;
chartTitle = arrChartTitleTestCasesReport
[chartTitleCount] + " " + nameOfTestSuit; ;
Bitmap btMapImages = GeneratePieChart.pieChart
(TCStatus, arrValueNames, chartTitle); btMapImages.Save(strLocationToSavePieChartImages +
strLocationToSavePieChartImages + strImageNames,
arrValueNames, totalRow, strHtmlWebpageLocation);
} catch (Exception ex)
} } chartTitleCount += 1;
- Now we will call pie chart function to draw pie chart for the various test status. We will pass various parameters to the pie chart method to draw our pie chart like: test status count, test status names, chart title.
For the code to draw pie chart, download the code and go through the code. You can use your own code for that purpose too. There is so much code available on the net to draw a pie chart.
- The pie chart method will return the images as bitmap. We will save images to our local location to use this into HTML web page report, else you can directly use this to HTML page but for record purposes, I am saving this to our local location.
Fig 7. Pie chart sample
Bitmap btMapImages = GeneratePieChart.pieChart(TCStatus, arrValueNames, chartTitle);
- After that we will call a method to put all the data into an HTML web page with tabular format as shown in the below diagram:
Fig 8. Format into HTML web page
For the code, please go through the code uploaded on this website. I have provided comments at each line so that you can understand better and in a nice way.
- Call your method to send out the report as attached or embedded into the email through Outlook or any email client.
- The ready report would be available in your mail box.
- You can add this *.exe to your Windows
scheduler to run daily or weekly basis and to send out reports to your team members or to whomever you want.
Is this not great!!!
- So being automation engineers, this is our responsibility to make manual processes easy and automatic so that we can save time, effort and of course money.
You can go through my blog to get more ideas and to see the work in progress.
Happy automation using C#.....
Feel free to provide your comments and suggestions. Thanks!!