Using WindowFinder to search for modal dialog

I use FEST to test my Java dialogs, and I need to verify that a new modal dialog is being created.

@Before public void setUp() throws Exception { TestFrame testFrame = GuiActionRunner.execute(new GuiQuery<TestFrame>() { @Override protected TestFrame executeInEDT() throws Throwable { panel = new CustomPanel(); return new TestFrame(panel); } }); frameFixture = new FrameFixture(testFrame); frameFixture.show(); frameFixture.robot.waitForIdle(); } 

Note. TestFrame is a helper class that extends the JFrame for use in unit testing.

In my test, I press a button that creates a modal dialog. I try to find and verify that the dialog is created, however, all my attempts cannot find anything:

 WindowFinder.findDialog("Window Title")).using(robot); 

Where is the robot =

  • BasicRobot.robotWithCurrentAwtHierarchy ();
  • BasicRobot.robotWithNewAwtHierarchy ();
  • frameFixture.robot (frameFixture => JFrame)

I also tried to specify the robot search area:

 robot.settings().componentLookupScope(ComponentLookupScope.ALL); 

There are many FEST examples on the Internet that call the robot() call, but I cannot find out how and what this robot function should do.

Why can't I find my new popup dialog?

+6
source share
2 answers

Try adding your search time:

 WindowFinder.findDialog(MyDialog.class).withTimeout(10000).using(robot); 

For more information: http://fest.googlecode.com/svn-history/r458/trunk/fest/fest-swing/javadocs/org/fest/swing/fixture/util/WindowFinder.html

+1
source

Recently, I also use FEST for testing.

When working in the same situation, I use the following method to simulate the action "get this window / dialog"

 private DialogFixture blablawindow; ... blablawindow = WindowFinder.findDialog("XXX").using(robot()); blablawindow.button("button1").click(); 

Since I'm new to FEST, something needs to be careful for me:

XXX is not the actual text displayed in the user interface, you need to check the source code to see the name of the window / dialog box: it looks like this: setName("actual name of window"); or any swing element private javax.swing.JButton button1;

0
source

Source: https://habr.com/ru/post/989283/


All Articles