Call Driver_Test_Set()
Function Driver_Test_Set()
oReport.AddSheet_BusinessList Environment("Report_Dir"),formatdatetime(now(),2)
Dim row_count '记录的测试用例集一共有多少个
' import the Set table to QTP's data table
call DataTable.AddSheet(SET_SHEET)
call DataTable.ImportSheet(TestSetExcelFile,1, SET_SHEET)
row_count = DataTable.GetSheet(SET_SHEET).GetRowCount
logPrint("最多执行"&row_count&"个测试用例")
' 导入测试用例的数据,默认为第一个Sheet
call DataTable.AddSheet(TEST_SHEET)
If testCaseSheetName<>"" Then
call DataTable.ImportSheet( testCaseFile, testCaseSheetName, TEST_SHEET )
else
call DataTable.ImportSheet( testCaseFile, 1, TEST_SHEET )
End If
logPrint("测试用例的数据加载完成。"&testCaseFile)
row_count = DataTable.GetSheet(TEST_SHEET).GetRowCount
set taskFile = createobject("scripting.dictionary") ' taskFIle Key为存放task的文件名称,值为其路径
set testDataTable = createobject("scripting.dictionary") ' testDataSheet ,Key为存放Excel文件名+Sheet名,值为Sheet名
'首先找到需要加载的task文件
DataTable.GetSheet(TEST_SHEET).SetCurrentRow( 1 )
For i=1 to row_count
If DataTable("IDX",TEST_SHEET) = "√" Then
taskFileName = DataTable("bizName",TEST_SHEET)
if NOT taskFile.Exists(taskFileName) Then
taskFilePath = pathFind(Environment("testScriptFolderName"),taskFileName,"vbs")
call taskFile.add(taskFileName,taskFilePath)
ExecuteFile taskFilePath '加载task脚本文件
' ExecuteFile "D:\测试技术\qtp\project1\project\frameUtil\ClassExcelReport.vbs" '加载task脚本文件
' Set oReport = New ExcelReport
logPrint("加载Task脚本文件完成。"&taskFilePath)
Execute "Set obj"&taskFileName&" = new "&taskFileName '初始化task的类
End If
End If
DataTable.GetSheet(TEST_SHEET).SetNextRow
Next
'存放业务的Task的文件加载完毕
'加载测试数据所在的Sheet
DataTable.GetSheet(TEST_SHEET).SetCurrentRow( 1 )
For i=1 to row_count
If DataTable("IDX",TEST_SHEET) = "√" Then
testDataSheetName = DataTable("bizDataTable",TEST_SHEET)
If NOT testDataTable.Exists(testDataSheetName) and testDataSheetName<>"" Then
tempArray = split(testDataSheetName,".") 'tempArray(0)是sheet名称
If Ubound(tempArray)=0 and tempArray(0)<>"" Then
'如果只有Sheet名称,则加载当前Excel文件的Sheet
call testDataTable.add(testDataSheetName,tempArray(0))
call DataTable.AddSheet(tempArray(0))
call DataTable.ImportSheet( testCaseFile, tempArray(0), tempArray(0) )
elseif Ubound(tempArray)=1 and tempArray(1)<>"" Then
'如果是引用的外部Excel的sheet,那么。。。
call testDataTable.add(testDataSheetName,tempArray(1))
testDataFilePath = pathFind(Environment("testDataFolderName"),tempArray(0),"xls")
call DataTable.AddSheet(tempArray(1))
call DataTable.ImportSheet( testDataFilePath, tempArray(1), tempArray(1) )
logPrint("加载测试数据完成。"&tempArray(1))
else
logPrint("数据文件的dataTable列格式错误。"&testDataSheetName)
End If
End If
End If
DataTable.GetSheet(TEST_SHEET).SetNextRow
Next
'开始按照顺序执行测试用例中的具体的各个Task
DataTable.GetSheet(TEST_SHEET).SetCurrentRow(1)
For i = 1 to row_count
If DataTable("IDX",TEST_SHEET) = "√" Then
'执行该脚本文件中的具体方法,方法名称为Excel表格中的taskName的值,暂时不做中英文名称的字典匹配,直接使用英文
className = DataTable("bizName",TEST_SHEET)
taskName = DataTable("taskName",TEST_SHEET)
bizDataTableName = DataTable("bizDataTable",TEST_SHEET)
filterExp =DataTable("filter",TEST_SHEET) '过滤测试数据的条件语句
If bizDataTableName<>"" Then
'如果task有对应的测试数据,那么加载对应的测试数据
Sheet_Name = testDataTable.item(DataTable("bizDataTable",TEST_SHEET))
test_data_row_count = DataTable.GetSheet(Sheet_Name).GetRowCount
For j=1 To test_data_row_count
DataTable.GetSheet(Sheet_Name).SetCurrentRow( j )
If Eval(generateFilterExp(Sheet_Name,filterExp)) Then
'Eval(generateFilterExp(Sheet_Name,filterExp)) ,解析测试数据的条件语句,符合此条件的,则执行该行测试数据,否则不执行
str = "obj"&className&"."&taskName&" "&chr(34)&Sheet_Name&chr(34)
End If
'oReport.AddReport caseName,className,taskName,,0,"成功","成功","明细"
'msgbox testCaseSheetName
DataTable.GetSheet(Sheet_Name).SetNextRow
Next
else
'如果task没有对应的测试数据,则不加载测试数据,如退出登录logout()方法
str = "Call obj"&className&"."&taskName&"()"
logPrint("执行测试步骤 "&i&", "&str)
Execute str
end if
oReport.AddReport caseName,className,taskName,0,"成功","成功","明细"
End If
DataTable.GetSheet(TEST_SHEET).SetNextRow
Next
logPrint("所有测试步骤执行完成。")
'释放定义的所有对象
tempArray = taskFile.keys
For i=0 to taskFile.Count-1
Execute "Set obj"&tempArray(i)&" = nothing"
Next
Set taskFile = nothing
tempArray = testDataTable.items
For i=0 to testDataTable.Count -1
If tempArray(i)<>"" Then
Call DataTable.DeleteSheet(tempArray(i))
End If
Next
Set testDataTable = nothing
Call DataTable.DeleteSheet(TEST_SHEET)
Driver_TestCase= 0
End Function作者: auuppp 时间: 2011-12-25 13:22 标题: 自己整合的比较经典的qtp框架+excel报告 本帖最后由 auuppp 于 2011-12-25 13:24 编辑
这个问题解决了,我创建了几个文件夹以后就可以了。
但是心的问题又出现了,是不是我环境变量设置的有问题?应该如何设置?[attach]86260[/attach][attach]86260[/attach]作者: amo666 时间: 2013-7-19 20:56
SET_SHEET = Environment("SET_SHEET")
TEST_SHEET = Environment("TEST_SHEET")
不明白Environment("SET_SHEET")和 Environment("TEST_SHEET")的值是什么?在QTP中查看也没查出来。作者: leal_2012 时间: 2013-7-22 21:14
Private Sub Report_Click()
Dim input_report As String
Dim long_input As Long
Dim serrial_project As Integer: serrial_project = 0
If Date_Month.Text = "" Then
MsgBox "Please input Report Date !"
End
End If
input_report = Date_Month.Text
long_input = CLng(CDate(input_report)) 'change date to long
'
Private Function each_project(a, b)
Dim j, k As Integer: k = 0
Dim sourch_report As String
Dim p1, p2 As Integer
Dim q1, q2 As String
Dim long_source As Long
Dim sum_ports As Integer: sum_ports = 0
For j = 1 To Sheets.Count
If UCase(Sheets(j).Name) = UCase(Sheets("month").Cells(a + 5, 3).Value) Then
While (UCase(Sheets(j).Cells(4 + k, 13).Value) <> "")
If (UCase(Sheets(j).Cells(4 + k, 13).Value) = "YES") Then
sourch_report = Sheets(j).Cells(4 + k, 10).Value
p1 = InStr(sourch_report, "/")
p2 = InStrRev(sourch_report, "/")
q1 = Left(sourch_report, p1 - 1)
q2 = Right(sourch_report, Len(sourch_report) - p2)
long_source = CLng(CDate(q1 & "/" & q2))
If long_source = b Then
sum_ports = sum_ports + Val(Sheets(j).Cells(4 + k, 11).Value)
End If
End If
k = k + 1
Wend
Sheets("month").Cells(a + 5, 5).Value = sum_ports
sum_ports = 0: k = 0
Exit For
End If
Next j
End Function作者: sakuragi0 时间: 2013-7-23 09:50
楼主是“QTP轻量级自动化测试框架”的作者吗?目测该框架和那个几乎一样.作者: forlanhan 时间: 2013-9-10 14:03 回复 29#nonesense