Java application automation by Clicknium

Background

Java is an extremely popular programming language that is used to create many desktop GUI applications. It has become a typical demand to automate these Java GUI applications. Clicknium is perfectly suited to the task.

This blog takes SwingSet.jar as an example to introduce how to use Clicknium to automate Java application.

Let’s start to learn about Java automation by automating SwingSet.jar.

Development tools preparation

1. Install Visual Studio Code
2. Install Clicknium extension in Visual Studio Code

Follow the Welcome Page to set up the environment.

3. Install Java autoamtion extension

Click the “Install” button, and a confirmation dialog box will pop up. Click “Yes” to confirm. Get the result of the Java extension installation status in the OUTPUT tab of Visual Studio Code.

Create Sample Project

In Visual Studio Code, press Ctrl+Shift+P to open Command Palette, and then type “Clicknium:Sample” to create a sample project. 


After choosing a project path and creating the sample project, click on the sample.py file. Press F5 to run it and start to learn the Clicknium automation.

Recording UI elements

1. Click the Capture button to record UI elements


The recorder will recognize the Java application automatically and highlight the UI element when the mouse hovers over the element. Press Ctrl+Click on the target element and the relevant locator will be captured.

For more details,please refer the Clicknium Recorder.

API Usage

Clicknium API provides an automation programming interface to automate Web, Desktop, SAP, and other applications. The following functions demonstrate Java automation.

  1. click
  2. clear_text
  3. get_text
  4. select_item
  5. set_checkbox
  6. set_text

Java Automation Sample Code

import subprocess
from time import sleep
from clicknium import clicknium as cc, locator,ui

def main():
   ui(locator.javaw.swingset2.menu_one).click()
   preText=ui(locator.javaw.swingset2.text).get_text()
   print(preText)
   ui(locator.javaw.swingset2.text).set_text("clicknium")
   preText=ui(locator.javaw.swingset2.text).get_text()
   print(preText)
   ui(locator.javaw.swingset2.text).clear_text(by="set-text")
   ui(locator.javaw.swingset2.menu_two).click()
   ui(locator.javaw.swingset2.checkbox).set_checkbox(check_type="uncheck")
   ui(locator.javaw.swingset2.combo_box).select_item("Single")

if __name__ == "__main__":
    main()

Conclusion

Java application automation can be very easy with Clicknium.

What are your feelings