assertj-swing
assertj-swing copied to clipboard
Testing issues with org.openide.DialogDisplayer
Issue by Mark Corkery from Thu, 24 Sep 2009 04:53:11 -0500 Originally opened as http://jira.codehaus.org/browse/FEST-226
I'm having issues testing NetBeans Platforms DialogDescriptor. If I am testing the behavior in more than one test case the robot will not find the dialog panel in any test subsequent to the first test case which means that only the first test will pass. Netbeans Platform is
included as part of the standard netbeans IDE download. See the following page for more: http://platform.netbeans.org/
Testcase:
shouldDisplayDialog2(com.login.view.LoginFormTest): Caused an ERROR Timed out waiting for dialog to be found using matcher org.fest.swing.core.matcher.DialogMatcher[name=<Any>, title='Hello', requireShowing=false] org.fest.swing.exception.WaitTimedOutError: Timed out waiting for dialog to be found using matcher org.fest.swing.core.matcher.DialogMatcher[name=<Any>, title='Hello', requireShowing=false] at org.fest.swing.timing.Pause.pause(Pause.java:74) at org.fest.swing.timing.Pause.pause(Pause.java:58) at org.fest.swing.fixture.ContainerFixture.findDialog (ContainerFixture.java:165) at org.fest.swing.fixture.ContainerFixture.dialog (ContainerFixture.java:148) at org.fest.swing.fixture.ContainerFixture.dialog (ContainerFixture.java:143) at com.login.view.LoginFormTest.shouldDisplayDialog2 (LoginFormTest.java:85)
I've created a cut down version of what my test looks like below (LoginForm could be replaced with any default JPanel object) :
package com.login.view;import org.fest.swing.driver.ComponentStateValidator; import org.fest.swing.edt.FailOnThreadViolationRepaintManager; import org.fest.swing.edt.GuiTask; import org.fest.swing.fixture.Containers; import org.fest.swing.fixture.DialogFixture; import org.fest.swing.fixture.FrameFixture; import org.fest.swing.core.matcher.DialogMatcher; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import static org.fest.swing.edt.GuiActionRunner.*;
public class LoginFormTest {
<span class="code-keyword">private</span> LoginForm loginForm; <span class="code-keyword">private</span> FrameFixture testPanelFixture = <span class="code-keyword">null</span>; @BeforeClass <span class="code-keyword">public</span> <span class="code-keyword">static</span> void setUpOnce() { FailOnThreadViolationRepaintManager.install(); } @Before <span class="code-keyword">public</span> void setUp() { execute(<span class="code-keyword">new</span> GuiTask() { @Override <span class="code-keyword">protected</span> void executeInEDT() <span class="code-keyword">throws</span> Throwable { loginForm = <span class="code-keyword">new</span> LoginForm(); } }); testPanelFixture = Containers.frameFixtureFor(loginForm); <span class="code-comment">//Aways call wait <span class="code-keyword">for</span> idle after using the GuiActionRunner.
testPanelFixture.robot.waitForIdle(); }
@After <span class="code-keyword">public</span> void cleanUp() { testPanelFixture.robot.cleanUp(); } @Test <span class="code-keyword">public</span> void shouldDisplayDialog() <span class="code-keyword">throws</span> Exception { <span class="code-keyword">final</span> DialogDescriptor dd = <span class="code-keyword">new</span> DialogDescriptor(<span class="code-quote">"Hello"</span>, <span class="code-quote">"Hello"</span>); DialogDisplayer.getDefault().notifyLater(dd); <span class="code-keyword">final</span> DialogFixture loginDialog = testPanelFixture.dialog(DialogMatcher.withTitle(<span class="code-quote">"Hello"</span>)); ComponentStateValidator.validateIsShowing(loginDialog.component()); loginDialog.focus(); } @Test <span class="code-keyword">public</span> void shouldDisplayDialog2() <span class="code-keyword">throws</span> Exception { <span class="code-keyword">final</span> DialogDescriptor dd = <span class="code-keyword">new</span> DialogDescriptor(<span class="code-quote">"Hello"</span>, <span class="code-quote">"Hello"</span>); DialogDisplayer.getDefault().notifyLater(dd); <span class="code-keyword">final</span> DialogFixture loginDialog = testPanelFixture.dialog(DialogMatcher.withTitle(<span class="code-quote">"Hello"</span>)); ComponentStateValidator.validateIsShowing(loginDialog.component()); loginDialog.focus(); }
}
votes (original issue): 0 watches (original issue): 0
Comment by mortenbreum from Fri, 26 Feb 2010 06:32:22 -0600
My two cents on this issue:
The problems seems to be marked with bold
org.fest.swing.exception.WaitTimedOutError: Timed out waiting for
dialog to be found using matcher
org.fest.swing.core.matcher.DialogMatcher[name=<Any>, title='Hello',
requireShowing=false ]
If I am rigth, the dialog()-methods on container fixures should be overloaded with a boolean to specify requireShowing to solve this issue?
/Morten
Edit: The workaround is to to the following:
DialogFixture dialogUser = WindowFinder.findDialog(DialogMatcher.withName("dialogName").andShowing()).using(myexisting.fixture.robot);