How to get function codes for SAP context menus?

I am automating tests of our SAP application using Silk4J (16.0.1.7470). There is a tree where I selected node. I can open the SapTree.nodeContextMenu () context menu .

Now I want to simulate a click on one of the context menu items. It looks like it can be done with SapTree.selectContextMenuItem () . However, this function requires a function code.

How do I get a list of the function codes available in the context menu?

I tried SapTree.selectContextMenuItemByText () but it resulted in an exception.

java.lang.RuntimeException: Error executing 'SelectContextMenuItemByText'. An unexpected COM exception occurred at SAP Frontend Server (The method got an invalid argument.). .
at com.borland.silktest.jtf.internal.Agent.convertException(Agent.java:294)
at com.borland.silktest.jtf.internal.Agent.invoke(Agent.java:394)
at com.borland.silktest.jtf.AbstractTestObject.invoke(AbstractTestObject.java:462)
at com.microfocus.silktest.jtf.sap.SapTree.selectContextMenuItemByText(SapTree.java:1650)
...

      

I also tried SapContextMenu.select () , but there is no parameter for this method, so I wonder which item it will select.

+3


source to share


1 answer


Using SAP Script Recorder

One way to get the function code is to record the action using SAP Script Record and Playback (screen shot in German).

SAP Script Recording and Playback

Open the recorded Script in Notepad and find the action

session.findById(...).selectContextMenuItem "DELETE_RELATION"

      



"DELETE_RELATION"

is the function code you are looking for.

Using Silk4J

Context menus in SAP are a collection of context menus. This might explain the select()

parameterless method . This probably works well in leaf menu items.

To reset all function codes programmatically, you can use the getName () function and call it on all context menus. getText()

gets human readable text.

List<SapContextMenu> menus = tree.getDesktop().findAll("//SapContextMenu");
for(SapContextMenu menu:menus){
    try{
        logger.debug("Function code: "+menu.getName());
        logger.debug("Displayed text: "+menu.getText());
        logger.debug("");
    }
    catch(Exception e){
        logger.debug(e); // Didn't happen for me
    }                                                        
}

      

+3


source







All Articles