automated-testssap-guisilktest

How to get function codes for SAP GUI context menus?


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

Now I want to simulate a click onto one of the context menu items. It seems that this can be done with SapTree.selectContextMenuItem(). However, this function needs a function code.

How do I get a list of function codes that are available on the context menu?

I have tried SapTree.selectContextMenuItemByText() but that resulted in the 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 have also tried SapContextMenu.select(), but there is no parameter to that method, so I wonder which item it will select.


Solution

  • Using SAP Script Recorder

    One way of getting the function code is to record the action with the SAP Script Recording and Playback (screenshot 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're looking for.

    Using Silk4J

    Context menus in SAP are a collection of context menus. This could explain the select() method without parameters. That probably works well on leaf context menu items.

    To dump all function codes programatically, you can use the function getName() and call it on all context menus. getText() gets the 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
        }                                                        
    }