Created On:  19 August 2010
 
A SAPMenu is shown here:



In order to return the value for the Selected Node "Telephone Integration" you could use the following code called against the SAPMenu.

 [ ] STRING lvs_SelectedNodeKey, lvs_SelectedItemText, lvs_SelectedNodePath, lvs_SelectedNodePathConvert
 [ ]
 [ ] lvs_SelectedNodeKey = Desktop.Find("/SapWindow[@automationId='/app/con[0]/ses[0]/wnd[0]']//SapTree[@automationId='usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell']").GetProperty("SelectedItemNode")
 [ ] lvs_SelectedNodePath = Desktop.Find("/SapWindow[@automationId='/app/con[0]/ses[0]/wnd[0]']//SapTree[@automationId='usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell']").GetNodePathByKey( lvs_SelectedNodeKey )
 [ ] lvs_SelectedItemText = Desktop.Find("/SapWindow[@automationId='/app/con[0]/ses[0]/wnd[0]']//SapTree[@automationId='usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell']").GetNodeTextByPath( lvs_SelectedNodePath )
 [ ]
 [ ] print(lvs_SelectedNodeKey)
 [ ] print(lvs_SelectedNodePath)
 [ ] print(lvs_SelectedItemText)

This code returns the following result:

[-] Testcase SAPMenuTest - Passed
 [ ] 0000000005
 [ ] 2\1\2
 [ ] SAP menu

This result is incorrect as it has returned "SAPMenu" instead of "Telephone Integration". The reason for this incorrect result is due to the method GetNodePathByKey() returning a result in the format "2\1\2". This causes problems when that value is then passed into the method GetNodeTextByPath() as it requires the input to be in the format "2/1/2". The problem here is the use of backslashes instead of forwardslashes.

This has been identified as a problem within the SAP automation itself. This can be seen if you use the internal SAP Record and Playback functionality. This uses VBS scripts to call the SAP automation. To test this record a simple script and then edit the .vbs file to include the following lines of code entering the relevant NodeID for your tests in the first line:

MsgBox (session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").getNodePathByKey("0000000005"))
MsgBox (session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").getNodeTextByPath("2\1\2"))
MsgBox (session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").getNodeTextByPath("2/1/2"))

The result of this will display 3 message boxes as shown below:


This message box shows the same path as is returned by SilkTest.


This message box shows the same incorrect result as in SilkTest.



This message box shows the correct result because forwardslashes are now used in the path.
 
As this is an issue in the SAP automation itself it cannot be directly resolved on the SilkTest side. However, it is possible to create a workaround by writing a custom function to replace the "\" characters with a "/" in the returned path. Such a function is as follows:

[-] STRING PathConvert(STRING lvs_SelectedNodePath)
 [ ] STRING lvs_SelectedNodePathConvert
 [ ] lvs_SelectedNodePathConvert = StrTran (lvs_SelectedNodePath, "\", "/" )
 [ ] return lvs_SelectedNodePathConvert

Then include this function in your code as follows:

 [ ] STRING lvs_SelectedNodeKey, lvs_SelectedItemText, lvs_SelectedNodePath, lvs_SelectedNodePathConvert
 [ ]
 [ ] lvs_SelectedNodeKey = Desktop.Find("/SapWindow[@automationId='/app/con[0]/ses[0]/wnd[0]']//SapTree[@automationId='usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell']").GetProperty("SelectedItemNode")
 [ ] lvs_SelectedNodePath = Desktop.Find("/SapWindow[@automationId='/app/con[0]/ses[0]/wnd[0]']//SapTree[@automationId='usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell']").GetNodePathByKey( lvs_SelectedNodeKey )
 [ ] lvs_SelectedNodePathConvert = PathConvert(lvs_SelectedNodePath)
 [ ] lvs_SelectedItemText = Desktop.Find("/SapWindow[@automationId='/app/con[0]/ses[0]/wnd[0]']//SapTree[@automationId='usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell']").GetNodeTextByPath( lvs_SelectedNodePathConvert )
 [ ]
 [ ] print(lvs_SelectedNodeKey)
 [ ] print(lvs_SelectedNodePathConvert)
 [ ] print(lvs_SelectedItemText)

When this code is executed you get the following result:

[-] Testcase SAPMenuTest - Passed
 [ ] 0000000005
 [ ] 2/1/2
 [ ] Telephone Integration

This is now returning the expected result.
Incident #2471239