Intermittent issue with JFileChooserFixture

19 views
Skip to first unread message

Dan

unread,
Jun 11, 2009, 1:51:06 PM6/11/09
to easytesting
I have the following situation:
1. I need to prove that the JFileChooser works as designed (before
going into some custom JFC functionality tests).
2. I designed a simple FEST-swing test that passes in eclipse.
(Recently I've been able to get sporadic tests to fail in eclipse when
the JFCFinder cannot locate the JFC being displayed as part of another
thread).
3. The tests, when committed to the repo and run on Hudson (using
xvfb), fail intermittently (usually 1-3 fails per build).

I put a bunch of timing println's and have included my test code
below. I've recently traced the failures as far as my test not
receiving the event fired when the approve button is clicked (not part
of code below). All gui-based interaction occurs in the EDT properly,
and I am at a loss here. Any help would be appreciated.


---------------------- CODE:----------------------
public class JFileChooserTest implements ActionListener {

private static int count = 0;
public static JFrame jframe;


@BeforeClass
public static void initClass() {
FailOnThreadViolationRepaintManager.install();
}

@Before
public void setup() {
System.gc();
count++;
System.out.println(time(count) + ": begining execution");
}

@After
public void teardown() throws InterruptedException {
System.out.println(time(count) + ": ending execution.\n");
}

public void test() {

Robot myRobot = BasicRobot.robotWithNewAwtHierarchy();

GuiActionRunner.executeInEDT(true);

final int loccount = count;
final ArrayList<Integer> results = new ArrayList<Integer>();

new Thread( new Runnable(){
public void run() {

GuiActionRunner.execute(new GuiTask() {

public void executeInEDT() {
jframe = new JFrame();

System.out.println(time(loccount) + ": Pre-Chooser
ID");
JFileChooser chooser = new JFileChooser() {

@Override
public void approveSelection() {
super.approveSelection();
System.out.println(time(loccount) + "In the
OVER-RIDDEN APPROVE_SELECTION METHOD.");
}
};
chooser.setName("chooser" + loccount);
System.out.println(time(loccount) + ": Pre-show");
results.add( chooser.showOpenDialog
(JFileChooserTest.jframe) );
System.out.println(time(loccount) + ": Post-show");
}
});
}}).start();

JFileChooserFixture found = null;
ComponentFinder finder =
BasicComponentFinder.finderWithCurrentAwtHierarchy();

try {
found = JFileChooserFinder.findFileChooser("chooser" +
loccount).using(myRobot);
} catch (WaitTimedOutError wtoe) {
ScreenLock.instance().release(myRobot);
System.out.println(time(loccount) + ": FAILING");
fail("Could not find file chooser.");
}

System.out.println(time(loccount) + ": Fixture ID: " + found);

System.out.println(time(loccount) + ": setting
fileNameTextBox.");
found.fileNameTextBox().setText(System.getProperty
("user.home") + "/file.txt");

System.out.println(time(loccount) + ": Requesting focus.");
found.focus();

System.out.println(time(loccount) + ": Clicking approve.");
found.approve();

if ( !(results.size() > 0) ) {
ScreenLock.instance().release(myRobot);
System.out.println(time(loccount) + ": FAILING");
fail("The showOpenDialog didn't return anything to add to
the array list.");
}


System.out.println(time(loccount) + ": Actual returned result:
" + results.get(0) );
assertEquals(new File(System.getProperty("user.home"),
"file.txt"), found.target.getSelectedFile());
assertEquals(results.get(0), (Integer)
JFileChooser.APPROVE_OPTION);

myRobot.cleanUp();
}

@Test (timeout=11000)
public void test1() throws Exception {
System.out.println("Test 1");
test();
}

@Test (timeout=11000)
public void test2() throws Exception {
System.out.println("Test 2");
test();
}

@Test(timeout=11000)
public void test3() throws Exception {
System.out.println("Test 3");
test();
}

@Test(timeout=11000)
public void test4() throws Exception {
System.out.println("Test 4");
test();
}

@Test(timeout=11000)
public void test5() throws Exception {
System.out.println("Test 5");
test();
}

@Test(timeout=11000)
public void test6() throws Exception {
System.out.println("Test 6");
test();
}

@Test(timeout=11000)
public void test7() throws Exception {
System.out.println("Test 7");
test();
}

@Test(timeout=11000)
public void test8() throws Exception {
System.out.println("Test 8");
test();
}

@Test(timeout=11000)
public void test9() throws Exception {
System.out.println("Test 9");
test();
}

@Test(timeout=11000)
public void test10() throws Exception {
System.out.println("Test 10");
test();
}

@Test(timeout=11000)
public void test11() throws Exception {
System.out.println("Test 11");
test();
}

@Test(timeout=11000)
public void test12() throws Exception {
System.out.println("Test 12");
test();
}

@Test(timeout=11000)
public void test13() throws Exception {
System.out.println("Test 13");
test();
}


private String time(int iter) {
String retValue = (iter + " @ " + GregorianCalendar.getInstance
().getTimeInMillis()
+ " Thread: " + Thread.currentThread().getId
() + " ");

return retValue;
}
}


---------------------- RESULTS: ----------------------
[junit] 1 @ 1244581460241 Thread: 1 : begining execution
[junit] Test 1
[junit] 1 @ 1244581460482 Thread: 148 : Pre-Chooser ID
[junit] 1 @ 1244581460609 Thread: 148 : Pre-show
[junit] 1 @ 1244581460873 Thread: 152 : Fixture ID:
org.fest.swing.fixture.JFileChooserFixture@1e956bd
[junit] 1 @ 1244581460873 Thread: 152 : setting fileNameTextBox.
[junit] 1 @ 1244581460971 Thread: 152 : Requesting focus.
[junit] 1 @ 1244581461100 Thread: 152 : Clicking approve.
[junit] 1 @ 1244581461347 Thread: 148 In the OVER-RIDDEN
APPROVE_SELECTION METHOD.
[junit] 1 @ 1244581461351 Thread: 148 : Post-show
[junit] 1 @ 1244581461460 Thread: 152 : Actual returned result: 0
[junit] 1 @ 1244581461462 Thread: 1 : ending execution.
[junit]
[junit] 2 @ 1244581461577 Thread: 1 : begining execution
[junit] Test 2
[junit] 2 @ 1244581461582 Thread: 148 : Pre-Chooser ID
[junit] 2 @ 1244581461592 Thread: 148 : Pre-show
[junit] 2 @ 1244581461646 Thread: 171 : Fixture ID:
org.fest.swing.fixture.JFileChooserFixture@1b7c463
[junit] 2 @ 1244581461646 Thread: 171 : setting fileNameTextBox.
[junit] 2 @ 1244581461705 Thread: 171 : Requesting focus.
[junit] 2 @ 1244581461822 Thread: 171 : Clicking approve.
[junit] 2 @ 1244581462180 Thread: 171 : FAILING
[junit] 2 @ 1244581462181 Thread: 1 : ending execution.
[junit]
[junit] 3 @ 1244581462301 Thread: 1 : begining execution
[junit] Test 3
[junit] 3 @ 1244581462302 Thread: 148 : Pre-Chooser ID
[junit] 3 @ 1244581462311 Thread: 148 : Pre-show
[junit] 3 @ 1244581462363 Thread: 185 : Fixture ID:
org.fest.swing.fixture.JFileChooserFixture@1dfb8d0
[junit] 3 @ 1244581462363 Thread: 185 : setting fileNameTextBox.
[junit] 3 @ 1244581462428 Thread: 185 : Requesting focus.
[junit] 3 @ 1244581462545 Thread: 185 : Clicking approve.
[junit] 3 @ 1244581462804 Thread: 148 In the OVER-RIDDEN
APPROVE_SELECTION METHOD.
[junit] 3 @ 1244581462806 Thread: 148 : Post-show
[junit] 3 @ 1244581462902 Thread: 185 : Actual returned result: 0
[junit] 3 @ 1244581462904 Thread: 1 : ending execution.
[junit]
[junit] 4 @ 1244581463045 Thread: 1 : begining execution
[junit] Test 4
[junit] 4 @ 1244581463046 Thread: 148 : Pre-Chooser ID
[junit] 4 @ 1244581463055 Thread: 148 : Pre-show
[junit] 4 @ 1244581463108 Thread: 202 : Fixture ID:
org.fest.swing.fixture.JFileChooserFixture@1d9f91c
[junit] 4 @ 1244581463108 Thread: 202 : setting fileNameTextBox.
[junit] 4 @ 1244581463168 Thread: 202 : Requesting focus.
[junit] 4 @ 1244581463285 Thread: 202 : Clicking approve.
[junit] 4 @ 1244581463528 Thread: 148 In the OVER-RIDDEN
APPROVE_SELECTION METHOD.
[junit] 4 @ 1244581463531 Thread: 148 : Post-show
[junit] 4 @ 1244581463642 Thread: 202 : Actual returned result: 0
[junit] 4 @ 1244581463643 Thread: 1 : ending execution.
[junit]
[junit] 5 @ 1244581463757 Thread: 1 : begining execution
[junit] Test 5
[junit] 5 @ 1244581463759 Thread: 148 : Pre-Chooser ID
[junit] 5 @ 1244581463769 Thread: 148 : Pre-show
[junit] 5 @ 1244581463824 Thread: 219 : Fixture ID:
org.fest.swing.fixture.JFileChooserFixture@7614d6
[junit] 5 @ 1244581463824 Thread: 219 : setting fileNameTextBox.
[junit] 5 @ 1244581463884 Thread: 219 : Requesting focus.
[junit] 5 @ 1244581463999 Thread: 219 : Clicking approve.
[junit] 5 @ 1244581464355 Thread: 219 : FAILING
[junit] 5 @ 1244581464355 Thread: 1 : ending execution.
[junit]
[junit] 6 @ 1244581464474 Thread: 1 : begining execution
[junit] Test 6
[junit] 6 @ 1244581464476 Thread: 148 : Pre-Chooser ID
[junit] 6 @ 1244581464484 Thread: 148 : Pre-show
[junit] 6 @ 1244581464537 Thread: 233 : Fixture ID:
org.fest.swing.fixture.JFileChooserFixture@16bb691
[junit] 6 @ 1244581464537 Thread: 233 : setting fileNameTextBox.
[junit] 6 @ 1244581464595 Thread: 233 : Requesting focus.
[junit] 6 @ 1244581464711 Thread: 233 : Clicking approve.
[junit] 6 @ 1244581464952 Thread: 148 In the OVER-RIDDEN
APPROVE_SELECTION METHOD.
[junit] 6 @ 1244581464954 Thread: 148 : Post-show
[junit] 6 @ 1244581465067 Thread: 233 : Actual returned result: 0
[junit] 6 @ 1244581465068 Thread: 1 : ending execution.
[junit]
[junit] 7 @ 1244581465181 Thread: 1 : begining execution
[junit] Test 7
[junit] 7 @ 1244581465183 Thread: 148 : Pre-Chooser ID
[junit] 7 @ 1244581465190 Thread: 148 : Pre-show
[junit] 7 @ 1244581465245 Thread: 250 : Fixture ID:
org.fest.swing.fixture.JFileChooserFixture@aaa1c3
[junit] 7 @ 1244581465245 Thread: 250 : setting fileNameTextBox.
[junit] 7 @ 1244581465303 Thread: 250 : Requesting focus.
[junit] 7 @ 1244581465418 Thread: 250 : Clicking approve.
[junit] 7 @ 1244581465773 Thread: 250 : FAILING
[junit] 7 @ 1244581465773 Thread: 1 : ending execution.
[junit]
[junit] 8 @ 1244581465897 Thread: 1 : begining execution
[junit] Test 8
[junit] 8 @ 1244581465899 Thread: 148 : Pre-Chooser ID
[junit] 8 @ 1244581465906 Thread: 148 : Pre-show
[junit] 8 @ 1244581465963 Thread: 264 : Fixture ID:
org.fest.swing.fixture.JFileChooserFixture@334f8e
[junit] 8 @ 1244581465963 Thread: 264 : setting fileNameTextBox.
[junit] 8 @ 1244581466021 Thread: 264 : Requesting focus.
[junit] 8 @ 1244581466137 Thread: 264 : Clicking approve.
[junit] 8 @ 1244581466379 Thread: 148 In the OVER-RIDDEN
APPROVE_SELECTION METHOD.
[junit] 8 @ 1244581466381 Thread: 148 : Post-show
[junit] 8 @ 1244581466494 Thread: 264 : Actual returned result: 0
[junit] 8 @ 1244581466497 Thread: 1 : ending execution.
[junit]
[junit] 9 @ 1244581466618 Thread: 1 : begining execution
[junit] Test 9
[junit] 9 @ 1244581466620 Thread: 148 : Pre-Chooser ID
[junit] 9 @ 1244581466627 Thread: 148 : Pre-show
[junit] 9 @ 1244581466686 Thread: 281 : Fixture ID:
org.fest.swing.fixture.JFileChooserFixture@1050e86
[junit] 9 @ 1244581466686 Thread: 281 : setting fileNameTextBox.
[junit] 9 @ 1244581466744 Thread: 281 : Requesting focus.
[junit] 9 @ 1244581466859 Thread: 281 : Clicking approve.
[junit] 9 @ 1244581467101 Thread: 148 In the OVER-RIDDEN
APPROVE_SELECTION METHOD.
[junit] 9 @ 1244581467103 Thread: 148 : Post-show
[junit] 9 @ 1244581467215 Thread: 281 : Actual returned result: 0
[junit] 9 @ 1244581467216 Thread: 1 : ending execution.
[junit]
[junit] 10 @ 1244581467334 Thread: 1 : begining execution
[junit] Test 10
[junit] 10 @ 1244581467336 Thread: 148 : Pre-Chooser ID
[junit] 10 @ 1244581467343 Thread: 148 : Pre-show
[junit] 10 @ 1244581467407 Thread: 298 : Fixture ID:
org.fest.swing.fixture.JFileChooserFixture@12bd15e
[junit] 10 @ 1244581467407 Thread: 298 : setting fileNameTextBox.
[junit] 10 @ 1244581467465 Thread: 298 : Requesting focus.
[junit] 10 @ 1244581467580 Thread: 298 : Clicking approve.
[junit] 10 @ 1244581467822 Thread: 148 In the OVER-RIDDEN
APPROVE_SELECTION METHOD.
[junit] 10 @ 1244581467824 Thread: 148 : Post-show
[junit] 10 @ 1244581467937 Thread: 298 : Actual returned result:
0
[junit] 10 @ 1244581467938 Thread: 1 : ending execution.
[junit]
[junit] 11 @ 1244581468057 Thread: 1 : begining execution
[junit] Test 11
[junit] 11 @ 1244581468058 Thread: 148 : Pre-Chooser ID
[junit] 11 @ 1244581468067 Thread: 148 : Pre-show
[junit] 11 @ 1244581468116 Thread: 315 : Fixture ID:
org.fest.swing.fixture.JFileChooserFixture@1a75098
[junit] 11 @ 1244581468116 Thread: 315 : setting fileNameTextBox.
[junit] 11 @ 1244581468174 Thread: 315 : Requesting focus.
[junit] 11 @ 1244581468290 Thread: 315 : Clicking approve.
[junit] 11 @ 1244581468533 Thread: 148 In the OVER-RIDDEN
APPROVE_SELECTION METHOD.
[junit] 11 @ 1244581468535 Thread: 148 : Post-show
[junit] 11 @ 1244581468647 Thread: 315 : Actual returned result:
0
[junit] 11 @ 1244581468648 Thread: 1 : ending execution.
[junit]
[junit] 12 @ 1244581468764 Thread: 1 : begining execution
[junit] Test 12
[junit] 12 @ 1244581468765 Thread: 148 : Pre-Chooser ID
[junit] 12 @ 1244581468773 Thread: 148 : Pre-show
[junit] 12 @ 1244581468826 Thread: 332 : Fixture ID:
org.fest.swing.fixture.JFileChooserFixture@15cc764
[junit] 12 @ 1244581468826 Thread: 332 : setting fileNameTextBox.
[junit] 12 @ 1244581468884 Thread: 332 : Requesting focus.
[junit] 12 @ 1244581468999 Thread: 332 : Clicking approve.
[junit] 12 @ 1244581469240 Thread: 148 In the OVER-RIDDEN
APPROVE_SELECTION METHOD.
[junit] 12 @ 1244581469242 Thread: 148 : Post-show
[junit] 12 @ 1244581469354 Thread: 332 : Actual returned result:
0
[junit] 12 @ 1244581469355 Thread: 1 : ending execution.
[junit]
[junit] 13 @ 1244581469474 Thread: 1 : begining execution
[junit] Test 13
[junit] 13 @ 1244581469476 Thread: 148 : Pre-Chooser ID
[junit] 13 @ 1244581469482 Thread: 148 : Pre-show
[junit] 13 @ 1244581469528 Thread: 349 : Fixture ID:
org.fest.swing.fixture.JFileChooserFixture@1b5e7a0
[junit] 13 @ 1244581469528 Thread: 349 : setting fileNameTextBox.
[junit] 13 @ 1244581469584 Thread: 349 : Requesting focus.
[junit] 13 @ 1244581469700 Thread: 349 : Clicking approve.
[junit] 13 @ 1244581470058 Thread: 349 : FAILING
[junit] 13 @ 1244581470058 Thread: 1 : ending execution.
[junit]
[junit] ------------- ---------------- ---------------
[junit] Testcase: test2<<test class>>: FAILED
[junit] The showOpenDialog didn't return anything to add to the
array list.
[junit] junit.framework.AssertionFailedError: The showOpenDialog
didn't return anything to add to the array list.
[junit] at (<<test class>>.java:130)
[junit] at (<<test class>>.java:159)
[junit] at java.util.concurrent.FutureTask$Sync.innerRun
(FutureTask.java:303)
[junit] at java.util.concurrent.FutureTask.run(FutureTask.java:
138)
[junit] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:886)
[junit] at java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:908)
[junit] at java.lang.Thread.run(Thread.java:619)
[junit]
[junit]
[junit] Testcase: test5(<<test class>>): FAILED
[junit] The showOpenDialog didn't return anything to add to the
array list.
[junit] junit.framework.AssertionFailedError: The showOpenDialog
didn't return anything to add to the array list.
[junit] at (<<test class>>.java:130)
[junit] at (<<test class>>.java:177)
[junit] at java.util.concurrent.FutureTask$Sync.innerRun
(FutureTask.java:303)
[junit] at java.util.concurrent.FutureTask.run(FutureTask.java:
138)
[junit] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:886)
[junit] at java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:908)
[junit] at java.lang.Thread.run(Thread.java:619)
[junit]
[junit]
[junit] Testcase: test7(<<test class>>): FAILED
[junit] The showOpenDialog didn't return anything to add to the
array list.
[junit] junit.framework.AssertionFailedError: The showOpenDialog
didn't return anything to add to the array list.
[junit] at (<<test class>>.java:130)
[junit] at (<<test class>>.java:189)
[junit] at java.util.concurrent.FutureTask$Sync.innerRun
(FutureTask.java:303)
[junit] at java.util.concurrent.FutureTask.run(FutureTask.java:
138)
[junit] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:886)
[junit] at java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:908)
[junit] at java.lang.Thread.run(Thread.java:619)
[junit]
[junit]
[junit] Testcase: test13(<<test class>>): FAILED
[junit] The showOpenDialog didn't return anything to add to the
array list.
[junit] junit.framework.AssertionFailedError: The showOpenDialog
didn't return anything to add to the array list.
[junit] at (<<test class>>.java:130)
[junit] at (<<test class>>.java:225)
[junit] at java.util.concurrent.FutureTask$Sync.innerRun
(FutureTask.java:303)
[junit] at java.util.concurrent.FutureTask.run(FutureTask.java:
138)
[junit] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:886)
[junit] at java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:908)
[junit] at java.lang.Thread.run(Thread.java:619)

Woody Folsom

unread,
Jun 11, 2009, 3:42:12 PM6/11/09
to easyt...@googlegroups.com
Hi Dan,
I was not able to get any of the 13 tests above to fail, either
under Netbeans or Hudson/vncserver. This suggests that the problem is
in code that was not inlcluded in the post above, such as the missing
actionPerformed() method.

Dan

unread,
Jun 11, 2009, 4:01:24 PM6/11/09
to easytesting
Woody,

Interesting - maybe it points to a problem with Xvfb then?? (We do
not have X11 installed, and the accepted solution is to use Xvfb).
Are there any other solutions we can try that do not involve
installing X11?


On a side note, I get the feeling everything is being displayed/typed/
etc properly, except when it gets to the found.approve() method call
it just times out. IDK, but that's what my gut is telling me.

Thanks!
DAN

Woody Folsom

unread,
Jun 11, 2009, 4:18:04 PM6/11/09
to easyt...@googlegroups.com
I'm using vncserver but it should function like xvfb. I did once have
the issue where I got this exact behavior whenever a dialog appaered
in a location such that the JButton I was trying to click() as outside
of the virtual screen's resolution. When I changed the resolution to
1600x1200, that particular problem went away. The issue I got was
always timeout, never component not found or multiple components
found.

Specifically, I am using the following in tomcat's catalina.sh

DISPLAY=:2
vncserver -kill $DISPLAY
vncserver $DISPLAY -geometry 1600x1200
...
-Djava.awt.headless=true
Reply all
Reply to author
Forward
Message has been deleted
0 new messages