benjamin84 / fest

Automatically exported from code.google.com/p/fest
0 stars 0 forks source link

Popup menu with separator has problem? #199

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
From Sachin Siddhaye:

I have a JPopupMenu which has five menu items. The first three are
radiobuttonmenuitems, then there is a separator, then there are two
regular JMenuItems.

This popup is shown when I double-click on a JLabel instance. I am
testing two use-cases in a single FEST test.
First, I double-click on the JLable, which displays the popup menu. I
select one of the three radiobuttons and click "somewhere else" to
dismiss the popup. The code that does all of the above is basically a
method (called findPopupAndClickOn(String menuItemLabel)) which takes
in a string parameter which is the label - *not* name - of the
menuitem to click.

The above represents the first part of the FEST test. Within the same
test, I continue ahead. Now I call the findPopupAndClickOn() method
again, but with a different menu item label (the one that comes after
the separator). However, this time, for some reason, the menu item is
not clicked on. The exact code that worked in the first instance does
not work in the second instance, any ideas why?

The only reason I can come up with is that the separator has something
to do with it, so I even wrote my own GenericTypeMatcher, but no
effect. Here is the above method implementation

protected void findUnitsPopupAndClickOn(final String text) {
       ComponentFinder finder = frame.robot.finder();
       JPopupMenu unitsPopup = finder.findByType(JPopupMenu.class,
true);
       final JPopupMenuFixture unitsPopupFixture = new
JPopupMenuFixture(robot, unitsPopup);

       GenericTypeMatcher<JMenuItem> matcher = new
GenericTypeMatcher<JMenuItem>() {
           @Override
           protected boolean isMatching(JMenuItem component) {
               return component.getText().equalsIgnoreCase(text);

           }
       };

       JMenuItemFixture mif = unitsPopupFixture.menuItem(matcher);
       System.out.println(mif.target.getText()) ;  // prints the
correct text string BOTH times!
       robot.moveMouse(mif.target) ; // was added just to see if it
actually moves the mouse to the right location - it does so in the
first case, but not in the second case.

       mif.click() ;

   }

The above method is called AFTER I double-click on the JLabel
instance, so that its actionlistener then actually displays the popup
which is then found by the robot in the above method.

Original issue reported on code.google.com by Alex.Rui...@gmail.com on 22 Aug 2008 at 5:59

GoogleCodeExporter commented 9 years ago
It seems that the problem is with the matcher. Since it is not specifying that 
it is
looking for "showing" components, my guess is that multiple matching JMenuItems 
are
being found. I sent an e-mail to Sachin but I haven't got an answer yet.

Marking this issue as "Invalid"

Original comment by Alex.Rui...@gmail.com on 15 Oct 2008 at 8:30

GoogleCodeExporter commented 9 years ago
Set the module as a label, instead of being part of the title.

Original comment by Alex.Rui...@gmail.com on 1 Dec 2008 at 3:17