Abstract
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).
Introduction
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
Background
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 -
TDConnection
object
Fig 2. OTA Object model
Implementation
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:
="1.0" ="utf-8"
<configuration>
<appSettings>
-->
<add key="QCserverURL" value="QCServerURL"/>
-->
<add key="QCdomainName" value="Your Domain Name"/>
-->
<add key="QCprojectName" value="Your project Name"/>
-->
<add key="username"
value="<a href="mailto:jawed.ace@gmail.com%22/%3E">jawed.ace@gmail.com</a>-->
<add key="pwd" value="myPassword"/>
-->
<add key="QCFolderLocationForTestCase"
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;
Failed;Passed;Accepted Failure;Blocked;N/A;Repair;Unsupported"/>
-->
<add key="htmlWebPageLocation" value="C:\\QcReportIntegrationTeam.html"/>
</appSettings>
</configuration>
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.
Declaring namespace:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Net;
using System.Drawing;
using System.Drawing.Drawing2D;
using TDAPIOLELib;
To add 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 =
ConfigurationSettings.AppSettings["TCStatusNames"].ToString();
string testSetFolderPath =
ConfigurationSettings.AppSettings["QCFolderLocationForTestCase"].ToString();
string chartTitleTestCasesReport =
ConfigurationSettings.AppSettings["ChartTitleForTestCasesReport"].ToString();
string strLocationToSavePieChartImages =
ConfigurationSettings.AppSettings["locationToSavePieChartImages"].ToString();
string strServerURL = ConfigurationSettings.AppSettings["QCserverURL"].ToString();
string strDomainName = ConfigurationSettings.AppSettings["QCdomainName"].ToString();
string strProjectName =
ConfigurationSettings.AppSettings["QCprojectName"].ToString();
string strHtmlWebpageLocation =
ConfigurationSettings.AppSettings["htmlWebPageLocation"].ToString();
Now we are ready with all the input to start our programming.
- First login to the QC.
TDConnection qctd = new TDConnection();
qctd.InitConnectionEx(strServerURL);
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.
Class Diagram
Fig 6. Class Diagram
The code is as explained below:
if (qctd.Connected)
{
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)
{
if (testFoldername!=null)
{
filter["CY_FOLDER_ID"] = "\"" +
testFoldername + "\"";
List testSets = (List)testSetFactory.NewList(filter.Text);
if (testSets != null)
{
string[] arrValueNames = strTestCaseStatus.Split(';');
DataSet dsTC = new DataSet();
dsTC.Tables.Add("TestCaseExecutionReport");
dsTC.Tables[0].Columns.Add("TestName");
dsTC.Tables[0].Columns.Add("TestStatus");
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];
try
{
foreach (TDAPIOLELib.TSTest test in ftest)
{
dsTC.Tables[0].Rows.Add
(test.Name, test.Status);
}
int totalRow = dsTC.Tables[0].Rows.Count;
int TSrowValue = 0;
foreach (string TCfilterValue in arrValueNames)
{
if (TCfilterValue != null)
{
DataView dvDataTC = new DataView(dsTC.Tables[0]);
dvDataTC.RowFilter = "TestStatus like '" +
TCfilterValue + "'";
TCStatus[TSrowValue] = dvDataTC.Count;
TSrowValue++;
}
}
string strImageNames = nameOfTestSuit + "_" +
DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
string chartTitle=string.Empty;
if(arrChartTitleTestCasesReport.Length==1)
{
chartTitle = arrChartTitleTestCasesReport[0] +
" " + nameOfTestSuit;
}
else
{
chartTitle = arrChartTitleTestCasesReport
[chartTitleCount] + " " + nameOfTestSuit; ;
}
Bitmap btMapImages = GeneratePieChart.pieChart
(TCStatus, arrValueNames, chartTitle); btMapImages.Save(strLocationToSavePieChartImages +
strImageNames, System.Drawing.Imaging.ImageFormat.Png);
CreateHtmlPage.saveHtmLPage(TCStatus, nameOfTestSuit,
strLocationToSavePieChartImages + strImageNames,
arrValueNames, totalRow, strHtmlWebpageLocation);
dsTC.Clear();
} catch (Exception ex)
{
Console.WriteLine(ex.Message);
} }
} } 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);
btMapImages.Save(strLocationToSavePieChartImages +
strImageNames, System.Drawing.Imaging.ImageFormat.Png);
- 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.
http://jawedm.blogspot.com
Happy automation using C#.....
Feel free to provide your comments and suggestions. Thanks!!