标题: initfunc [打印本页] 作者: smalliv407 时间: 2013-5-28 15:59 标题: initfunc Public Function InitFunc()
If is_fileexists(Local_Path & "debu.txt") or is_fileexists(Local_Path & "debu.txt.bak") Then
reporter.ReportEvent micFail, "error", "met error, exiting test, please re-run it."
ExitTest
End If
''''''''''''''''''''''Modify And''''''''''''''''''''''''''''''''
'Initinal the general configure of the project.
'If connected with QC, download the DataTable from QC, else the DataTable is in the local.
On Error Resume Next
sTemp=QCUtil.CurrentTestSet.Name
If err.number Then
CheckQCConnect2
Err.Clear
Else
CheckQCConnect
End if
On error goto 0
Dim ExcelObj
Dim fso
Dim rc
Dim qtApp
' Set qtApp = CreateObject("QuickTest.Application")
' qtApp.Test.Settings.Run.IterationMode = "oneIteration"
' Set qtApp = Nothing
SYC_TWO=2
SYC_ONE=1
SYC_FIVE=5
SYC_TEN=10
SYC_TWENTY=20
Total_Pass_Count=0
Total_Fail_Count=0
POPUP_WINDOW_TIME=20
DEFAULT_TIMEOUT=Setting("DefaultTimeout")
Setting("DefaultTimeout") =TIMEOUT_WAITPROPERTY
RUNNING_TEST_NAME=Environment("TestName")
TS_TEST_ID = ""
' JpgPath=Environment("TestDir") & "\scr"
JpgPath="C:\Temp\scr"
DATA_TABLE=""
''''''''''''''''If Data Table in QC Test Plan , use this.'''''''''''''''''''''
' If QCUtil.IsConnected Then
' Is_Local_Run=0
' TS_TEST_ID = QCUtil.CurrentTest.ID
' Set CurrentTS=QCUtil.CurrentTestSet
' CURRENT_TESTSET=UCase(Trim(CurrentTS.Name))
' Local_Path=GetAttachmentLocalPathFromTest(TS_TEST_ID,RUNNING_TEST_NAME & ".xls")
' DATA_TABLE=DownloadAttachmentFromTest (TS_TEST_ID,RUNNING_TEST_NAME & ".xls",Local_Path)
' Data_Table=QCGetDataTable(sDataTablePath, Environment("TestName"))
' Else
' Is_Local_Run=1
' DATA_TABLE = Environment("TestDir") & "\" & RUNNING_TEST_NAME & ".xls"
' End If
' Modify By Harris Mar 14
' If Trim(DATA_TABLE) = "" Then
' Report_Msg "", micFailed, "Cannot import the DataTable"
' ExitTest
' End If
''''''''''''''''If Data Table in QC Test Plan , use this.'''''''''''''''''''''
If QCUtil.IsConnected then
Set qcConn = QCUtil.QCConnection
Select Case trim(qcConn.ProjectName)
case "AP_BAURelease_UAT_11a"
DOMAIN = "https://eclipseuat-card.appc.citicorp.com/siteminderagent/forms/login.html"
case "AP_BAURelease_SIT_11a"
DOMAIN = "https://eclipsesit-bank.appc.citicorp.com:5000/siteminderagent/forms/login.html"
case "AP_RainbowNA_Bank_SIT"
DOMAIN = "https://sit1.northasia.customer360view.aspac.citigroup.net:8443/siteminderagent/forms/login.html"
' Case "GCTT_Regression"
' DOMAIN="https://sit.customer360view.aspac.citigroup.net:8443/wps/myportal"
case "GlobalCommon_SIT"
DOMAIN = "https://sit1.globalcommon360view.consumer.citigroup.net:5001"
End Select
Is_Local_Run=0
On Error Resume Next
TS_TEST_ID = QCUtil.CurrentTest.ID
If err.number Then
Set tdc = qcutil.QCConnection
Set tFact = tdc.TestFactory
Set TestFilter = tFact.Filter
TestFilter.Filter("TS_NAME") = chr(34) & RUNNING_TEST_NAME & chr(34)
TestFilter.Filter("TS_TYPE") = "QUICKTEST_TEST"
TestFilter.Filter("TS_SUBJECT") = SubjectPath
Set testList = tFact.NewList(TestFilter.Text)
If testList.Count = 1 Then
TS_TEST_ID = testList.item(1).Field("TS_TEST_ID")
Else
print "the TEST_ID is more than one. please check it."
End If
Set TreeManager = tdc.TestSetTreeManager
Set tsFolder = TreeManager.NodeByPath(Lab_Path_DataPrerare)
Set lst = tsFolder.FindTestInstances(RUNNING_TEST_NAME, True, "")
For i = 1 To lst.Count
Set instance = lst.Item(i)
If Instr(1,UCase(instance.TestSet.Name),UCase(sCountry)) > 0 And CLng(instance.TestID) = TS_TEST_ID Then
CURRENT_TESTSET = UCase(instance.TestSet.Name)
Set runFact = instance.RunFactory
Set theRun = runFact.AddItem("Local Run")
theRun("RN_TESTER_NAME") = tdc.UserName
Exit For
End If
Next
Set TestFilter = nothing
Set tdc = nothing
Set tFact = nothing
Err.Clear
Else
TS_TEST_ID = QCUtil.CurrentTest.ID
Set CurrentTS=QCUtil.CurrentTestSet
CURRENT_TESTSET=ucase(trim(CurrentTS.Name))
End If
On error goto 0
Set obj_data=createobject("vb_html_report.clsreport")
obj_data.SHHK_mkdir(Local_Path)
DataPathonQC = "[QualityCenter\Resources] Resources\Automation\ECS\AutoTest_Card\Regression 2012\Data Table\"
If Instr(1,UCase(CURRENT_TESTSET),"BVT") > 0 Then
DataPathonQC = DataPathonQC & "\BVT\"
End If
DATA_TABLE_ID = GetFoldID(DataPathonQC)
DownloadResource DATA_TABLE_ID, RUNNING_TEST_NAME & ".xls", Local_Path '''Please don't comment block.
DATA_TABLE= Local_Path & RUNNING_TEST_NAME & ".xls"
Else
Is_Local_Run=1
DATA_TABLE = Local_Path & RUNNING_TEST_NAME & ".xls"
DOMAIN = "https://eclipsesit-bank.appc.citicorp.com:5000/siteminderagent/forms/login.html"
End if
Set obj_data=CreateObject("vb_html_report.clsreport")
Set obj_bmp2jpg=CreateObject("vb_bmp2jpg.clsbmp2jpg")
Set fso = CreateObject("Scripting.FileSystemObject")
Set ExcelObj = CreateObject("Excel.Application")
If obj_data.SHHK_folderorfile_exist(jpgpath)=0 Then
obj_data.SHHK_mkdir(jpgpath)
End If
suffix_num=0
ExcelObj.Workbooks.Add
html_file="C:\Temp\"&RUNNING_TEST_NAME&"_result"&suffix_num&".xls"
Do while fso.FileExists(html_file)
suffix_num=suffix_num+1
html_file="C:\Temp\"&RUNNING_TEST_NAME&"_result"&suffix_num&".xls"
Loop
ExcelObj.ActiveWorkbook.Worksheets("sheet1").Range("A:IV").Interior.ColorIndex = 2
' ExcelObj.ActiveWorkbook.SaveAs html_file
Const xlWorkbookNormal = -4143
ExcelObj.ActiveWorkbook.SaveAs html_file,xlWorkbookNormal
ExcelObj.Quit
img_name=1
''''''''''''''''''''''@Harris 11/16 Modify Begin''''''''''''''''''''''''''''''''
Set fso=Nothing
''''''''''''''''''''''Modify And'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Function作者: smalliv407 时间: 2013-5-28 16:02
Public Function SaveAttachmentToRun( LocalFilePath, FileDescription)
Dim current_run,sCnt,sItemID
On Error Resume Next
sFlg = 0
sTestID = QCUtil.CurrentTest.ID
If err.number Then
sFlg = 1
End If
On error goto 0
If sFlg = 0 Then
Set current_run = QCUtil.CurrentTestSetTest
Set Attachments = current_run.attachments
'Update by wc89229 2012.09.21-start
sCnt = Attachments.newlist("").count
For i = 1 to sCnt
sItemID = Attachments.newlist("").Item(1).id
Attachments.RemoveItem sItemID
Next
'Update by wc89229 2012.09.21-End
Set Attachment = Attachments.AddItem(Null)
Attachment.FileName = LocalFilePath
Attachment.Description = FileDescription
Attachment.Type = 1'TDATT_FILE
Attachment.Post ' Commit changes
Else
Set Attachments = instance.attachments
sCnt = Attachments.newlist("").Count
For j = 1 to sCnt
sItemID = Attachments.newlist("").Item(1).id
Attachments.RemoveItem sItemID
Next
Set Attachment = Attachments.AddItem(Null)
Attachment.FileName = LocalFilePath
Attachment.Description = FileDescription
Attachment.Type = 1'TDATT_FILE
Attachment.Post ' Commit changes
Select Case Trim(Reporter.RunStatus)
Case 0
theRun.Status = "PASSED"
Case 1
theRun.Status = "FAILED"
Case 2
theRun.Status = "PASSED"
Case 3
theRun.Status = "PASSED"
Case Else
theRun.Status = "NOT_COMPLETED"
End Select
theRun.Post
End If
End Function作者: smalliv407 时间: 2013-5-28 16:04
Public Function DownloadResource(ParentFolderID, fileName,saveTo)
Set qcConn = QCUtil.QCConnection
Set oResourceFac = qcConn.QCResourceFactory
Set oFilter = oResourceFac.Filter
oFilter.Filter("RSC_PARENT_ID") = ParentFolderID
If fileName <> "" Then
oFilter.Filter("RSC_Name") = chr(34) & fileName & chr(34)
End If
Set oFileList = oFilter.NewList
If oFileList.Count = 0 Then
reporter.ReportEvent micWarning, "not found resource : " & fileName, ""
Exit Function
End If
For i = 1 to oFileList.Count
Set oFile = oFileList.Item(i)
reporter.ReportEvent micDone, "download : " & oFile.FileName, oFile.ResourceType
oFile.DownloadResource saveTo, True
Next
Set qcConn = Nothing
Set oResourceFac = Nothing
Set oFilter = Nothing
Set oFlieList = Nothing
Set oFile = Nothing
end function作者: smalliv407 时间: 2013-5-28 16:05
Function UploadResource(ParentFolderID, fileName, localfilepath)
resourceType = ""
Select Case right(fileName, 3)
Case "vbs"
resourceType = "Function library"
Case "xls"
resourceType = "Data table"
Case "tsr"
resourceType = "Shared object repository"
End Select
Set qcConn = QCUtil.QCConnection
Set oResourceFac = qcConn.QCResourceFactory
Set oFilter = oResourceFac.Filter
oFilter.Filter("RSC_PARENT_ID") = ParentFolderID
oFilter.Filter("RSC_Name") = chr(34) & fileName & chr(34)
Set oFileList = oFilter.NewList
If oFileList.Count = 0 Then
'''''''''''''''''add new resource
Set oFilter = Nothing
Set oResourceFac = Nothing
Set oResourceFolder = qcConn.QCResourceFolderFactory
Set oFilter = oResourceFolder.Filter
oFilter.Filter("RFO_ID") = ParentFolderID
Set oResourceFolderList = oFilter.NewList
Set oResourceFac=oResourceFolderList.item(1).QCResourceFactory
Set oResource = oResourceFac.AddItem(Null)
oResource.FileName = fileName
oResource.ResourceType = resourceType
oResource.Post
End If
Set oFileList = Nothing
Set oFilter = Nothing
Set oResourceFac = Nothing
Set oResourceFac = qcConn.QCResourceFactory
Set oFilter = oResourceFac.Filter
oFilter.Filter("RSC_PARENT_ID") = ParentFolderID
oFilter.Filter("RSC_Name") = chr(34) & fileName & chr(34)
Set oFileList = oFilter.NewList
For i = 1 to oFileList.Count
Set oFile = oFileList.Item(i)
reporter.ReportEvent micDone, "upload : " & oFile.FileName, oFile.ResourceType
oFile.Post
oFile.UploadResource localfilepath,True
Next
Set qcConn = Nothing
Set oResourceFac = Nothing
Set oFilter = Nothing
Set oFlieList = Nothing
Set oFile = Nothing
End Function作者: smalliv407 时间: 2013-5-28 16:06
Function GetFoldID(QCpath)
pathArray = Split(QCpath,"\",-1,1)
GetFoldID = "Nothing"
Set qcConn = QCUtil.QCConnection
Set oFResource = qcConn.QCResourceFolderFactory
Set rootFolder = oFResource.Root
Set Rfolder = rootFolder.QCResourceFolderFactory
Set Rootlist = Rfolder.NewList("")
listCount = Rootlist.Count
For i = 1 to Ubound(pathArray)
For j = 1 to listCount
Set RFolderItem = Rootlist.Item(j)
If RFolderItem.Name = pathArray(i) Then
GetFoldID = RFolderItem.ID
Set Rfolder = RFolderItem.QCResourceFolderFactory
Set Rootlist = Rfolder.NewList("")
listCount = Rootlist.Count
Exit for
else
End If
Next