How to get Business component instance number from QC/ALM - vbscript

I am working on BPT framework on QTP and for a testcase i am using same component multiple times. I want to fetch the Business component instance number from QC ->Testplan->TestCase->Business component. Based on the instance number i will read the required component parameters from excel sheet.
Thanks.

Below code worked for me:
Set TestTree = TestSet.TSTestFactory
Set TestList = TestTree.NewList("")
For Each TSTest In TestList
Set Test = TSTest.Test
Set objTestFactory = tdc.TestFactory
Set tFilter = objTestFactory.Filter
tFilter.Filter("TS_TEST_ID") = Test.ID
Set tList = objTestFactory.NewList(tFilter.Text)
Dim objTest
For Each tst In tList
If tst.Type = "BUSINESS-PROCESS" Then
Set objTest = tst
Exit For
End If
Next
If objTest Is Nothing Then
Else
Dim BPTest As BusinessProcess
Set BPTest = objTest
BPTest.Load
' Get list if component instance from the Test
Set components = BPTest.BPComponents
Set Component = components.Item(1)
For i = 1 To BPTest.BPComponents.Count
componentName = components.Item(i).Name
componentInstanceId = components.Item(i).ID
ComponentId = components.Item(i).Component.ID
Next
End if
Next
This code will fetch the details from the test lab level and go until the business component level. Currently it is extracting the component name and id. You can modify the code as per your need.
Visit tutorial at knowlzz . It has explained the solution nicely with each and every detail.

Related

Using HP-UFT, is Is there anyway to tell whether or not an object in the object repository is being used in other tests?

I'm currently using UFT -- I have a GUI test, and there's a web element object in one of my tests I'd like to delete/update, but I'm worried it's being referenced by another test in our test suite. (I am coming into a test suite that someone else built)
Is there anyway to tell whether or not an object in the object repository is being used in other tests? (Without having to go into each individual test and action to find out?)
My way would be simple recursive file search.
Open EditPlus
Search -> Find In Files
Find What =
File Type = *.mts | *.vbs | *.qfl
Folder =
Select the Include Sub Folder Check Box
Click Find
You can use Search>View>Find (or ctrl+F) from UFT and select to look in entire solution
Open "Script.mts" file from every action and search for your object name. If you find the object, write the script name and line number where your object exists, in a file.
Use the below code:
'strScriptsPath is the path where your test script folders are placed.
Set strScripts = objFSO.GetFolder(strScriptsPath).SubFolders
For Each Script In strScripts
strAction = strScriptsPath & "\" & Script.Name & "\Action1\Script.mts"
If objFSO.FileExists(strAction) Then
'Open Script in NotePad
Set strFile = objFSO.OpenTextFile(strAction, 1)
Do While Not (strFile.AtEndOfStream)
strLine = strFile.ReadLine
If InStr(1, strLine, strObjectName) > 0 Then
iVerificationCount = objSheet.UsedRange.Rows.Count
iCurrentRow = iVerificationCount + 1
objSheet.Cells(iCurrentRow, 1) = Script.Name
objSheet.Cells(iCurrentRow, 2) = strLine
If strFile.AtEndOfStream Then
objSheet.Cells(iCurrentRow, 3) = strFile.Line
Else
objSheet.Cells(iCurrentRow, 3) = strFile.Line - 1
End If
End If
Loop
strFile.Close
Set strFile = Nothing
End If
Next
Set strScripts = Nothing
To be able to use this code, declare objFSO object and write a piece of code to create an excel and get objSheet.
You can also replace the object name using the below code:
Use the For Each Loop as mentioned above
strScript = strScriptsPath & "\" & strScriptName & "\Action1\Script.mts"
strFind = "Old Object Name"
strReplace = "New Object Name"
Set strFile = objFSO.OpenTextFile(strScript, 1)
strData = strFile.ReadAll
strNewData = Replace(strData, strFind, strReplace)
strFile.Close
Set strFile = Nothing
Set strFile = objFSO.OpenTextFile(strScript, 2)
strFile.Write strNewData
strFile.Close
Set strFile = Nothing
** You just need to write this entire code in a .vbs file and run that file.

Trying to Read Value from Excel Through Loop and Storing to Environment Variable

I am trying to read values from Excel Data File and trying to store the values to environment variables. Then I want to reuse these environment variables in my tests.
However following code giving me unexpected run time error. With no error code no . When I fix the code with static excel (Row,Col) then I get the result but I need to control it through a loop. Need help.
For x = 2 to Row_TD
TDID = TestData_Sheet.Cells (x , "A")
IF TestData_Sheet.Cells (x,"B") = "Y" Then
fnReadData
Function fnReadData
Environment.Value("URL") = TestData_Sheet.Cells(x,"C")
msgbox environment.Value("URL")
Environment.Value("Browser") = TestData_Sheet.Cells(x,"D")
msgbox environment.Value("Browser")
Environment.Value("City") = TestData_Sheet.Cells(x,"E")
Environment.Value("Zip") = TestData_Sheet.Cells(x,"F")
Environment.Value("LoanAmount") = TestData_Sheet.Cells(x,"G")
Environment.Value("DownPayment") = TestData_Sheet.Cells(x,"H")
Environment.Value("Points") = TestData_Sheet.Cells(x,"I")
msgbox Environment.Value("Points")
Environment.Value("FICO") = TestData_Sheet.Cells(x,"J")
Try the below
TestData_Sheet.Cells(x,"E").Value 'Invalid
And
TestData_Sheet.Range("E"&x).value 'valid
TestData_Sheet.Cells(x,5).value 'valid

Use VBScript to show properties dialog/sheet - for multiple items

I'm trying to write a script in VBS to show the file properties dialog/sheet for multiple items. Those items will be all of the items in a parent folder (e.g. all items in W:\).
Essentially, I'm trying to get the properties dialog to show the number of files in a drive. Right-clicking on the drive and selecting Properties does not show the number of files. You would instead need to go into the first level of the drive, select all folders/files, and then right-click and select Properties.
I have customised some code (below) I've found on the internet to bring up the file properties dialog/sheet for either a specific folder, or a drive. I have no idea what I could further change to get the properties dialog for all files and folder of a specified drive. Perhaps getting all folders/files of the drive into an array and then working with that?
Please note I'm looking for the actual properties dialog, and not just a simple return of the total number of files (I know how to do this).
Any help would be appreciated! Thanks :)
Code:
dim objShell, objFSO, folParent, sParent, filTarget, sFileName, sOutput, fivVerbs, iVerb, vVerb, fvbVerb, testItemsParent, TestMappedDestination
set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("Shell.Application")
const mappedDestination = "c:\"
vVerb = "P&roperties"
sParent = objFSO.GetParentFolderName(mappedDestination)
sFileName = objFSO.GetFileName(mappedDestination)
If Len(mappedDestination) = 3 then
nsTarget = &H11
TestMappedDestination = "(" & UCase(Left(mappedDestination,2)) & ")"
Else
nsTarget = sParent
TestMappedDestination = UCase(sFileName)
End If
set folParent = objShell.Namespace(nsTarget)
For each filTarget in folParent.Items
If Len(mappedDestination) = 3 then
testItemsParent = UCase(Right(filTarget,4))
Else
testItemsParent = UCase(filTarget)
End if
If testItemsParent = TestMappedDestination then
Set fivVerbs = filTarget.Verbs
For iVerb = 0 to fivVerbs.Count - 1
If fivVerbs.Item(iVerb).Name = vVerb then
Set fvbVerb = fivVerbs.Item(iVerb)
fvbVerb.DoIt()
filTarget.InvokeVerbEx fvbVerb.Name, ""
Msgbox "Placeholder msgbox to keep properties dialog/sheet from disappearing on script completion"
Exit for
End if
Next
Exit for
End if
Next

AutoExport Run Results from UFT Function

I am running an automated test script using UFT 12.52. I am wondering if there is a way to export results from within a function in the UFT Script. The idea is to call the function and export the run results.
I can do it externally by creating a .vbs file which launches the script in uft and runs and exports the result, but i cannot figure out how to do it from within a UFT Script as function.
Below is my code for exporting results externally.
Thanks
Dim qtApp
Dim qtTest
Dim qtResultsOpt
Dim qtAutoExportResultsOpts
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible = True
qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False
qtApp.Open "Z:\D:\paperlessEnhancements\", True
Set qtTest = qtApp.Test
qtTest.Settings.Run.IterationMode = "rngIterations"
qtTest.Settings.Run.StartIteration = 1
qtTest.Settings.Run.EndIteration = 1
qtTest.Settings.Run.OnError = "NextStep"
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
qtResultsOpt.ResultsLocation = "C:\Tests\Test1\Res1" n
Set qtAutoExportResultsOpts = qtApp.Options.Run.AutoExportReportConfig
qtAutoExportResultsOpts.AutoExportResults = True
qtAutoExportResultsOpts.StepDetailsReport = True
qtAutoExportResultsOpts.DataTableReport = True
qtAutoExportResultsOpts.LogTrackingReport = True
qtAutoExportResultsOpts.ScreenRecorderReport = True
qtAutoExportResultsOpts.SystemMonitorReport = False
qtAutoExportResultsOpts.ExportLocation =
"C:\Documents and Settings\All Users\Desktop"
qtAutoExportResultsOpts.UserDefinedXSL = "C:\Documents and Settings\All
Users\Desktop\MyCustXSL.xsl"
qtAutoExportResultsOpts.StepDetailsReportFormat = "UserDefined"
qtAutoExportResultsOpts.ExportForFailedRunsOnly = True
qtTest.Run qtResultsOpt
MsgBox qtTest.LastRunResults.Status
qtTest.Close
Set qtResultsOpt = Nothing
Set qtTest = Nothing
Set qtApp = Nothing
Set qtAutoExportSettings = Nothing
I also tried this :
Dim qtResultsOpt
Dim qtAutoExportResultsOpts
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
qtResultsOpt.ResultsLocation = "C:\Temp\Notepad1"
Set qtResultsOpt = Nothing
#Lukeriggz :Attach a function library to all your script and the function library should be called in first place in your script(Either you can call the lines in your current library function itself. But the significance is to set the attribute at the first place and start with the execution). The content of the library should be the one which you have shown the code except the Open,run statement and releasing the objects(Primarily the configuration statements should be there). This will make your result location always pointed to your desired path and you can view the results. While configuration of the script have the script name in a variable to create the result file name to act is as dynamic
Another Implementation
We can easily identify where the results are getting saved Using the inbuilt environment variable. So programmatically we can copy the folder using file system objects
enter code here
executionpath=Environment.Value("ResultDir")
path_to_save_the_results= "Type your path where the results should be saved"
fso.CopyFolder executionpath, path_to_save_the_results

Change the name of added worksheet

objWriteWorkbook.sheets.add ,objWriteWorkbook.sheets(objWriteWorkbook.sheets.count)
Set NewWorksheetObject = objWriteWorkbook.Worksheets(num)
objWriteWorkbook.Sheets(num).Name = sheetName
I wanted to change the name of added worksheet.
Adding of sheet and object creation for that sheet is working fine but when I try to change the name of the sheet I am getting an error "Unknown runtime error"
Can any one help how can change the name of added sheet.
Assign the new sheet to a variable when you add it:
Set ws = wb.Sheets.Add(, wb.Sheets(wb.Sheets.Count))
ws.Name = sheetName
set xlo=CreateObject("excel.application")
set wbo=xlo.workbooks.open("C:\Users\XXX\Desktop\Temp.xlsx")
Set ws = wbo.Sheets.Add(, wbo.Sheets("sheet1"))
ws.Name = "Priyesh"
wbo.save
wbo.close
xlo.quit
set wbo=nothing
set xlo=Nothing

Resources