Tell me how (with what tool) to test ui desktop application written in java (keystroke, etc.)? Give an example or skinte article link. thank
2 answers
I can suggest using the java.awt.Robot class
String text = "Hello world"; Robot robot = new Robot(); for (int n = 0; n < text.length(); n++) { int keyEvent = KeyEvent.getExtendedKeyCodeForChar(text.charAt(n)); robot.keyPress(keyEvent); robot.keyRelease(keyEvent); robot.delay(1000); } robot.waitForIdle(); Rectangle rectangle = new Rectangle(new Dimension(1000, 1000)); BufferedImage printScreen = robot.createScreenCapture(rectangle); File outputFile = new File("screenShot.jpg"); ImageIO.write(printScreen, "jpg", outputFile); This example prints text and takes a screenshot. With this class, you can change the position of the cursor, emulate a click with a mouse and keyboard.
Another option is to use the event queue directly. Independently adding your own event'ы it is possible to emit user actions:
java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(customEvent);
You can use the library Fest .
This library will be able to connect to the tested application, run it. It can choose values from the combo box, check whether the checkbox is selected, press buttons, enter text, pick up text and more.
It is designed for ui тестирование swing applications.