how to send QuickTest Professional (QTP) test results to an .xls file through vb script
You can modify the pair of functions below to suit your needs.
This function initializes an Excel spreadsheet.
Function initOutExcel(sTablePath)
Datatable.addSheet "Results"
Datatable.importSheet sTablePath, "Results","Results"
iParamCount = Datatable.getSheet("Results").getParameterCount
if iParamCount = 0 Then
Datatable.getSheet("Results").addParameter "S.No",""
Datatable.getSheet("Results").addParameter "Status",""
Datatable.getSheet("Results").addParameter "Functionality",""
Datatable.getSheet("Results").addParameter "Description",""
End If
Datatable.ExportSheet sTablePath,"Results"
End Function
This function appends the Result of a Test to the end of the existing results.
Function WriteResults(sTablePath,sStatus,sFunctionality,sDescription)
Datatable.addSheet "Results"
Datatable.importSheet sTablePath, "Results","Results"
iRowCount = Datatable.getSheet("Results").getRowCount
Datatable.getSheet("Results").setCurrentRow(iRowCount+1)
Datatable("S.No","Results") = iRowCount+1
Datatable("Status","Results") = sStatus
Datatable("Description","Results") = sDescription
Datatable("Functionality","Results") = sFunctionality
Datatable.ExportSheet sTablePath,"Results"
End Function
(Source)
Related
Hello I am using the following code and trying to write the results in the excel sheet column name result, but it's not writing the results in it, however, it will export the sheet but wouldn't write the result. Can you please help me with what I am missing here? All the help is much appreciated. Thanks.
DataTable.AddSheet "TestCases"
DataTable.AddSheet "TestSteps"
DataTable.ImportSheet "this is the excel sheet", "Tcases", "TestCases"
DataTable.ImportSheet "this is the excel sheet", "Tsteps", "TestSteps"
testcasecount = DataTable.GetSheet("TestCases").GetRowCount
For i = 1 To testcasecount
DataTable.GetSheet("TestCases").SetCurrentRow (i)
If DataTable.Value("Execution", "TestCases") = "Yes" Then
stestcaseid = DataTable.GetSheet("TestCases").GetParameter("TestCaseID")
teststepcount = DataTable.GetSheet("TestSteps").GetRowCount
For j = 1 To teststepcount
DataTable.GetSheet("TestSteps").SetCurrentRow (j)
sid = DataTable.GetSheet("TestSteps").GetParameter("TestCaseID")
If DataTable.GetSheet("TestSteps").GetParameter("TestCaseID") = stestcaseid Then
Select Case DataTable.Value("Keyword", "TestSteps")
Case Browser()
sresult = Browser()
End Select
DataTable.Value("Result", "TestSteps") = sresult
End If
If sresult = "Pass" Then
DataTable.Value("Result", "TestCases") = "Pass"
End If
Next
End If
Next
DataTable.ExportSheet "this is the excel sheet", "TestCases"
DataTable.ExportSheet "this is the excel sheet", "TestSteps"
Function Browser()
systemutil.Run "chrome.exe", "www.google.com"
Browser = "Pass"
End Function
I'm using the following script with a software which reads a CheckBox using OMR and outputs the data to an XML file.
Is there a way I can change it to say if more than one box has been checked, the data output should be the first checked box in the list?
Hope this makes sense.
Any help would be appreciated.
Dim installer
q_a1= Metadata.Values("OMR_FRED_P2")
q_a2= Metadata.Values("OMR_JON_P2")
q_a3= Metadata.Values("OMR_MATT_P2")
q_a4= Metadata.Values("OMR_STEVE_P2")
If q_a1 = "Filled" Then
installer = "Fred"
End If
If q_a2 = "Filled" then
installer = "Jon"
End If
If q_a3 = "Filled" then
installer = "Matt"
End If
If q_a4 = "Filled" then
installer = "Steve"
End If
call Metadata.SetValues("CompleteBy",installer)
You could do something like this:
Dim a1Checked, a2Checked, a3Checked, a4Checked
Dim numberOfChecked
a1Checked = (q_a1 = "Filled")
a2Checked = (q_a2 = "Filled")
a3Checked = (q_a3 = "Filled")
a4Checked = (q_a4 = "Filled")
numberOfChecked = Abs(a1Checked + a2Checked + a3Checked + a4Checked)
If a1Checked Or numberOfChecked > 1 Then
installer = "Fred"
ElseIf a2Checked Then
installer = "Jon"
ElseIf a3Checked Then
installer = "Matt"
ElseIf a4Checked Then
installer = "Steve"
Else
' Decide what you want to do if none is checked.
End If
Call Metadata.SetValues("CompleteBy", installer)
In VBScript, the numeric value of a "boolean true" value is -1 and of the false value is 0.
The above code simply adds the values together. If two conditions are met, the total would be -2, then we use the Abs function to get the abstract value (i.e., returning 2 instead of -2). After that, you can easily check if two or more conditions are met by using numberofChecked > 1.
I'm using Pervasive 9.2 and would like to somehow convert the vbscript into pervasives RIFL language. I want to execute the code during a Process where the f(x) component is executed to run the code. As far as the Path to the xml data, I'll be using a Macro defining where the source data is and another to save the file as well.
Here is the vbscript code below:
Set xml = CreateObject("Microsoft.XMLDOM")
xml.async = False
count_var = 1
If xml.Load("c:\folder1\test.xml") Then
For Each accounts In xml.SelectNodes("//Accounts")
For Each account In Accounts.SelectNodes("./Account")
If count_var > 1 Then
Set accountEnum = xml.createNode(1, "Account" & count_var, "")
For Each child In Account.childNodes
accountEnum.appendChild(child.cloneNode(TRUE))
Next
Accounts.replaceChild accountEnum, Account
xml.save("c:\folder1\test.xml")
else
Set accountEnum = xml.createNode(1, "Account" & count_var, "")
For Each child In Account.childNodes
accountEnum.appendChild(child.cloneNode(TRUE))
Next
Accounts.replaceChild accountEnum, Account
xml.save("c:\folder1\test.xml")
End If
count_var = count_var + 1
Next
count_var = 1
Next
End If
Set node = Nothing
Set xml = Nothing
ParseXMLFile(filepath)
documentation here
http://docs.pervasive.com/products/integration/di/rifl/wwhelp/wwhimpl/common/html/wwhelp.htm#href=ParseXMLFile_Function.html&single=true
this will return a DOMDocument Object Type
documentation here
http://docs.pervasive.com/products/integration/di/rifl/wwhelp/wwhimpl/common/html/wwhelp.htm#href=DOMDocument_Object_Type.html&single=true
hope this helps
I have no knowledge of VBScript and need help.
Logically - I thought of splitting it with # in a for loop and then using : to split again.
Example:
Text file:
a : 21312 # asdfasd23sad : 43624 # asdsad*:21
Excel file:
Function arr()
input = a : 21312 # asdfasd23sad : 43624 # asdsad*:21
arr1 = Split(input, "#")
For i = Lbound(arr1) To Ubound (arr1)
arr2 = Split(arr1(i),":")
For j = Lbound(arr2) To Ubound (arr2)
Msgbox arr2(j)
Next
Next
End function
I've created a function called EnergyPrice with the following code:
Here's the pricetable I'm looking up from
Prijstabel
fixed variable
Startdate Einddate gas electra gas electra
€/a €/a ct/KWh ct/KWh
1-1-2010 1-7-2010 181,00 235,00 0,11 0,33
1-7-2010 1-1-2011 362,00 470,00 0,33 1,30
1-1-2011 1-7-2011 191,00 245,00 0,22 0,65
1-7-2011 1-1-2012 162,35 208,25 0,19 0,55
1-1-2012 1-7-2012 324,70 416,50 0,37 1,11
And here's the relevant code
Public Enum Energietype
v_gas = 1
v_electricity = 2
End Enum
Public Enum FixedOrVariable
v_fixed = 1
v_variable = 2
End Enum
Public Function EnergyPrice(PriceDate As Date, E_type As Energietype, variabel As FixedOrVariable) As Variant
Dim PrijsTable As Range
Dim RowNr As Integer
Dim Found As Boolean
Dim KolomNr As Integer
Set PrijsTable = Range("EnergyPriceTable")
If PrijsTable.Columns.Count <> 6 Then Err.Raise Number:=vbObjectError + 1000, Description:="No valid valid pricetable defined"
RowNr = 1
Found = False
While Not (Found) And (RowNr <= PriceTable.Rows.Count)
Found = (PriceTable.Cells(RowNr, 1).Value <= PriceDate) And (PriceTable.Cells(RowNr, 2) > PriceDate)
If Not (Found) Then RowNr = RowNr + 1
Wend
If Found Then
If E_type = v_gas Then KolomNr = 1
If E_type = v_elektra Then KolomNr = 2
If variabel = v_variabel Then KolomNr = KolomNr * 2
KolomNr = KolomNr + 2
EnergyPrice = PriceTable.Cells(RowNr, KolomNr).Value
Else
EnergyPrice = Empty
End If
End Function
The question is how do I use the above enums in an Excel spreadsheet? So I can enter a formula like:
If I use the numbers 1,2 the functions works fine, but I want to use the enum names.
Can this be done using only Excel VBA?
If you add the enums to the workbook as defined names, you can pass them into functions and the value that is passed is the actual value you set the enum for. Do this manually or via VBA if you prefer.
Example:
ActiveWorkbook.Names.Add Name:="v_gas", RefersToR1C1:="=1"
ActiveWorkbook.Names.Add Name:="v_fixed", RefersToR1C1:="=2"
The only way I see, is by defining Names in your workbook, assigning them the constants of your Enums.
From the menu: Insert ... Name .... Define
Name: v_gas
Refers to: =1
Alternatively, you could create those names by VBA, but that has no interest, since it will be a 1 shot (names are saved with the workbook).
By using such names, the users will be able to use F3 while entering the formula.