Locator for JFileChooser "Home" button

WindowTester allows you to easily create and run unit tests for every GUI they build. It can also be used to generate system level tests.

Moderators: gnebling, Eric Clayberg, Dan Rubel, keertip, Phil Quitslund

Locator for JFileChooser "Home" button

Postby deisner » Wed May 04, 2011 10:48 am

I'm having trouble locating the "Home" button in a JFileChooser dialog. [1] The WindowTester recorder records my mouse click as

Code: Select all
ui.click(new JButtonLocator(""));

But when I run the test it fails at the point it should click the Home button with:

Code: Select all
com.windowtester.runtime.MultipleWidgetsFoundException: Multiple Components found


My attempted solution to this problem is to disambiguate like so:

Code: Select all
ui.click(new JButtonLocator("", 0, new SwingWidgetLocator(JPanel.class)));


This at least lets me click a button, but it's the "Parent Directory" button. The only index that works is 0. Any other index (I've tried 1 through 10) produces a WidgetNotFoundException:

Code: Select all
com.windowtester.runtime.WidgetNotFoundException: Component not found JButtonLocator("", 1, WidgetLocator(javax.swing.JPanel)):


If this were an SWT app, I could use the handy com.windowtester.runtime.swt.util.DebugHelper to print the widget hierarchy. There is no equivalent helper for Swing as far as I can tell, so I used Swing Explorer [2]. The highlighted JButton is the one I'm trying to click:

Image

It looks like index 2 would be what I wanted (or maybe 1 if you interpret the semantics of index i to mean the ith JButton, and not just the ith child). Certainly some index between 1 and 7 should do the trick.

So what do I have to do to click the "Home" button?

Thanks.

-David

[1] http://download.oracle.com/javase/tutor ... ooserM.png
[2] http://www.swingexplorer.com/
deisner
 
Posts: 11
Joined: Wed Feb 16, 2011 11:48 am

Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest

cron