automate java desktop application actions - java

I developed a java desktop application where the user can manually load a file and press a button to start a simulation process. I want to automate the above two steps so that an external program can iteratively call this desktop application multiple times and run the simulation process without any human intervention every time. Any thoughts on how I can go about doing this?

It depends on which OS you do it.
If OS X, use automator, for Windows you can use winautomation and for Linux use google and search (for example) kde automation.

I know this is an old question. But there is a new solution now,
JAuto: a JVMTI agent that runs in Java VM and expose UI widget attributes such as class names, screen coordinates. You talk to JAuto by sending a command to a named pipe. It responds by writing a file. It lets you control a Java program via bash scripts.
Using an input simulator such as xdotool, you can achieve automation under the Linux X11 settings.
Disclaimer: I'm the author of JAuto.

Related

Execute a jar file ever Windows initialize and after the user logon (Not as a Service) that call a process with a GUI

I have a jar file and I wanted to run this file as a service. When this .jar executes, it opens another program that I want to be able to see it GUI. But note: only the second program needs a GUI (the .jar not). I open this second program using the following:
ProcessBuilder processBuilder = new ProcessBuilder(cmdCommand);
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
Searching about this issue I saw that if I performed my .jar file as a service, I could not see the process started GUI because services executing in another desktop since Windows Vista. To create a service, I used Java Service Wrapper. On this tutorial, they teach how to use the wrapper.ntservice.interactive configuration to make for the service to display a GUI. They alert too:
"Starting with Windows Vista and Server 2008, Microsoft changed the way services are allowed to interact with the desktop. They decided that for security reasons, services are now only allowed to show their GUI on a special desktop that only the service can interact with. Unfortunately, this makes interactive features pretty much useless. We are looking into ways to display a GUI in a different way. Stay tuned.
If you do a search on the Internet with keywords of "Interactive services dialog Vista", you will find a number of references to the way Windows will display a dialog on the user desktop whenever a service has updated into GUI on the services desktop.
There are some important security reasons why this was disabled in Windows. But if you really need to reenable this functionality, it is possible to do so by editing the Windows Registry and setting HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows\NoInteractiveServices to 0. Always be very careful editing the registry as you can easily mess up your system by changing the wrong values."
I've been tried to configuration the NoInteractiveServices to 0, but yet do not work.
So, how can I execute a .jar program when windows initialize and the user do the login, and still be able to see the GUI of my opened process?

How do I run a gui Java application headless, without control of the source code?

I want to execute a Jar file using javax swing GUI with 1 radial option, a file selector and a button. The goal is to be able to automate the jar through CLI and select the radial option, file and then click the button.
I do not have access to edit the source of the jar
Is this possible?
You can look up JAuto, which is a JVMTI agent that is capable of expose UI widget attributes such as class names, screen coordinates. You talk to JAuto by sending a command to a named pipe. It responds by writing a file. A communication scheme like this works in bash scripts.
With the help of xdotool as an input simulator, you can achieve automation under the Linux X11 environment, inside a docker container.
Although depending on the complexity of the Java app, automating it in a headless manner can also be time-consuming. You may also need a VNC setup to inspect program behavior. Checkout this project IBGA and see how it uses JAuto and xdotool to automate a program.
Disclaimer: I'm the author of both JAuto and IBGA.

Interop with Java System Tray Application

In Java I'm writing a System Tray application which runs in the background on a user's desktop.
How does one interact/interop with this system tray app from another Java program? I want to be able to send notifications to the service arbitrarily, eg causing it to then show a balloon message.
Any solution needs to work on Windows and Mac, and it would be nice if it worked on Linux too - but hey, Java is inherently cross-platform so this shouldn't be an issue.. right?!
Many thanks
If the other (non-tray) programs are Java, RMI is probably the easiest approach. If the other programs aren't Java, but have good support for SOAP, create a WSDL (including XML schema) to represent the notification message(s), and have the tray app call Endpoint.create to listen for SOAP messages from other programs.

Java service wrapper to create service for Java UI application

I have created a Java application which needs to run as a service. For service wrapper I tried using tanuki and other wrapper softwares.
Now, my application does run as a service - however, it runs as a service under SYSTEM and not under currently logged in user.
My application has a UI, which does not show when the application is running as a service. I doubt that this has happened because the service is running under SYSTEM and not under currently logged in user.
When I run the application (without installing it as a service), the UI does show up and I could see the java process running under the current user's id, whereas it runs under SYSTEM when installed as a service.
Now, there is nothing to my application if there is no UI. I need to application to run as a service when the system boots up and the UI needs to show up as well.
Has anyone tried to do what I am doing here and has faced a similar issue. If so, how did you go about resolving it?
Is there a different wrapper service that I could use and not have this issue.
Tanuki's documentation does explain setting a java application as a service, but does not talk about a java applicaiton with a UI and running it under the currently logged in user.
Update
Just so that folks here could get a bit more idea as to what is it that I am trying to accomplish - the behavior that I am trying to have with my app is similar to how Dropbox or Yahoo Messenger or any other software has which starts with Windows boot and continues to run in the background, allowing the users to interact with it using the system tray icon. So basically all of this has been built in Java/Swing. Now when it has come to deployment of the app - I can run it standalone but running the jar file or by creating and running an executable wrapper for it. However, I want the software to start with Windows boot and continue to run as a service in the background, while allowing the user to make changes and interact with it via lets say bringing up the UI from a system tray icon that it sets.
As of now, it does run as a service successfully. It performs all the actions that it ideally should - there just is no system tray icon to bring up the UI and make changes to its configuration.
Update - 2
Ok.. I tried advanced installer and it does wrap up everything for me to generate an exe installer for windows. Now all I need is to auto-start the software. Can anyone help me with this? I don't see an option in Advanced installer to automatically have the program add itself up in the auto-start.
Link to tanuki's doc http://wrapper.tanukisoftware.com/doc/english/faq.html
Rohan,
Please take a look at the following page:
http://wrapper.tanukisoftware.com/doc/english/prop-ntservice-interactive.html
You will need to mark the Service as interactive and then run as the SYSTEM user in order to get your GUI to show up on the first logged in desktop.
The problem is that Microsoft changed what services are allowed to do starting with Windows 2008 and Vista. This means that starting with these versions, the GUI will always show up on a sandboxed desktop which the user will need to switch over to.
If you want to show a GUI on all desktops, in all versions of Windows, you will need to run the JVM within the desktop.
Cheers,
Leif
I wanted to comment on your question, but I don't have enough reputation to do it. So I'm misusing the answer function now.
I have a similar problem. I used the tanuki wrapper for a while now on a Windows XP machine and the Swing GUI was shown to all users who logged in.
Now I migrated to Windows 2008 Server and configured the current version of the tanuki wrapper like this:
wrapper.ntservice.interactive=true
wrapper.ntservice.hide_console=true
(see documentation here and here)
The Windows service runs under the LOCAL SYSTEM account.
But the GUI is still not shown. Did you find any solution to the problem?
Don't think you should have a UI with a service. Put it in the startup group instead ?
What's does the UI and application do?

How to Remotely Block and Unblock any application on Windows

I am creating a program using Java Sockets in which I capture the client desktop and send messaging to client. Its working properly but now I want to block Client applications like Notepad, MS-Word, etc.
How can I do this?
Thanks.
It is hard to do using pure java API.
I do not know what do you mean when you say "block". The easiest way is to check from time to time running processes and kill one named "notepad" by executing taskkill from java.
If you wish to achieve effect of inactivity of application, i.e. user sees the notepad but cannot type you can do the following.
You have to check which application is on front. There is no clean pure java solution for this but you can probably write VBScript or JScript that does this task and run it from java. Once you detected that notepad is on top create transparent window (or even probably half-transparent window) that occupies full screen. Bring it on top. User will not be able to type into notepad because your window is on top but will see it.
Here is reference how to create transparent windows: http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/
Good luck.

Categories

Resources