FindActivePopup does not work for cascade JPopupMenu with JMenu cascading items

50 views
Skip to first unread message

dav...@sympatico.ca

unread,
Jan 29, 2013, 6:14:45 AM1/29/13
to easyt...@googlegroups.com
When I test using findActivePopup I found that JPopupMenu with a cascade menu fails to found a popup.
 
On investigation (using FEST-Swing source code and debug via eclipse) the method private JPopupMenu activePopupMenu()  of BasicRobot.java was doing a finder action and the found List<Component> structure had more than one item (JPopupMenu, JMenu). Thus the test for found.size() == 1 was failing. Changing the test to >= 1 resolved the problem.
 
Any chance this can be put into the new release of FEST-Swing?
 
 
Below is the code and a JUnit test for testing with a cascade.
 
BasicRobot.java
==========
  @RunsInEDT
  private JPopupMenu activePopupMenu() {
    List<Component> found = new ArrayList<Component>(finder().findAll(POPUP_MATCHER));
    if (found.size() == 1) return (JPopupMenu)found.get(0);
    return null;
  }
 
 
advise to change to >= from == as the finder seems to find additional cascade jmenu in the array too
 
@RunsInEDT
private JPopupMenu activePopupMenu() {
List<Component> found = new ArrayList<Component>(finder().findAll(POPUP_MATCHER));
if (found.size() >= 1) return (JPopupMenu)found.get(0);
return null;
}
 
 
BasicRobot_findActivePopupMenu_Test.java
===================================
  @RunsInEDT
    final JPopupMenu addPopupMenuToTextFieldWithCascade() {
      return createAndSetPopupMenuWithCascade(window.textField, "Luke", "Leia");
    }
  
   @RunsInEDT
    public static JPopupMenu createAndSetPopupMenuWithCascade(final JComponent c, final String...items) {
      return execute(new GuiQuery<JPopupMenu>() {
        @Override protected JPopupMenu executeInEDT() {
          JPopupMenu popupMenu = new JPopupMenu();
         
          JMenu menu2 = new JMenu("cascade test");
          menu2.add(new JMenuItem("cascade line 1"));
          menu2.add(new JMenuItem("cascade line 2"));
         
          popupMenu.add(menu2);
          popupMenu.add(new JMenuItem(items[0]));
          popupMenu.add(menu2);
          popupMenu.add(new JMenuItem(items[1]));
         
          c.setComponentPopupMenu(popupMenu); // causes popup-menu to display
          return popupMenu;
        }
      });
    }
 
  @Test
  public void should_return_active_popupMenu_cascadingPopup() {
    addPopupMenuToTextFieldWithCascade();
    robot.showPopupMenu(window.textField);
   
    // wait for 2nd cascade menu to show
    pause(1000);
   
    JPopupMenu found = robot.findActivePopupMenu();
    MenuElement[] meArr = found.getSubElements();
   
    Component comp = meArr[0].getComponent();
 
    assertThat("cascade line 1").isEqualTo(((JMenuItem)comp).getText());
  }

Alex Ruiz

unread,
Jan 29, 2013, 9:29:08 AM1/29/13
to easytesting
Please file a bug in our github repo with info, and I'll include a fix in the next release. I'm working hard to get it out by next month (fingers crossed) :)

Cheers,
-Alex


--
You received this message because you are subscribed to the Google Groups "easytesting" group.
To unsubscribe from this group and stop receiving emails from it, send an email to easytesting...@googlegroups.com.
To post to this group, send email to easyt...@googlegroups.com.
Visit this group at http://groups.google.com/group/easytesting?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages