Quantcast
Channel: Silk Test Knowledge Base
Viewing all articles
Browse latest Browse all 105

Determining the menu names and item texts of a SapContextMenu

$
0
0
Revision 1 posted to Silk Test Knowledge Base by RobertM on 5/25/2015 9:04:00 AM

When automating a SAP application, during which you must interact with a SapContextMenu, it is not possible to identify SapContextMenu controls or their menu items using the Locator Spy. This can make it difficult to determine what names and item texts have been associated with each SapContextMenu, in the event that this information must be verified. Currently it is only possible to retrieve the names and item texts of any menu item belonging to a SapContextMenu programmatically. 

When exploring how a SapContextMenu is constructed from a control perspective, it is found that each menu item in a SapContextMenu control, is actually another SapContextMenu control. Therefore with this information it is possible to script some logic that will:

  1. Find a SapContextMenu that contains 1 or more child controls
  2. Iterate through those child controls and print the name and text information for those controls


For example, to retrieve the names and item texts that belong to a SapContextMenu accessed via a tree node from a SapTree, the following Silk4J helper method can be used:


public
void
discoverMenuNamesAndText(Desktop desktop, SapTree tree, String sNodeKey){

     tree.nodeContextMenu(sNodeKey);
     List<SapContextMenu> wins = desktop.findAll("//SapContextMenu");
     for(SapContextMenu win:wins){
          if(win.getChildren().size()>0){
               System.out.println("Parent Context Menu");

               List<TestObject> items = win.getChildren();
               for(TestObject item:items){
                    if(!((SapContextMenu)item).getName().equals("")){
                         System.out.println(" Name: "+((SapContextMenu)item).getName());
                         System.out.println(" Item Text: "+((SapContextMenu)item).getText()+"\n");
                    }
               }
          }
     }
}

 

The above method can then be used as follows:

SapTree tree desktop.<SapTree>find("//SapTree");
discoverMenuNamesAndText(desktoptree"F00005");


When executed, output similar to the following can be found in the console:

Parent Context Menu
          Name: XXEXEN
          Item Text: Execute in new window

          Name: XXECK1
          Item Text: Display documentation

          Name: XXAEND
          Item Text: Change favorite

          Name: XXECK2
          Item Text: Saved lists

Tags: SapTree, SapContextMenu, SAP, silk4j

Viewing all articles
Browse latest Browse all 105

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>