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

•

u/AutoModerator Dec 24 '22

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

6

u/marskuh Dec 24 '22

Is this a fun question? I don’t understand what you are asking?! Are you talking about a GUI application written in Java? What do you want to automate. We need a bit more information

2

u/[deleted] Dec 24 '22

Yes , you are right, how to automate a GUI application written in java. Do we access its DOM structure of it from the jar files ?

5

u/khooke Extreme Brewer Dec 24 '22

Can you explain what it is you're trying to do and why? Browsers have a DOM, Java apps do not.

2

u/[deleted] Dec 24 '22 edited Jan 02 '23

I am trying to automate any java application ( cross framework , cross platform) . I understand now java applications do not have DOM. How do we get the components structure of any java application then.

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

1

u/Comfortable_Swing_75 Dec 25 '22

http://sikulix.com sikulix is also an option if you want to automate by application images