How do I minimize application window in Java swing UI?

90 Views Asked by At

I am working with a java swing application. I would like to test a drag and drop feature between two instances of the application. To do that, I need to arrange the two windows so they are both visible on the screen.

The "component event: RESIZED" and "component event: MOVED" seem to work to do this, except when the applications is in full-screen mode. However I can not get QFTest to recognize any of the three button at the top right of the application (ie minimize, restore, and close).

My question has two parts

  1. Why do the "component event:RESIZED" and "component event: MOVED" not work in full screen mode?
  2. How do I get QFtest to recognize the 'restore' button clicks? Are these not part of the application?

[Application showing minimize, restore down (is that what it is called?) and exit buttons at top right] (https://i.stack.imgur.com/UyFEF.png)

These component events only work after the "restore down" button has been clicked

I have tried using the "record", "record checks", and "record components" tools to get QFTest to recognize the "restore down" buttons. Nothing is recorded.

-----EDIT-------

I am trying to arrange two application windows side by side so I can test a drag and drop feature. I added the two pictures below to illustrate this:

starting point

Finishing point

The issue I'm running into is that when the application is in fullscreen mode it does not respond to the "Component event: MOVED" or "Component event: RESIZED".

If I manually take the application out of full screen mode the component event nodes work as expected.

From this starting point "Component event: move" works

Is there a QFtest tool for exiting full screen mode(ie going from the "starting point" picture to the above picture)?

"Window event: WINDOW_ICONIFIED" minimizes the window completely, which also prevents me from moving and resizing.

2

There are 2 best solutions below

0
On

I can reproduce the problem. It turns out at least under Ubnutu the window gets snapped to the maximized size and the events can be recorded but not replayed. Also if I use TeamViewer the solution works but if I use my VirtualBox the events are caught from the VirtulBox it does not work. I couldn't find the settings to prevent this though. So the solution is to use the shortcut Alt-F10 to maximize or restore the window. In order to get the window to front you may tell QF-Test to execute a Mouse-Event as "a hard event" and then use this Groovy Server Script:

import java.awt.Robot
import java.awt.event.KeyEvent

r = new Robot()

r.setAutoDelay(200)

r.keyPress(KeyEvent.VK_ALT)
r.keyPress(KeyEvent.VK_F10)
r.keyRelease(KeyEvent.VK_F10)
r.keyRelease(KeyEvent.VK_ALT)

In order to arrange the windows next to each other you need to use a "Component Event" node in QF-Test to resize them first. Then you need to know the resolution of your desktop and move them to a coordinates so that you get the layout you want. I was using in similar scenarios the Toolkit.getDefaultToolkit().getScreenResolution() and since you know the size of the windows you can calculate the new X,Y of those windows.

A long answer, but sometimes the Display Managers under Linux force us :)

P.S. If you need a testsuite with examples you may write to [email protected].

1
On

A QF-Test affiliate here. So I have tried and under Ubunutu I was able to record and successfully replay the min and max events. I used the demo Suite whicn comes with QF-Test.

My recording

The buttons on the window cannot be recorded, because they are on a native OS level, and QF-Test has access only to the applciaiton which lives within. Therefore only Events can be recorded, but not the buttons.

Note: An advice - You should resize the windows to a predefinded values because if your test setup changes the windows size will change and this may have bad consequences on the tests.