on ‎2020 Oct 30 9:36 AM
Hello,
I have created a custom VBScript which records the SAP GUI user actions, and saves them into a JSON file in a given format (that I use in another completely different custom program).
I'd like to write automatic tests to make sure there's no regression in the future, but I don't know if it's possible the way I think.
My idea is to:
I didn't try to do it yet, but I'm suspicious about the possibility of play and record at the same time (I fear that the same session cannot be locked by two processes "play" and "record" at the same time).
Did somebody tried that already?
Thanks a lot.
Sandra
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
Okay, "play and record" at the same time works. CC daniel_mccollum.
For information, my test VBScript that I debug at line "WScript.Quit 0" (dummy line) to watch the global variable "command":
Dim command
Call Main
WScript.Quit 0
Sub Main()
If Not IsObject(oApplication) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set oApplication = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = oApplication.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject oApplication, "on"
End If
session.findById("wnd[0]").resizeWorkingPane 174,35,false
command = "[ {}" & chr(10)
Call WScript.ConnectObject(session,"sess")
session.record = True
session.findById("wnd[0]/tbar[0]/okcd").text = "/NSE38"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRS38M-PROGRAMM").text = "SAPCOLUMN_TREE_CONTROL_DEMO"
session.findById("wnd[0]/usr/ctxtRS38M-PROGRAMM").caretPosition = 27
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]/usr/cntlTREE_CONTAINER/shellcont/shell").selectItem "Child1","Column2"
session.findById("wnd[0]/usr/cntlTREE_CONTAINER/shellcont/shell").ensureVisibleHorizontalItem "Child1","Column2"
session.findById("wnd[0]/usr/cntlTREE_CONTAINER/shellcont/shell").pressButton "Child1","Column2"
Call WScript.DisconnectObject(Session)
session.record = False
command = command & "]" & chr(10)
End Sub
Sub sessChange(Session, Component, CommandArray)
If Component Is Nothing Then
' Create Session
Exit Sub
End if
length = 0
For i = 0 To UBound(CommandArray)
commandargument = getCommandArgument(CommandArray,i)
componentType = getComponentType(component)
command = command & ", { ""stepType"":""userCommand""" & ", ""userCommand"":" & jv(commandarray(i)(0) & ":" & commandarray(i)(1)) & ", ""componentType"":" & jv(getComponentType(Component))
command = command & ", ""commandType"":""" & commandarray(i)(0) & "/" & componentType & "/" & commandarray(i)(1) & """ }" & chr(10)
Next
End Sub
Function getCommandArgument(commandarray,i)
On Error Resume Next
lastIndex = UBound(commandarray(i))
commandargument = ""
If Err.Number <> 0 Then
commandargument = commandargument & "ERR! " & Typename(commandarray)
Exit Function
End If
commandargument = ""
For j = 2 To lastIndex
Err.Clear
commandargument = commandargument & commandarray(i)(j) & ","
If Err.Number <> 0 Then
commandargument = commandargument & "ERR! " & Typename(commandarray(i)(j)) & ","
End If
Next
getCommandArgument = commandargument
End Function
Function getComponentType(component)
If component.type = "GuiShell" Then
componentType = component.SubType
ElseIf left(component.type,3) = "Gui" Then
' Gui should always be the first three characters
componentType = Mid(component.type,4)
Else
' Unexpected situation, keep the component type.
componentType = component.type
End If
' First letter lower case, except if second letter is upper case
If Mid(componentType,2,1) = LCase(Mid(componentType,2,1)) Then
getComponentType = LCase(Left(componentType,1)) & Mid(componentType,2)
Else
getComponentType = componentType
End If
End Function
Function jv(value)
jv = """" & replace(replace(replace(replace(replace(replace(value, "\", "\\"),"""","\"""),"/","\/"),chr(10),"\n"),chr(13),"\r"),chr(9),"\t") & """"
end function
And so, now, if I write the variable "command" (JSON) to a file and I create a VBScript which reads the JSON file and converts it into SAP GUI Scripting commands, and records the screens at the same time, it should detect any regression in the recorder.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.