New Defect from Excecution Grid when Status is changed to failed - alm

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

Related

Macro won't run in my latest system(capturing data)

I have 2 macro version code that runs in old version of PCOMM System(capturing data). However After the update of latest PCOMM System(Capturing data). My macro will run as "Macro run complete" but the data didn't reflect in excel.
Here's my Version 1 My code can't capture data in my new latest PCOMM system(capturing data site) However macro says "Macro Run Complete!" to get the data. Show images and sample code below
Public Function Extra_Init() As Boolean On Error
GoTo ExitExtraInit
Extra_Init = False
Set goExtraSys = CreateObject("PCOMM.autECLConnList")
goExtraSys.Refresh
Set goSessions = CreateObject("PCOMM.autECLOIA")
goSessions.SetConnectionByHandle (goExtraSys(1).Handle)
giSessionCount = goExtraSys.Count
If giSessionCount = 1 Then
Set goSession = CreateObject("PCOMM.autECLPS")
goSession.SetConnectionByHandle (goExtraSys(1).Handle)
If goSession.CommStarted Then
Extra_Init = True
Else
Extra_Init = False
End If
End If
Exit Function
Here's my Version 2 My Microsoft Visual Basic when being run, an error prompts showing "class not registered"
Sample images below.
Error appears in this part of code.
Set Exl = GetObject(, "Excel.Application")
Set Extra = CreateObject("PCOMM.autECLConnList")
Extra.Refresh
Thank you in advance!
Get the data in my latest version of PCOMM System

VBA Run-time error '380': A script engine for the specified language can not be created

This is more of general question, I suppose, as-well-as help with a specific line of code.
I have an Excel file that I was working on just a few days ago that was working fine, however now whenever I try to run the macro in the workbook to pull data from a website, I receive the error "Run-time error '380': A script engine for the specified language can not be created."
Here is the code block where I am running into the issue. I have starred the specific section where the error is thrown.
Dim H As Object, S As Object, jParse As Object, X64 As Object, i&
Set H = CreateObject("WinHTTP.WinHTTPRequest.5.1")
H.SetAutoLogonPolicy 0
#If Win64 Then
Set X64 = x64Solution()
X64.execScript "Function CreateObjectx86(sProgID) Set CreateObjectx86 = CreateObject(sProgID): End Function", "VBScript"
Set S = X64.CreateObjectx86("MSScriptControl.ScriptControl")
#Else
Set S = CreateObject("ScriptControl")
#End If
***S.Language = "JScript"***
S.AddCode "function keys(O) { var k = new Array(); for (var x in O) { k.push(x); } return k; } "
I have never seen this error before and I am not sure how to fix this issue. I have looked online and have thus far been unsuccessful in figuring out the problem. I have also tried downloading and installing the zip file from Microsoft in this link: https://gallery.technet.microsoft.com/scriptcenter/Registry-key-to-re-enable-835fba77 with no success.
Any help would be appreciated, because I really don't know what to do here.
Also if Stack Overflow is not really the place for this kind of question, any help in directing me somewhere that would be better suited for this kind of problem would be appreciated.
I just had a similar encounter attempting to use JScript to parse some JSON from the SO API using a x64 machine.
Disclaimer: I did not author the following procedures, but unfortunately I do not have the source of where I obtained them either.
As you've probably already figured out, MSScriptControl.ScriptControl doesn't like the x64 architecture very well. Here are a couple of functions that will allow you to do what you need.
I placed these in a separate module:
Public Function CreateObjectx86(Optional sProgID, Optional bClose = False)
Static oWnd As Object
Dim bRunning As Boolean
#If Win64 Then
bRunning = InStr(TypeName(oWnd), "HTMLWindow") > 0
If bClose Then
If bRunning Then oWnd.Close
Exit Function
End If
If Not bRunning Then
Set oWnd = CreateWindow()
oWnd.execScript "Function CreateObjectx86(sProgID): Set CreateObjectx86 = CreateObject(sProgID): End Function", "VBScript"
End If
Set CreateObjectx86 = oWnd.CreateObjectx86(sProgID)
#Else
Set CreateObjectx86 = CreateObject(sProgID)
#End If
End Function
Private Function CreateWindow()
Dim sSignature, oShellWnd, oProc
On Error Resume Next
sSignature = Left(CreateObject("Scriptlet.TypeLib").GUID, 38)
CreateObject("WScript.Shell").Run "%systemroot%\syswow64\mshta.exe about:""about:<head><script>moveTo(-32000,-32000);document.title='x86Host'</script><hta:application showintaskbar=no /><object id='shell' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shell.putproperty('" & sSignature & "',document.parentWindow);</script></head>""", 0, False
Do
For Each oShellWnd In CreateObject("Shell.Application").Windows
Set CreateWindow = oShellWnd.GetProperty(sSignature)
If Err.Number = 0 Then Exit Function
Err.Clear
Next
Loop
End Function
Then you can go back to your S object and set it this way:
Dim S As Object
Set S = CreateObjectx86("MSScriptControl.ScriptControl")
S.Language = "JScript"

How to access SAP using Excel VBA?

I am trying to log on to SAP. The Excel VBA code gives me a popup window confirming my information however when I submit the form it does not take me to a new SAP window.
Additionally is there a way to automate all the popup boxes asking for confirmation on my information? I want this code eventually to run at certain times of the day, and I might not be available to input any data.
Sub login1()
Dim sap As Object
Dim conn As Object
Set sap = CreateObject("SAP.Functions")
Set conn = sap.Connection
conn.System = "System Test Environment"
conn.client = "100"
conn.user = "user"
conn.Password = "password"
conn.Language = "EN"
If conn.logon(0, False) <> True Then
MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"
Else
End If
End Sub
This Macro will never open a SAP Window - it will create an SAP-Object within VBA where you can work with SAP-RFC-Functions. (Reading Data from SAP, Writing Data into SAP)
In your version the SAP connection will be unaccessible after "End Sub". You have to declair the Object outside the sub.
This works silent (without dialog) for me:
Dim sap As Object
Public Function login1() As Boolean
Set sap = CreateObject("SAP.Functions")
sap.Connection.System = "System Test Environment"
sap.Connection.client = "100"
sap.Connection.user = "user"
sap.Connection.Password = "password"
sap.Connection.Language = "EN"
If sap.Connection.logon(0, False) <> True Then
sap.RemoveAll
MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"
Else
login1 = true
End If
End Function
Public Function SAPLogoff()
On Error Resume Next
sap.RemoveAll
sap.Connection.logoff
LoggedOn = False
Set sap = Nothing
'Set conn = Nothing
End Function
Since you want to "open a new SAP Window" you have to make a different approach!
At First try to open the new instance of SAP from the DOS Commandline with "sapshcut":
C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapshcut.exe -system="System Test Environment" -client="100" -user="user" -password="password" -language="EN"
If your SystemName has no Spaces (and I belive so!) then you can write it also like:
C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapshcut.exe -system=SystemTestEnvironment -client=100 -user=user -password=password -language=EN
When this call works with your credentials, then you can transfer it to Excel like this:
Sub login1()
Call Shell("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapshcut.exe -system=SystemTestEnvironment -client=100 -user=user -password=password -language=EN",vbNormalFocus)
End Sub
You could also add a transaction by adding "-command=your_tcode" to the String.
If your have spaces in the parameters and you could only start it with -system="System Test Environment" from the Commanline, you will have to escape this in Excel with -system="""System Test Environment""" (!)

Executing the test cases in alm from Excel by Test ID

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.

Excel VBA: Adding objects to a collection within a class

I am trying to create a class (named ClassSection) that contains a collection (named DefectCollection). It needs a function to add items to that collection but I'm having trouble making it work. I get Error 91 "Object variable or with block variable not set."
I have looked at the other answers on here, which is what got me this far, but I don't understand what I'm missing.
Here is the class module code:
Public DefectCollection As Collection
Private Sub Class_Initialise()
Set DefectCollection = New Collection
End Sub
Public Function AddDefect(ByRef defect As CDefect)
DefectCollection.Add defect [<---- error 91]
End Function
And here is the code that calls the function: ('defect' is another class, which works fine - I want each 'ClassSection' to be able to hold an unlimited number of 'defects')
Dim SC As Collection
Dim section As ClassSection
Set SC = New Collection
Dim SurveyLength As Double
For Each defect In DC
SurveyLength = WorksheetFunction.Max(SurveyLength, defect.Pos, defect.EndPos)
Next defect
SurveyLength = Int(SurveyLength)
For i = 0 To numSurveys
For j = 0 To SurveyLength
Set section = New ClassSection
section.ID = CStr(j & "-" & dates(i))
SC.Add Item:=section, Key:=section.ID
Next j
Next i
Dim meterage As Double
For Each defect In DC
meterage = Int(defect.Pos)
Set section = SC.Item(meterage & "-" & defect.SurveyDate)
section.AddDefect defect
Next defect
Thanks!
You get the error because the DefectCollection is Nothing. This is due to the fact that you mispelled the initalization method:
Private Sub Class_Initialise() '<-- it's with "Z", not "S"
Hence, the initialization of the class is never called, the object remain Nothing by default and the method fails when trying to add an object to Nothing

Resources