Menu

#65 NamedComponentFinder doesn't find JMenuItm with jdk1.4.2

open
nobody
None
5
2004-12-08
2004-12-08
Anonymous
No

I use the NamedComponentFinder to find my menu items
("JMenuItem") in a simple frame. In fact with
jdk1.4.2_05 my test suite block after a menu is ckicked
and the finder doesn't find the named menu item
whereas I had no problem before with jdk1.4.1_02 (a
JMenu component does not contain any sub
components : method getComponents() return an empty
array; so that it is difficult to find JMenuItem it
contains ! but it's popupMenu was previously accessible
from it's parent JPanel contained in the JLayeredPane of
the frame... that seems not to be always the case
now !).

Here are some methods that allow me to retrieve my
menu item or to click on it.

public JMenuItem getMenuItem(String itemKey) {
NamedComponentFinder menuItemFinder = new
NamedComponentFinder(
JMenuItem.class, "^" + itemKey + "$");
JMenuItem menuItem = (JMenuItem)
menuItemFinder.find(mainFrame, 0);
return menuItem;
}

public void enterClickAndLeaveMenuItem(String
menuKey, String itemKey)
throws Exception {
getHelper().enterClickAndLeave(
new MouseEventData(getTestCase(), getMenu
(menuKey)));
getHelper().enterClickAndLeave(
new MouseEventData(getTestCase(), getMenuItem
(itemKey)));
}

Here is the work around I have use to solve my problem :
I rewrite the Finder class with method
findComponentList modified :

public static final List findComponentList(final Finder
finder,
final Container cont, final List pList, final int index)
{
List outList = pList;

if (outList == null) {
outList = new ArrayList();
}

if ((cont == null) || (finder == null)) {
return outList;
}

ArrayList childrenList = new ArrayList();
childrenList.addAll(Arrays.asList
(cont.getComponents()));
if (cont instanceof JMenu) {
JPopupMenu menu = ((JMenu)
cont).getPopupMenu();
if (menu != null) {
childrenList.add(menu);
}
}
Component[] children = (Component[])
childrenList.toArray(new Component[0]);

... the suite is unchanged

Thanks
Stephane.CARRE@eu.biomerieux.com

Discussion


Log in to post a comment.

MongoDB Logo MongoDB