Student Mode Code Display

Welcome to the Fraternity!

Commenting has been enabled. You can comment on all the Code Items now.

KW Driven FW using Data table Approach

Add This Code to My Favourite List
Enter Email

Contributed By IT Prof
Date 2016-03-12 07:28:54

'Tutorial: itprof_tut
'Description: Example of KW Test FW
'Author: Akash
'Company: IT Professional Academy
'Details: TC list will be maintained in the MetaData file. All test cases marked as True will Run.
' 			Each row in Meta Data Sheet corresponds to a TC, with the same name in the work book.
'			All the KW in the TC will Execute.

'Create a File with the Name: MetaDataAndTCFile
' Create MetaData Sheet with Schema as Below:
'TC1        TRUE
'TC2        TRUE
'TC3        FALSE

' Create Each TC sheet with Schema as below:
'FunctionName	RunFlag	Arg1	                        Arg2	Arg3	Arg4	Arg5	Result
'InvokeApp	       TRUE	
'Login	              TRUE	  john	                           demo
'NavigateToPage	TRUE	Open New Account 	
'Fnc2	              FALSE		

Dim sFilePath, sSrcSheetName, sMainSheetName
sFilePath = "C:\QTPStuff\QTPTrainingCode\DataSheet\MetaDataAndTCFile.xls"
sFilePath_Export = "C:\QTPStuff\QTPTrainingCode\DataSheet\MetaDataAndTCFile_Export.xls"
sMainSheetName = "MetaData"

'Import Excel File

DataTable.ImportSheet sFilePath,"MetaData","MetaData"
DataTable.ImportSheet sFilePath,"TC1","TC1"
DataTable.ImportSheet sFilePath,"TC2","TC2"
DataTable.ImportSheet sFilePath,"TC3","TC3"
DataTable.ImportSheet sFilePath,"TC4","TC4"

'Delete Unwanted Sheet

'Get Row Count
sRowCount_MetaData =  DataTable.GetSheet("MetaData").GetRowCount
For i=1 to sRowCount_MetaData
	sTC_ID =DataTable.Value("TC_ID",sMainSheetName)
	sRunFlag = DataTable.Value("RunFlag",sMainSheetName)
	If Cbool(sRunFlag)  Then
		Reporter.ReportEvent micDone, "Running TC:"&sTC_ID,"TC Started"
		Call RunTestCase(sTC_ID)
		DataTable.Value("Result",sMainSheetName) = "Executed"
		Reporter.ReportEvent micDone,"TC Skipped:"&sTC_ID,"TC Skipped"
		DataTable.Value("Result",sMainSheetName) = "Not Executed"
	End If


'Export Data File

'Funtion to Execute KW present inside TC
Function RunTestCase(sTCName)
   Dim sRowCount_TC, i
   Dim sFncName, sRunFlag, sArg1, sArg2, sArg3, sArg4, sArg5

	'Get the Row Count
	sRowCount_TC=  DataTable.GetSheet(sTCName).GetRowCount

	'Iterating KWs in the TC
	For i=1 to sRowCount_TC
		'Reading values form Current Row
		sFncName = DataTable.Value("FunctionName",sTCName)
		sRunFlag = DataTable.Value("RunFlag",sTCName)
		sArg1 = DataTable.Value("Arg1",sTCName)
		sArg2 = DataTable.Value("Arg2",sTCName)
		sArg3 = DataTable.Value("Arg3",sTCName)
		sArg4 = DataTable.Value("Arg4",sTCName)
		sArg5 = DataTable.Value("Arg5",sTCName)
		Reporter.ReportEvent micDone,"Running KW "&sFncName& " .For TC" & sTCName,""
		'Checking if Run Flag is Set
		If Cbool(sRunFlag) Then
			Select Case sFncName
				Case "InvokeApp"
					Call InvokeApp(sArg1)
				Case "Login"
					Call Login(sArg1,sArg2)
				Case "NavigateToPage"
					Call NavigateToPage(sArg1)
			End Select
			DataTable.Value("Result",sTCName) = "Executed"
			Reporter.ReportEvent micDone,"KW Skipped", sFncName
			DataTable.Value("Result",sTCName) = "Not Executed"
		End If
		'Setting the next row

End Function

Download Above Code


Add your comments...
Name : *      
Email : *      
The content of this field will be kept private and will not be shown publicly

Your Comment/Answer *

Enter the text present in this box : *