Executing the test cases in alm from Excel by Test ID - excel

I am trying to execute the test cases in QC ALM through an Excel macro. I am able to access the tests in testlist, but I am not able to find the particular test case I need to execute by its ID.
Below is the sample code I am using:
Set tsTreeMgr = tdConnection.testsettreemanager
Set tsFolder = tsTreeMgr.NodeByPath(nPath)
' --Search for the test set passed as an argument to the example code
Set tsList = tsFolder.FindTestSets("Test Set Name")
'------Accessing the Test Cases inside the Test SEt ----
Set theTestSet = tsList.Item(1)
For Each testsetfound In tsList
Set tsFolder = testsetfound.TestSetFolder
Set tsTestFactory = testsetfound.tsTestFactory
Set tsTestList = tsTestFactory.NewList("")
For Each tsTest In tsTestList
MsgBox (tsTest.Name+","+ tsTest.ID)
testrunname = "Test Case name from excel sheet"
'----Accesssing the Run Factory ---
Set RunFactory = tsTest.RunFactory
Set obj_theRun = RunFactory.AddItem(CStr(testrunname))
obj_theRun.Status = "Passed"
obj_theRun.Post
Next
Next
Any help to get TestCase in testset of testlab to execute would be great help.

I think you are looking for the TestId property of the TSTest object. So in your loop you could just test whether TestId matches the value from Excel:
If tsTest.TestId = testidfromexcel Then
' do something
End If
Or you can use a Filter to only get the TSTest instances from your Test Set that matches the respective test ID from Excel:
Set testSetFilter = tsTestFactory.Filter
testSetFilter.Filter("TC_TEST_ID") = testidfromexcel
Set tsTestList = testSetFilter.NewList()
Now your tsTestList should only contain test instances from the test with the ID from Excel.

Related

Wildcards/patterns with .Tables("PARA") when executing RFC INST_EXECUTE_REPORT

I'm using Excel and VBA to get SAP to download data from SAP through RFC using INST_EXECUTE_REPORT.
It works like a charm when I have specific input parameters. I just build up .Tables("PARA") with the screen name of the parameter and the desired value. I can even use this method for date ranges.
The challenge is when I don't know exactly the input parameters. For example, I wanted to identify all internal orders with a specific text in the description, e.g. CODE40.
Is there any way to use wildcards with INST_EXECUTE_REPORT? When the program passed into INST_EXECUTE_REPORT is executed normally as a transaction on screen, I can set the parameter to *CODE40* and SAP automatically applies a wildcard search. But I can't get that to work with VBA.
I can simulate using wildcards when accessing individual tables with BBP_RFC_READ_TABLE by using LIKE statements in the selection option, but I need a similar functionality for whole reports, not individual tables.
Can anyone help?
Best regards,
The code I'm using is as follows:
Set ObjR3_EXECUTE_REPORT = ObjR3.Add("INST_EXECUTE_REPORT")
With ObjR3_EXECUTE_REPORT
Set ObjR3_EXECUTE_REPORT_Name = .Exports("PROGRAM")
Set ObjR3_EXECUTE_REPORT_Para = .Tables("PARA")
Set ObjR3_EXECUTE_REPORT_Result = .Tables("RESULT_TAB")
Set ObjR3_EXECUTE_REPORT_Output = .Tables("OUTPUT_TAB")
End With
ObjR3_EXECUTE_REPORT_Name.Value = ReportName
'Build up the table with the fields to be selected
f = 1
For a = LBound(aParameters) To UBound(aParameters)
aParameterPair = aParameters(a)
aParameterInput = aParameterPair(UBound(aParameterPair))
sParameterName = aParameterPair(LBound(aParameterPair))
For c = LBound(aParameterInput) To UBound(aParameterInput)
sParameterInput = aParameterInput(c)
ObjR3_EXECUTE_REPORT_Para.AppendRow
ObjR3_EXECUTE_REPORT_Para(f, "PARA_NAME") = sParameterName
ObjR3_EXECUTE_REPORT_Para(f, "PARA_VALUE") = sParameterInput
Debug.Print sParameterName & " " & sParameterInput
f = f + 1
Next c
Next a

New Defect from Excecution Grid when Status is changed to failed

I want to open the Defect Window from the TestSet's Execution Grid when the "TC_STATUS" is "failed"
The following code seems only to work when I perform a "full" run
Actions.Action("Defects.NewDefect").Execute
or
Actions.Action("StepsView.NewDefect").Execute
I already tried:
Actions.Action("TestSetView.NewDefect").Execute
but this does nothing
You can post a new defect automatically each time test instance status is changed and link this new defect to currently selected test instance.
In Test Lab module script workflow put this code:
Sub TestSetTests_FieldChange(FieldName)
On Error Resume Next
If FieldName = "TC_STATUS" and TestSetTest_Fields.Field("TC_STATUS").Value = "Failed" Then
Set BugFact = TDConnection.BugFactory
Set NewBug = BugFact.AddItem(null)
'Fill new defect fields
NewBug.Summary = "New Defect"
NewBug.Field("BG_SEVERITY") = "3-High"
NewBug.Field("BG_STATUS") = "New"
NewBug.Field("BG_DETECTION_DATE") = "2016-01-01"
'...
NewBug.Post()
TestInstanceId = TestSetTest_Fields.Field("TC_TESTCYCL_ID").Value
Set TestInstanceFact = TDConnection.TSTestFactory
Set TestInstance = TestInstanceFact.Item(TestInstanceId)
Set NewBugLinkFact = TestInstance.BugLinkFactory
Set NewBugLink = NewBugLinkFact.AddItem(null)
NewBugLink.TargetEntity = NewBug
NewBugLink.Post
End If
On Error GoTo 0
End Sub
Or if you are working with ALM 12.53, you can try executing masthead "New Defect" action available from all modules.
Actions.Action("HeaderActions.HeaderNewDefect").Execute

SAPgui script with variables values from Excel

I need to populate dates on fields in SAP which if manually entered is properly captured by the script recorder.
Is it possible to update the script dates using a cell link in Excel?
session.findById("wnd[0]/usr/ctxtLKO74-PERIO").Text = "2"
session.findById("wnd[0]/usr/ctxtLKO74-BUPERIO").Text = "2"
session.findById("wnd[0]/usr/txtLKO74-GJAHR").Text = "2016"
session.findById("wnd[0]/usr/ctxtLKO74-BZDAT").Text = "29.02.2016"
I plan to copy the recorded SAP script and incorporate it in an Excel macro as a button.
You may try like this:
Set app = CreateObject("Excel.Application")
Set wbook = app.Workbooks.Open("c:\tmp\prices.xls")
set sheet = wbook.Sheets("Tabelle1")
session.findById("wnd[0]/usr/ctxtLKO74-PERIO").Text = sheet.Cells(1,2).Value
session.findById("wnd[0]/usr/ctxtLKO74-BUPERIO").Text = sheet.Cells(1,3).Value
session.findById("wnd[0]/usr/txtLKO74-GJAHR").Text = sheet.Cells(1,4).Value
session.findById("wnd[0]/usr/ctxtLKO74-BZDAT").Text = sheet.Cells(1,5).Value
Get App object, then get workbook and worksheet objects, and then assign your script cell values.
Everything is well discussed here including all the comments asking for different scenarios. https://scn.sap.com/thread/1699675

Running the test cases in ALM 12.01 version using groovy script

I am working on updating the test results in test lab of ALM 12.01 version from soapui pro.so i am doing this through groovy scripting. I can now filter the test case and make it passed or failed,but could not do the same for test steps.have used step factory to get the count of nodes. but i have no idea of using run factory for updating each field in test step like 'status','actual results'.below is the part of code i m stuck with.
// Create a new Test Run
newRun= tsfact.RunFactory.AddItem('Run_Auto')
newRun.Status = 'Passed'
newRun.Post()
newRun.CopyDesignSteps()
newRun.Post()
// Populate Auto Run Test step Data
tsSteps = newRun.StepFactory.NewList("")
log.info tsSteps.count()
for(tsStep in tsSteps)
{
tsStep.Status = 'Passed'
}
My script is from the opposite side but i think it should work.
I run soapui test from ALM 11.
There is my vb script to populate ALM teststeps from soap ui teststep.
For each step, i call this function, juste replace my stepFactory currentRun by your variable newRun
Sub addRunData(CurrentRun, sStepName, sStatus, sDescription, sExpected, sActual )
Dim objRun
Set objRun = CurrentRun
//Create Step object and add values to Object array
Set objStep = objRun.StepFactory.AddItem(null)
objStep.Field("ST_STEP_NAME")= sStepName
objStep.Field("ST_STATUS") = sStatus
objStep.Field("ST_DESCRIPTION") = sDescription
objStep.Field("ST_EXPECTED") = sExpected
objStep.Field("ST_ACTUAL") = sActual
objStep.Post
Set objStep = Nothing
end sub
You can insert expected and actual value with assertions or messages from your request for example

Export SQL query results into a multi tabbed Excel spreadsheet

I want to write a set of 100 select queries in DB2 10.1 to return all rows in each table in the database and have the results exported to an excel spreadsheet with a new tab for each result set.
Is this possible and if so how can I do it?
At the moment the only way I can do this looks like to export each result set and then manually create the multi tabbed spreadsheet by copying each tab across.
Thanks
You can use EasyXLS API for Excel with scripting languages like VB Script.
The VBS code should be similar with this one:
'The class that exports result set to Excel file
Set xls = CreateObject("EasyXLS.ExcelDocument")
' The class used to format the cells
Dim xlsAutoFormat
set xlsAutoFormat = CreateObject("EasyXLS.ExcelAutoFormat")
xlsAutoFormat.InitAs(AUTOFORMAT_EASYXLS1)
For query = 1 To 100
' Add a new sheet
xls.easy_addWorksheet_2("Sheet" & query)
set xlsSheet = xls.easy_getSheetAt(query - 1)
' Create the record set object
Dim objResultSet
Set objResultSet = CreateObject("ADODB.Recordset")
objResultSet.Open queryString, objDBConnection
' Create the list that will store the values of the result set
Dim lstRows
Set lstRows = CreateObject("EasyXLS.Util.List")
' Add the header to the list
Dim lstHeaderRow
Set lstHeaderRow = CreateObject("EasyXLS.Util.List")
lstHeaderRow.addElement("Column 1")
lstHeaderRow.addElement("Column 2")
lstHeaderRow.addElement("Column 3")
lstRows.addElement(lstHeaderRow)
' Add the values from the database to the list
Do Until objResultSet.EOF = True
set RowList = CreateObject("EasyXLS.Util.List")
RowList.addElement("" & objResultSet("Column 1"))
RowList.addElement("" & objResultSet("Column 2"))
RowList.addElement("" & objResultSet("Column 3"))
lstRows.addElement(RowList)
' Move to the next record
objResultSet.MoveNext
Loop
xlsSheet.easy_insertList_2 lstRows, xlsAutoFormat
Next
' Export result sets to Excel file
xls.easy_WriteXLSFile("c:\Result sets.xls")
Check also this link about exporting lists of data to Excel.
If you will choose a non scripting language, the API has methods that insert data directly from the result set and the lists can be skiped. Check another sample here.

Resources