Only the first test runs.

122 views
Skip to first unread message

Marcin Sanecki

unread,
Jun 18, 2013, 4:44:58 AM6/18/13
to easyt...@googlegroups.com
Hi guys,

the situation looks as follows:
I have a class with more than one test method. Here are my setup and tearDown methods (it looks strange but I try to get it working , that is why :)):
    @Before
    public void setUp() {

        if (robot == null) {
            setUpRobot();
            robot = robot();
        }
        // Arguments for JVM
      
        launcher = ApplicationLauncher.application(VwGlobeRun.class);
        launcher.start();
        if (workbenchFrame != null) {
            workbenchFrame.show();
        }
        workbenchFrame = WindowFinder.findFrame(FrameNames.WORKBENCH.getName()).withTimeout(10000)
                .using(robot);

        workbenchFrame.show();
    }

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

The problem is
: after the execution of the first test method (without problems) all next tests methods fail. FrameNames.WORKBENC cannot be found.
Could you please give me any hint how should  I setup tests correctly, and how to clean up the context (tearDown method).
I just want to use the already started application for other tests.
What I noticed diggin in stack trace is that the frame I am looking for is there but in some WindowFilter.ignore collection. Help !!!

Marcin Sanecki

unread,
Jun 18, 2013, 8:36:34 AM6/18/13
to easyt...@googlegroups.com
I have changed my setup a bit and now test methods are executed sequentially. The only one problem now ist the timethat between executions. More than 10sec. Any idea?


@Before
    public void setUp() throws Exception {

        robot2 = BasicRobot.robotWithCurrentAwtHierarchy();

        ApplicationLauncher launcher = ApplicationLauncher.application(VwGlobeRun.class);
        launcher.start();

        workbenchFrame = WindowFinder.findFrame(FrameNames.WORKBENCH.getName()).withTimeout(10000)
                .using(robot2);
    }

    @After
    public void tearDown() {
        robot2.cleanUp();

Marcin Sanecki

unread,
Jun 20, 2013, 8:14:48 AM6/20/13
to easyt...@googlegroups.com
Ok, I have got it working with a workaround. The problem I had was with the execution of second test method. Component I was looging for could not be found. That is why I use the testMethodCounter.

    private static int testMethodCounter = 0;
    private static EmergencyAbortListener mEmergencyAbortListener;
    private FrameFixture workbenchFrame;
    private Robot robot2;
    private static final int myIdleTimeout = 100;


   @Before
    public void setUp() throws Exception {
        if (testMethodCounter == 0) {
            robot2 = BasicRobot.robotWithNewAwtHierarchy();
            GuiActionRunner.execute(new GuiTask() {
                @Override
                protected void executeInEDT() throws Throwable {
                  
                    ApplicationLauncher.application(VwGlobeRun.class).start();
                }
            });
        } else {
            robot2 = BasicRobot.robotWithCurrentAwtHierarchy();
        }
        testMethodCounter++;
        robot2.settings().idleTimeout(myIdleTimeout);


        workbenchFrame = WindowFinder.findFrame(FrameNames.WORKBENCH.getName()).withTimeout(10000)
                .using(robot2);
    }

    @After
    public void tearDown() {
        // current window will not be closed
        robot2.cleanUpWithoutDisposingWindows();

    }


The second problem long breaks between gui events was because of default idleTimeout in org.fest.swing.core.Settings class. In my test I need to get the current AWT hierarchy, after some new dialogs are opened, and for this I used >

robot2.cleanUpWithoutDisposingWindows();
robot2 = BasicRobot.robotWithCurrentAwtHierarchy();

and this line solves the problem with long breeaks between gui events.
robot2.settings().idleTimeout(some timeout);

I need detailed explanation why. If any of you know it please write it or contact me.

Regards,
Marcin

Martin

unread,
Jun 21, 2013, 12:03:18 PM6/21/13
to easyt...@googlegroups.com
Maybe you can try standing up your application before you start FEST.  You can use the @BeforeSuite annotation, this runs only once for the entire suite of tests.  Use that method to launch your application first and then create the FEST robot.  The trick may be waiting for the application to start up, but there is probably some event or some component that appears or disappears when the application is finished starting up.  That's how I have done it.  We have a startup dialog that disappears and a Window that appears once the application is ready.  I wait for that event to occur, then I start the FEST robot.

I have an @AfterSuite method that cleans up once all test classes have been run.

Hope that helps.

Marcin Sanecki

unread,
Jun 24, 2013, 1:49:37 AM6/24/13
to easyt...@googlegroups.com

Robot org.fest.swing.core.BasicRobot.robotWithNewAwtHierarchy()

Creates a new Robot with a new AWT hierarchy. The created Robot will not be able to access any components that were created before it.

When I put the code in a method annotated @BeforeClass (JUnit) which is static then applitation starts but the new problem is that I robot has long breaks (ca 30sec) between gui events. When I declare robot to be static then initial frame cannot be found. That it why I use the workarund. Any idea what may be wrong in my code?

take care,
Marcin

Martin

unread,
Jun 25, 2013, 12:09:41 PM6/25/13
to easyt...@googlegroups.com
Try this instead:

            this.testRobot = BasicRobot.robotWithCurrentAwtHierarchyWithoutScreenLock();

Marcin Sanecki

unread,
Jun 26, 2013, 7:35:25 AM6/26/13
to easyt...@googlegroups.com
That was the point. Thanks Martin!!!
I have noticed that I use the old official release 1.2 from 2010!!!


Now my code looks as follows:

@BeforeClass
    public static void setUpOnce() {

        GuiActionRunner.execute(new GuiTask() {
            @Override
            protected void executeInEDT() throws Throwable {
                ApplicationLauncher.application(Program.class).start();
            }
        });

    }

    @Before
    public void setUp() throws Exception {
        robot = BasicRobot.robotWithCurrentAwtHierarchyWithoutScreenLock();
        robot.settings().idleTimeout(IDLE_TIMEOUT);
        workbenchFrame = WindowFinder.findFrame(FrameNames.WORKBENCH.getName()).withTimeout(FIND_COMPONENT_TIMEOUT)
                .using(robot);
    }

Best regards,
Marcin
Reply all
Reply to author
Forward
0 new messages