JOptionPaneFinder hangs

157 views
Skip to first unread message

Jack Smith

unread,
Apr 30, 2012, 10:16:28 AM4/30/12
to easytesting

I have a simple testcase following what I've seen in the docs but it
just hangs trying to find/access a JOptionPane. This happens in every
case I've tried - my app, the testcase - my machine at home, the one
at work - JUnit 3, JUnit 4 - Eclipse Java project, plugin project -
etc. The frame comes up, the button is clicked, the optionpane is
shown but then it seems to just sit there waiting on acquiring the
owner lock (something else seems to have it).

Any ideas what I'm missing?

--

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

import org.fest.swing.core.BasicRobot;
import org.fest.swing.edt.FailOnThreadViolationRepaintManager;
import org.fest.swing.edt.GuiActionRunner;
import org.fest.swing.edt.GuiQuery;
import org.fest.swing.finder.JOptionPaneFinder;
import org.fest.swing.fixture.FrameFixture;
import org.fest.swing.fixture.JOptionPaneFixture;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class FestTest
{
FrameFixture window;

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

@Before
public void setUp()
{
MyFrame frame = GuiActionRunner.execute(new GuiQuery<MyFrame>()
{
@Override
protected MyFrame executeInEDT()
{
return new MyFrame();
}
});
window = new FrameFixture(frame);
window.show(); // shows the frame to test
}

@After
public void tearDown()
{
window.cleanUp();
}

@Test
public void testOptPane()
{
window.button().click();
pause(2);
JOptionPaneFixture optionPane =
JOptionPaneFinder.findOptionPane().using(BasicRobot.robotWithCurrentAwtHierarchy());
optionPane.requireMessage("Hello");
pause(1);
optionPane.click();
window.close();
}

void pause(int secs)
{
try
{
Thread.sleep(secs * 1000);
}
catch (InterruptedException e)
{
throw new RuntimeException(e);
}
}

class MyFrame extends JFrame
{
MyFrame()
{
JButton btn = new JButton("Click");
btn.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent arg0)
{
System.out.println("clicked");
JOptionPane.showMessageDialog(MyFrame.this, "Hello");
}
});
add(btn);
pack();
}
}
}

Jack Smith

unread,
Apr 30, 2012, 12:26:33 PM4/30/12
to easytesting

Not sure if this is related at all but having another issue with a
'second-level dialog' - if I have a dialog open, button is clicked,
color chooser is shown, tab is selected, textboxes are found <- this
all seems to work and I can see the components on the screen - but
when I try to have text entered into them, I get an illegalstate
exception because they aren't showing (?).
> JOptionPaneFinder.findOptionPane().using(BasicRobot.robotWithCurrentAwtHier­archy());
>                 optionPane.requireMessage("Hello");
>                 pause(1);
>                 optionPane.click();
>                 window.close();
>         }
>
>         void pause(int secs)
>         {
>                 try
>                 {
>                         Thread.sleep(secs * 1000);
>                 }
>                 catch (InterruptedException e)
>                 {
>                         throw new RuntimeException(e);
>                 }
>         }
>
>         class MyFrame extends JFrame
>         {
>                 MyFrame()
>                 {
>                         JButton btn = new JButton("Click");
>                         btn.addActionListener(new ActionListener()
>                         {
>                                 @Override
>                                 public void actionPerformed(ActionEvent arg0)
>                                 {
>                                         System.out.println("clicked");
>                                         JOptionPane.showMessageDialog(MyFrame.this, "Hello");
>                                 }
>                         });
>                         add(btn);
>                         pack();
>                 }
>         }
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages