Upload Test cases from Excel to Quality Center(QC)

Writing Test Cases directly to QC is quite a cumbersome task. So To simplify the process, We can create the test cases in an excel sheet and then upload them to QC.
To do so, we have to make sure that the columns used in excel match with the fields/data which we enter in QC. I will explain the steps using an example,–

1. Suppose we have created the test cases in excel in below

2. Now, next step would be to install the excel addin for QC. To do so, follow the following steps:-
    a. Launch Quality Center
    b. Click on Addins link
    c. Click on More QC Addins link
    d. We can go through the Guide also or this step can be skipped
    e. Click on “download …” link
    f. Follow the steps of installation
    g. Restart the system

3. Now open the excel sheet containing test cases ns select only the part which needs to be uploaded as shown in the picture below.

4. Now go to Tools—>Export to Quality Centre. Following window would be displayed. Login with valid credentials.

5.Click on Next and login with valid credentials. Click Next again.

6. Select the respective domain and project.

7. Select ‘Tests’ Radio button and click Next.

8. Select New Map to store the settings. Give a map name and click next.

9. Now, we have to map each column in our excel sheet to specific fields in QC. To do so, click on following from the quality center valued displayed in window and give their respective column numbers.

10. Window would look like this after selecting all values. Click on next button.

11. Above steps will upload the test cases in QC at path ‘Iteration1ModuleABCxyz’. We can view them in Qc now.
Donot mention the root directory.
If the xyz folder is not present  at Iteration1ModuleABC in QC, it would be created.
similarly, if the ModuleABC folder itself is not present at Iteration1, The folder and subfolder mentioned would be created.

Click the below links for further read on same topic:
Steps to download and install MS Excel Add-In for HP QC/ALM 11.5x

QTP code to perform double click action.

I worked on a requirement, where i had to view the contents of folder in documentum by double clicking the folders. I used the following code for this…

   1: 'Wait Property to wait for the contents of table to display 
   2: Browser("abc").Page("pqr").Frame("xyz").WebTables( 
"TableName").WaitProperty "rows",micGreaterThanOrEqual(1)
   3: 'Use ondblclick fireevent to double click on the required 
   4: Browser("abc").Page("pqr").Frame("xyz").WebTables( 
.fireevent "ondblclick"
   5: Browser("abc").Page("pqr").Sync

I have used web tables because, QTP was recognizing the folders as images and view as table.

QTP Code to Select All items from a list box

The following QTP code can be used in case we want to select multiple values in a list box. Here, I have selected all the items.

   1: Set oPage=Browser("Browser").Page("Page Name")
   2: Set Lists=WebListObjects(oPage)
   3: AllDataItems=Lists(3).GetROProperty("items Count")
   4: 'select all the data items
   5: For i=2 to AllDataItems
   6:    x=Lists(3).GetItem(i) 
   7:    Lists(3).ExtendSelect  x
   8: Next


1.set the current page
2. Set the List object by calling function. To view the WebListObjects is a function which is defined. Click here to view the function
3. Store the number of records in required list, in the variable AllDataItems
5. Initiate the for loop to traverse through the data items in the list
6. Store each item of list into a variable x
7. Select the elements one by one

QTP General Functions to Define Web Objects

While automating a web application, we encounter objects which are used again and again. We can always add them to out object repository, but iy would make the repository very bulky as the same object would be needed to add for each page.

To solve this issue, we can use following functions in the function library to define web objects.

   1: 'Functions for creating objects for web page
   2: Function WebObjects(Page, MicClass)
   3:     Set Desc = Description.Create()
   4:     Desc("micclass").Value = MicClass
   5:     Set WebObjects = Page.ChildObjects(Desc)
   6: End Function
   7: 'Function:Create webedit object
   8: Function WebEditObjects(Page)
   9:     Set WebEditObjects = WebObjects(Page, "WebEdit")
  10: End Function 
  11: 'Function:Create webbutton object
  12: Function WebButtonObjects(Page)
  13:     Set WebButtonObjects = WebObjects(Page, "WebButton")
  14: End Function
  15: 'Function:Create link object
  16: Function WebLinkObjects(Page)
  17:     Set WebLinkObjects = WebObjects(Page, "Link")
  18: End Function
  19: 'Function:Create image object
  20: Function WebImageObjects(Page)
  21:     Set WebImageObjects = WebObjects(Page, "Image")
  22: End Function
  23: 'Function:Create radiogroup object
  24: Function WebRadioObjects(Page)
  25:     Set WebRadioObjects = WebObjects(Page, "WebRadioGroup")
  26: End Function
  27: 'Function:Create weblist object
  28: Function WebListObjects(Page)
  29:     Set WebListObjects = WebObjects(Page, "WebList")
  30: End Function
  31: 'Function:Create webtable object
  32: Function WebTableObjects(Page)
  33:     Set WebTableObjects = WebObjects(Page, "WebTable")
  34: End Function
  35: 'Function:Create  WebCheckBox object
  36: Function WebCheckBoxObjects(Page)
  37:     Set WebCheckBoxObjects = WebObjects(Page, "WebCheckBox") 
  38: End Function

The above functions can be called as per below examples:-

   1: Value1 = "Delhi"
   2: Set oPage=Browser("Browser").Page("PageName")
   3: Set Lists=WebListObjects(oPage)
   4: Lists(0).select Value1

   5: Set Edits=WebEditObjects(oPage)
   6: Edits(9).set "test"
   7: Set RadioButton=WebRadioObjects(oPage)
   8: RadioButton(12).select "#0"

   9: set CheckBox=WebCheckBoxObjects(oPage)
  10: CheckBox(i).Set "ON"

QTP Function-Export/Send Output/Result Data to Excel

The below function exports the data to an excel sheet from QTP. We can use this function to export the test results to excel. The function would be called every time a custom checkpoint occurs.

   1: Function WriteData(Flag,ResultArray,i)
   2:    'Output data from result array to excel
   3:     ExcelPath="FilePath.xls"
   4:     WorkSheetName2="Sheet1"
   5:     StatusPass="Pass"
   6:     StatusFail="Fail"
   7:     StatusNoRun="No Run"
   8:     'Modify Array with status
   9:     If Flag=1 Then
  10:         ReDim Preserve ResultArray(i)
  11:         ResultArray(2)=StatusPass
  12:     else
  13:         ReDim Preserve ResultArray(i)
  14:         ResultArray(2)=StatusFail
  15:     End If
  16:     'Ensure that the xls file exists
  17:     CheckFile (ExcelPath)
  18:     'Create Excel Object
  19:     Set ObjExcel=CreateObject("Excel.Application")
  20:     Set ObjWorkbook=ObjExcel.Workbooks.Open(ExcelPath)
  21:     Set ObjSheet=ObjWorkbook.Worksheets(WorkSheetName2)
  22:     'Count  number of  used rows 
  23:     iRowCount = ObjSheet.usedrange.rows.count
  24:     i=iRowCount+1
  25:     j=0
  26:     For each k in ResultArray
  27:         j=j+1
  28:         ObjSheet.cells(i,j).value=k
  29:     Next
  30:     'Get the final value of status field
  31:     Status=ObjSheet.cells(i,3)
  32:     'Mark the colour of status field depending on its value
  33:     Select Case Status
  34:       Case StatusPass
  35:           ObjSheet.cells(i,3).interior.colorindex =4
  36:       Case StatusFail
  37:           ObjSheet.cells(i,3).interior.colorindex =3
  38:       Case StatusNoRun
  39:           ObjSheet.cells(i,3).interior.colorindex =6
  40:     End Select
  41:     'Save workbook
  42:     ObjWorkbook.Save
  43:     'Close excel sheet
  44:     ObjExcel.DisplayAlerts = False
  45:     ObjExcel.Quit
  46:     ' destroy the other objects 
  47:     Set ObjExcel = Nothing
  48:     Set ObjSheet = Nothing
  49:     Set objFS = Nothing
  50: End Function

Line Number wise Explanation:-

Flag is a Boolean variable where 1 is a pass.
ResultArray stores the strings for pass/fail status for each checkpoint.
i corresponds to number of strings in the Result array.
The excel sheet looks like:-

Excel Sheet for QTP function

1: We pass the variable Flag,ResultArray,i as function arguments.
3: Specify the path name in argument “ExcelPath”. Here we can also export the path name to a XML file by using the below code.
we load the environment  variables from the XML file. The contents of xml file can be as below

   1: <Environment>
   2:     <Variable>
   3:         <Name>FLOWREPOSITRY</Name>
   4:         <Value>pathShared_Repository.tsr</Value>
   5:     </Variable>
   6:     <Variable>
   7:         <Name>FUNCTIONLIBRARY</Name>
   8:         <Value>PathGeneralFunctionLibrary.qfl</Value>
   9:     </Variable>
  10:     <Variable>
  11:         <Name>INPUTEXCELPATH</Name>
  12:         <Value>PathTestData.xls</Value>
  13:     </Variable>
  14:     <Variable>
  15:         <Name>OUTPUTEXCELPATH</Name>
  16:         <Value>PathTestResult.xls</Value>
  17:     </Variable>
  18:     <Variable>
  19:         <Name>RECOVERYSCENARIO</Name>
  20:         <Value></Value>
  21:     </Variable>
  22: </Environment>

4:   Define the variable to store name of worksheet.
5:   StatusPass is the string to contain “Pass” string
6:   StatusFail is the string to contain “Fail” string
7:   StatusNoRun is the string to contain “No Run” string
9:   If Flag=1, then Store Pass status to 2nd column of ResultArray other wise Store Fail status to 2nd column of ResultArray
17: Check if the output file exists.
19: Create the object for Excel
20: Create the object for workbook
21: Create the objects for sheet.
23: Count the number of used rows in output sheet(so that the next run would be stored in next line) and store in variable iRowCount.
24: Set value if i to the next empty row number
15: Count the number of columns in input sheet and store in variable iColumnCount.

18: for each row, 1st column value is saved in the variable TestName
20: The controls goes into If condition if the TestName retrieved is same as TestId passed. Other wise it is skipped and goes to next row till end of rows.
21: The inner for loop traverses through the columns of required test.
23: Each column value is saved in DataArray.
26: The for loop traverses Result Array and places it’s data in the excelsheet
31: Retrieve the status of test from ith row, 3rd column.
33. The case statement is used to colour the cells according to their status. Red for Fail, Green for Pass and
42: Save the excel sheet
44: We need to close the excel object.
47: We should destroy the Objects as not doing so would

QTP General Function to Read Input Data from Excel and store it in an array.

The below function reads data from an excel file stored at some location, into an array.

   1: Function ReadData(TestId)
   2:     Dim DataArray()
   3:     'Specify  Values of path
   4:     ExcelPath="path of excel file"
   5:     WorkSheetName1="Test_InputData"
   6:     'Create the File System Object
   7:     CheckFile(ExcelPath)
   8:     'if file exists, proceed as below
   9:     'Create excel object
  10:     Set ObjExcel = createobject("excel.application") 
  11:     Set ObjWorkbook = ObjExcel.WorkBooks.Open(ExcelPath)
  12:     Set ObjSheet = ObjWorkbook.Worksheets(WorkSheetName1)
  13:     'Count  number of rows and columns
  14:     iRowCount = ObjSheet.usedrange.rows.count
  15:     jColumnCount=ObjSheet.usedrange.columns.count
  16:     'Retrieve row with current test  name
  17:     For i=1 to iRowCount
  18:         TestName=Trim(ObjSheet.cells(i,1).value)
  19:         'Retrieve value of  input data in array for current 
  20:         If  TestName=TestId Then
  21:             For j=1 to jColumnCount
  22:                 ReDim Preserve DataArray(j)
  23:                 DataArray(j)=Trim(ObjSheet.cells(i,j).value
  24:                 Next
  25:             Exit For
  26:         End If
  27:     Next
  28:     'Close excel sheet
  29:     objExcel.DisplayAlerts = False
  30:     objExcel.Quit
  31:     ' destroy the other objects
  32:     Set objFS = Nothing
  33:     Set ObjExcel = Nothing
  34:     Set ObjSheet = Nothing
  35:     ReadData=DataArray
  36: End Function
Line Number Wise Explanation:-

The excel file comprises of a workbook and the workbook then contains sheet(s). We are using an excel sheet which contains it’s first column as the testId or TestName.

1: We pass the TestId or TestName as a string to the function argument.

4: Specify the path name in argument “ExcelPath”. Here we can also extract the path name from a XML file by using the below code.

   1: Environment.LoadFromFile("pathEnvFile.xml")
   2: ExcelPath=Environment.Value("INPUTEXCELPATH")

we load the environment variables from the XML file. The contents of XML file can be as below.

   1: <Environment>
   2:     <Variable>
   3:         <Name>FLOWREPOSITRY</Name>
   4:         <Value>pathShared_Repository.tsr</Value>
   5:     </Variable>
   6:     <Variable>
   7:         <Name>FUNCTIONLIBRARY</Name>
   8:         <Value>PathGeneralFunctionLibrary.qfl</Value>
   9:     </Variable>
  10:     <Variable>
  11:         <Name>INPUTEXCELPATH</Name>
  12:         <Value>PathTestData.xls</Value>
  13:     </Variable>
  14:     <Variable>
  15:         <Name>OUTPUTEXCELPATH</Name>
  16:         <Value>PathTestResult.xls</Value>
  17:     </Variable>
  18:     <Variable>
  19:         <Name>RECOVERYSCENARIO</Name>
  20:         <Value></Value>
  21:     </Variable>    
  22: </Environment>

5:   Define the variable to store name of worksheet.
7:   Calling the function to check if the file name exists or not.
10: Create the object for Excel
11: Create the object for workbook
12: Create the objects for sheet.
14: Count the number of rows in input sheet and store in variable iRowCount.
15: Count the number of columns in input sheet and store in variable iColumnCount.
17: The outer loop is used for retrieving row which contains the test name or test id same as that was passes in the function
18: for each row, 1st column value is saved in the variable TestName
20: The controls goes into If condition if the TestName retrieved is same as TestId passed. Other wise it is skipped and goes to next row till end of rows.
21: The inner for loop traverses through the columns of required test.
23: each column value is saved in DataArray.
25: Exit the outer for loop after all data has been retrieved.
26: Exit the if statement
29: We need to close the excel object.
33: We should destroy the Objects as not doing so would
35: This statement returns the array “DataArray” to the calling function.

QTP General Function to check/verify that some file exits on the given path or not.

Below is the QTP function which can be used in any general functional library to check/verify that a file exists or not.

1: Function CheckFile(FilePath)
2: 'Create the File System Object
3:  Set objFS = CreateObject("Scripting.FileSystemObject")
4: 'Ensure that the file exists
5:  If Not objFS.FileExists(FilePath) Then
6:     ' issue a fail if the file wasn't found
7:     Reporter.ReportEvent micFail, "Read File", "Unable to read  file, file not found: " & FilePath
8:     ' file wasn't found, so exit  test
9:     ExitTest
10: End If
11: End Function

1. We pass the fine name as a string to the function.
3. Then we are creating the file system object, “objFS”.
5. Now to ensure that the file exists on the file system, we use if conditional statement.
7. If the File name is not found on the file system, Fail is issued to the test with specified message.
8. After fail is issued, exit the test.

QTP – Menu bar / Menu Items missing

Some times, we face problems with QTP menu bar. The menu bar disappears or some menu items disappear from the tool bar.

To enable missing items or display all menu items in the tool bar, follow the following steps:-
1. Right click any where in the tool bar area.
2. Click Customize
3. Go to toolbars tab
4. Click on Restore all button.

To enable missing items or display all menu items in the menu bar, follow the following steps:-
1. Go to Start page of QTP
2. Go to Tools–>Options
3. In the general section, click on Restore Layout button.

Integration Testing

Integration Testing is is performed after Unit Testing. Integration testing is done when individual software modules are combined and tested as a group.Integration testing is the testing of combined parts of an application to determine if they function together correctly. The ‘parts’ can be code modules, individual applications, client and server applications on a network, etc. This type of testing is most useful to client/server and distributed systems.

Integration Testing can be classified in three different ways.

  • Big Bang Integration Testing
  • Top Down Integration Testing
  • Bottom Up Integration Testing
  • Hybrid Integration testing

What is Unit Testing?

Unit Testing is the testing of individual software components or modules. It is the foremost level of software testing and is commonly performed prior to integration testing.
Unit testing performed in the implementation phase can result in significant gains in software quality. If unit testing is done properly, testing phases done later on will be more successful. Unit testing is considered the job of developers only and test engineers need not know about Unit testing. But this is not the case, Unit testing is as important for test engineers as it is for developers.

Developers generally write the unit test cases but it is also important for the testers to understand them. Tester’s understanding of the framework and unit testing can certainly help him/her in designing the flow for unit test cases, generating test data and making good reports. All these activities will ultimately help a tester in the long run as product quality will increase significantly because of the efforts a tester put in on the unit testing.

Advantage/Benefits of Unit Testing

  • Unit Testing plays a major role in the total testing efforts.
  • It allows being able to test parts of a project with out waiting for the other parts to be available.
  • Achieve parallelism in testing by being able to test and fix problems simultaneously by many engineers.
  • Be able to detect and remove defects at a much less cost compared to other later stages of testing.
  • Be able to take advantage of a number of formal testing techniques available for unit testing.
  • Simplify debugging by limiting to a small unit the possible code areas in which to search for bugs.
  • Be able to test internal conditions that are not easily reached by external inputs in the larger integrated systems (for example, exception conditions not easily reached in normal operation).
  • Be able to achieve a high level of structural coverage of the code.
  • Avoid lengthy compile-build-debug cycles when debugging difficult problems.
  • Unit testing is more cost effective compared to the other stages of testing.

Demerits of Unit Testing:-

  • Testing can be monotonous, boring and repetitive at this level.
  • Poor Documentation of Test cases may be there.
  • Coding Drivers and Stubs.
  • Informal testing process.
  • Poor Regression Testing.
  • Lack of Complete Testing tools.