r/javahelp • • Dec 24 '22

How do we automate a java application?

How can we get the DOM structure of a java application and automate it? Can we use JAAPI ?

0 Upvotes

13 comments sorted by

View all comments

3

u/dionthorn this.isAPro=false; this.helping=true; Dec 24 '22

https://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html

This class is used to generate native system input events
for the purposes of test automation, self-running demos,
and other applications where control of the mouse and keyboard is needed.
The primary purpose of Robot is to
facilitate automated testing of Java platform implementations.

3

u/[deleted] Dec 24 '22

Thank you.

2

u/[deleted] Dec 24 '22

Would there be any other similar api if we need to automate platform independent (os) as well as framework independent (swing, javafx) java applications.

3

u/dionthorn this.isAPro=false; this.helping=true; Dec 24 '22

Robot can be used on any java application doesn't matter if it is Swing, JavaFX or any other.

For OS level keyboard/mouse listeners and events you can use JNativeHook project:

https://github.com/kwhat/jnativehook

which provides native global control of mouse and keyboard.

2

u/[deleted] Dec 24 '22

I see now, would use this . Very greatful for your help.

1

u/[deleted] Jan 02 '23

the JNativeHook provides information about the coordinates of the click, but it does not provide the details of the specific object (button/checkbox) which was clicked. Is there any alternative approach to get the particular details?

1

u/dionthorn this.isAPro=false; this.helping=true; Jan 02 '23

What you are proposing doesn't really make any sense. The whole point of Java using the JVM, and private member fields, etc. Is that it is secure and people can't just poke around in it with outside code.

Why don't you just decompile whatever you have into source code and then fiddle with the source code directly, it'd be much easier.

https://github.com/mstrobel/procyon