Controller "C:\AUTOMATION_CALC\CONFIG\CALC.TSR", "C:\WINDOWS\system32\calc.exe", "C:\Automation_calc\TestData\ Testcase.xls " ' File Call function Function Controller (ByVal tsrpath,byval apppath,byval datapath) Repositoriescollection.add Tsrpath Systemutil.run AppPath Executetestcase DataPath Window ("Calculator"). Close End Function ' Execute use case function Function executetestcase (ByVal filepath) Dim xlapp, Xlworkbook, Xlsheet Dim Irowcount, Iloop, Num1,op,num2,expect_result,test_result, Result_record Set xlapp = CreateObject ("Excel.Application") ' Xlapp.visible = True Set xlworkbook = Xlapp.workbooks.open (filepath) Set xlsheet = Xlworkbook.sheets ("Calc") Irowcount = Xlsheet.usedrange.rows.count For iloop = 2 to Irowcount NUM1 = Xlsheet.cells (Iloop, 1) op = Xlsheet.cells (Iloop, 2) num2 = Xlsheet.cells (Iloop, 3) Expect_result = Xlsheet.cells (Iloop, 4) Test_result = calculation (Num1,op,num2,expect_result) Result_record = Result_record & num1 & op & num2 & "=" & Expect_result & "TestResult---->" &am P Test_result & vbCrLf Next Writetestreport "C:\Automation_calc\Report\testreport.txt", Result_record ' Xlworkbook.save Xlworkbook.close xlApp.Quit Set xlsheet = Nothing Set xlworkbook = Nothing Set xlapp = Nothing End function ' Business logic functions Function calculation (ByVal num1, ByVal op, ByVal num2, Expect_result) Dim Actual, expect Window ("Calculator"). Winedit ("Edit"). Type (NUM1) Window ("Calculator"). Winbutton (OP). Click Window ("Calculator"). Winedit ("Edit"). Type (NUM2) Window ("Calculator"). Winbutton ("="). Click Actual_result = window ("calculator"). Winedit ("Edit"). Getroproperty ("text") actual = Trim (Actual_result) arr = Split (Actual, ".") If arr (0) = Trim (Expect_result) Then Calculation = "Pass" Else Calculation = "Fail" End If End Function ' Reporting functions Function Writetestreport (ByVal filepath, ByVal str) Dim FSO, fil Set fso = CreateObject ("Scripting.FileSystemObject") Set fil = fso.opentextfile (filepath, 2, True) Fil. Write Str Fil.close Set fil = Nothing Set fso = Nothing End Function |