QTP AOM code to enable image capture on script failure is not working - hp-uft

QTP AOM code to enable image capture on script failure is not working
I am using the below code to enable the QTP Screen Capture option but it's not storing any screenshots:
Code:
Dim App
Dim qtTest
'Create the QTP Application object
Set App = CreateObject("QuickTest.Application")
'If QTP is notopen then open it
If App.launched <> True then
App.Launch
End If
'Make the QuickTest application visible
App.Visible = True
'Set QuickTest run options
'Instruct QuickTest to perform next step when error occurs
App.Options.Run.ImageCaptureForTestResults = "OnError"
App.Options.Run.RunMode = "Fast"
App.Options.Run.ViewResults = True
'Open the test in read-only mode
App.Open "D:\GUITest4", True
'set run settings for the test
Set qtTest = App.Test
'Instruct QuickTest to perform next step when error occurs
qtTest.Settings.Run.OnError = "NextStep"
'Run the test
qtTest.Run
'Check the results of the test run
MsgBox qtTest.LastRunResults.Status
' Close the test
qtTest.Close
'Close QTP
'App.quit
'Release Object
Set qtTest = Nothing
Set App = Nothing
Can anyone help?

Try this to capture screenshots:
set obj = Desktop
obj.capturebitmap strFileName & ".png"
To have the screenshot embedded in results itself, give the path of results in strFileName parameter as:
strFileName = Environment.Value("ResultDir") & "\" & Mid(Environment.Value("ActionName"), 1, 15) & filename.png

Using QTP AOM we can capture the screenshot which will be stored in the results folder , can be controlled via below code.
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtApp.Open "C:\Tests\Test1", True
Set qtTest = qtApp.Test
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
Create the Run Results Options object
qtResultsOpt.ResultsLocation = "C:\Tests\Test1\Res1"
Set the results location
qtTest.Run qtResultsOpt
Run the test
qtTest.Close
Hope it helps, let me know the results

Related

It is necessary to write a vbs script to run multiple xlam files in one excel instance

The task is to write vbs scripts that:
The first vbs script (1.vbs) opens an excel instance and loads the 1.xlam file into the open excel instance.
The second vbs script (2.vbs) loads the 2.xlam file into the same excel instance.
The next one (3.vbs) loads the same instance of excel 3.xlam and so on.
I tried a lot, but I have new *.xlam being loaded into new instances of excel, not the previously opened one.
How to solve a problem?
My loader1.vbs - for load loader1.xlsm
Set omExcel = CreateObject("excel.application")
omExcel.Visible = True
vmAlertXLSM = omExcel.AutomationSecurity
omFile.AutomationSecurity = 1
vmFile = replace(WScript.ScriptFullName, ".vbs",".xlsm")
omExcel.Workbooks.Open vmFile
omExcel.AutomationSecurity = vmAlertXLSM
This Ok
I need to write loader2.vbs which loads my loader2.xlsm to the same Excel instance so that the functions written in loader1.xlsm and loader2.xlsm can see each other
It doesn't work like that - a new instance of Excel opens:
vmFile = replace(WScript.ScriptFullName, ".vbs",".xlsm")
With GetObject(, "Excel.Application")
.Visible = True
.Workbooks.Open (vmFile)
End With
Excel Instances
You can open a file in a new instance of Excel with:
With CreateObject("Excel.Application")
.Visible = True
.Workbooks.Open ("C:\Test1.xlsx")
End With
You can open another file in a running instance with:
With GetObject(, "Excel.Application")
.Workbooks.Open ("C:\Test2.xlsx")
' Prove that your in the same instance:
ReDim wbNames(.Workbooks.Count - 1)
For Each wb In .Workbooks
wbNames(n) = wb.FullName
n = n + 1
Next
MsgBox "Open Workbooks: " & vbLf & vbLf & Join(wbNames, vbLf)
End With

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.

Vbscript GetObject Returns Unspecified Error

I'm new to vbscript and i'm writing an application to:
open internet explorer
insert search text
click search button
get result count text
So far i have:
Dim obj
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "www.google.com"
WScript.Sleep 4000
IE.Document.getElementById("lst-ib").value = "Test"
IE.Document.Forms(0).Submit()
WScript.Sleep 4000
Set IE = GetObject("","InternetExplorer.Application")
obj = IE.Document.All.item("resultStats").InnerText
MsgBox obj
However, if i run this i get the following error:
Error: Unspecified error
Code: 80004005
I don't know what could be wrong.
Can anyone help me?
Thanks

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

Resources