我正在将脚本从BPT框架迁移到数据驱动。
每个QTP测试具有相同的结构(公共库和对象存储库),仅更改了QTP测试名称和Action中的4个参数(变量-testid,testname,test desc,testset )。
当前,我需要打开一个现有测试并更改上述参数,然后在ALM上将新测试“另存为”(具有新的测试名称和详细信息)
当占大约10000个测试用例时,这是一个繁琐的任务。但是,我想到了使用 FSO 并在每个测试的操作下更改变量,但是现在测试不是存储在本地而是存储在ALM上。
我正在尝试创建一个脚本,该脚本将更新并创建从Excel工作表提供的多个测试用例。
关于如何进行此操作的任何想法?
答案 0 :(得分:0)
'QC connection
Uname = InputBox ("Enter Username")
Passw = InputBox ("Enter Password")
Set qtApp = CreateObject("quicktest.application")
if Not qtApp.Visible then
qtApp.Launch
qtApp.Visible = True
End if
qtApp.Visible = True
qtApp.TDConnection.Connect "https://URL", "BS", "SRP", Uname, Passw, False
If qtApp.TDConnection.IsConnected Then
strQCTestPath = InputBox ("Give full test plan path")
strQCTestPath = "[ALM] " &strQCTestPath
DefScript = InputBox ("Test Script which is to be copied") 'existing test case
almupload = ALMConn(strQCTestPath, DefScript, qtApp)
if almupload <> "" then
Msgbox almupload
Call KL
Else
Msgbox "something went wrong"
Call KL
End if
Else
MsgBox "Cannot connect to ALM"
Flag = False
Call KL
End If
Function ALMConn(Path, copyscript, qtApp)
Set objexcel = createobject("excel.application")
Set objWorkbook = objexcel.Workbooks.open("C:\book1.xlsx")
Set exceldriver = objWorkbook.worksheets.item("Sheet1")
RC = exceldriver.usedrange.rows.count
CC = exceldriver.usedrange.columns.count
PC = 0
FC = 0
For i = 2 to RC
TSid = exceldriver.cells(i,1).value
TSName = exceldriver.cells(i,2).value
TCid = exceldriver.cells(i,3).value
TCName = exceldriver.cells(i,4).value
'replace the text
str1 = "FLN"&"("&""""""&")"
str2 = "TestSetID = " &""""&TSid&""""
str3 = "TestSetName = "&""""&TSName&""""
str4 = "TestCaseID = "&""""&TCid&""""
str5 = "TestCaseName = "&""""&TCName&""""
str6 = "Call ExecuteTestCase"&"("&"TestSetID"&","&"TestSetName"&","&"TestCaseID"&","&"TestCaseName"&")"
finalstr = str1 &VbCrlf &VbCrlf& str2 &VbCrlf& str3 &VbCrlf& str4 &VbCrlf& str5 &VbCrlf &VbCrlf& str6
Almtestname =TCid &" "&TCName
sFlag = UpdateScript(Path, finalstr, copyscript, Almtestname, qtApp)
if sFlag = True then
exceldriver.cells(i,5).value = "Pass"
PC = PC +1
Else
exceldriver.cells(i,5).value = "Fail"
FC = FC +1
End if
Next
finalcount = "Passcount is "&PC &VbCrlf& "Fail Count is "&FC
ALMConn = finalcount
objWorkbook.Save
objexcel.quit
qtApp.TDConnection.Disconnect
End Function
Function UpdateScript(Path, sfinalstr, refscript, Tname, qtApp)
'On error resume next
'Err.Clear
If qtApp.TDConnection.IsConnected Then
oPath = Path &"\"&refscript
qtApp.Open oPath, False
' if err.number>0 then
' UpdateScript = False
' ExitFunction
' Else
'"[ALM] Subject\Delete\1\GUITest1", False '"C:\Local Disk\New Folder\GUITest1"
oldtext = qtApp.Test.Actions(1).GetScript
' End if
Else
Msgbox "not connected"
UpdateScript = False
ExitFunction
End if
If oldtext <> "" then
qtApp.Test.Actions(1).SetScript(sfinalstr)
qtApp.Test.SaveAs Path &"\"&Tname '"C:\Local Disk\New Folder\GUITest2"
if Err.Number>0 then
UpdateScript = False
ExitFunction
Else
UpdateScript = True
End if
Else
UpdateScript = False
End if
End Function
Function KL
Set qtApp = Nothing
exceldriver = Nothing
objWorkbook = Nothing
objexcel = Nothing
End Function