If I have a random program, that shows some text and has some text input, is there a way to write a java program, that reads that text labels and/or fill that text input fields and press an ok button?
Text applications are things that run on the cli, and have no windows. On Microsoft Windows the 'dir' command is an example.
Graphical applications are things that the beginning user might see, and has buttons, text boxes, scroll bars and stuff like that. On Microsoft Windows the 'paint' program is an example.
Web applications are websites that provide front ends as web pages. The 'gmail' application is an example.
If you want to interact with an application using Java, the application type will determine your approach.
text application - use ProcessBuilder, it's a java class designed to launch and (to a degree) interact with processes through stdin, stderr, and stdout.
Graphical application - It depends on the graphical widgets the application uses. If those are not supported by a library that can navigate the presentation, then input is limited to x,y coordinates from the application's origin, and input could fail to go into the right component.
Web applications - Use selenium. It is a custom web browser solution that permits testing of web sites; but, you could use it for your task. It is big and complicated, but considering what is required for this task, it is comparatively easy to use.
Yes you can write a new program that can give input and trigger the service of 'OK' key.
Your first program needs to be designed in the way that - it should accept the input from second program.
You can design the first code as web service in a web application . your first program will be web service provider and second program will be web service consumer.
Using second program you can post the required data to first code. and all the triggers of 'OK' button can be processed from first application.
Related
I have an application in java in which I have start and stop buttons in swing. I want to make a windows service which automatically clicks on start button. Is it possible and if it's possible how to do it?
You must find a way to identify the main window of your swing application from the Windows service (common usage is the title bar)
Then, you search in subwindows how to identify the Start button (generally the id, but you could use text)
All that must be done only once, using the Windows SDK tools and/or you knowing from the GUI application
Now the service :
searches the top-level windows for the right one
searches the relevant button
gets it position
uses SendInput API function to simulate a MOUSEEVENTF_LEFTDOWN and MOUSEEVENTF_LEFTUP event over the button
The last part could be done in Java (with Robot), but the others will need to use Windows API
We are developing an application which accesses an API exposed over some embedded system. This API internally validates the user to provide the access to the embedded system. To validate the call, it opens a dialog box and asks for username and password. This dialog box is essentially a Java applet opened in applet viewer.
We want to automate this whole process by building small exe or by doing the same in tomcat server. To do the same, we need get the object of the dialog box and fill the credentials. How can we achieve this. There must be some way to automate the testing of applets which can be used to do the above task.
Thanks for helping. It will be great if someone can provide a code snippet or link for the same :)
Reason why I want to have this kind of system:
We need to build an application which gets the memory status of PLC device. This device is connected with heavy machines and has its own programming language via digital networks. To get the memory map, there are APIs exposed in java which communicates with assembly language. We use these APIs to get the memory status of various memory variables from PLC device. On the basis of the memory status we raise an alert by sending an email or SMS. When we try to access the memory area of this device for the very first time, it pops up an authorization dialog box which asks for username and password of PLC device.
Hence, to automate the memory monitoring system which can send the alerts, we have to fill the authorization dialog box through java program or some of the other way. When I access memory of PLC from java console program we need this authorization dialog to be filled by itself without any manual intervention.
So, How can we get an object of this dialog box?
I hope scenario is clear. We don't need any framework to build which can automate the applet UI. We just need for specific dialog box. Please help!!
You can do with with any number of Java GUI functional testing tools. Here's a good list, looks like FEST or Jemmy might be a good approach:
Automated tests for Java Swing GUIs
It looks like they all build on top of java.awt.Robot so you can look at that if you want to roll your own.
If this does not work you may have to go to a native GUI testing framework. Some good options are listed here for Windows:
https://stackoverflow.com/questions/120359/tools-for-automated-gui-testing-on-windows
http://sikuli.org/ pretty good.
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.
I've implemented an interactive map applet, which is embedded in a web application. The application uses some Ajax, but has a predominantly page based structure.
The problem is, navigating away from and back to the page containing the applet causes an applet reload, which takes several seconds.
Possible ways to alleviate this problem I thought of are:-
Make the applet run continuously in a separate browser window (I lose integration with the main web app though)
Convert the web app to use Ajax exclusively to avoid page reloads
Implement the map view as a standalone desktop app
If there is some way of preventing applet reloads in the browser I would be very interested to hear about it, but I don't think this is possible due to the applet lifecycle.
I think that you enumerated all options, their advantages and disadvantages.
I'd like to suggest you a combination of options you suggested.
You can separate you applet into 2 components. First, heavy-weight application that will be started using a java web start. It will contain all application logic and will run in minimized (or even transparent) window. It will prepare image and send it via network to light-weight applet that just shows it.
I this case you do not loose your application integrity: map is shown in browser. The applet is very light weight, so it starts fast. The stand-alone app implements the most of programming logic.
Here is how to make window transparent: http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/
I have a windows application which has a complex GUI that I would like to hide from users. In order to do this, I would like to create a wrapper with an extremely simple interface that overlays this application and automates a number of actions when a user clicks a single button on the wrapper. (I hope "wrapper" is the proper term.) Is it possible to use Java to block input to the underlying application so that users cannot inadvertently mess up the automation? How would I go about this? Also, how can I automate key presses and clicks to the application without hijacking the mouse? Is this possible in Java?
I have looked at java.awt.Robot, but it appears to hijack the mouse.
I have also looked at AutoIT, but it too hijacks the mouse and does not integrate with Java.
Neither of these options seem powerful enough for what I need, but I do not know how else to proceed.
I recommend that automation via the GUI only as the last resort if you really have no other alternative.
If there is an API that your application exposes, I would try to use that. For example, if the GUI is implemented in one DLL and the logic in another, then you can use JNA to load your application logic DLL and invoke the application functions directly from java. Even better would be if your application exposes a COM/OLE interface - there are plenty of Java<>COM briges, that will alow you to call this interface directly, e.g. Jacob.
If you really have no choice but to automate via the GUI, then here's how to go about doing that:
Use JNA to access the windows shell API. You can then use ShellExecute to launch your wrapped application. Specifically, passing SW_HIDE as the window mode should help ensure that the application does not appear.
Use JNA to access the windows API FindWindow to find your application window. You can also make it invisible using the ShowWindow API, just in case step 1 did not work (not all applications are written to use the nCmdShow parameter.)
You can now post messages to the application window using PostMessage. You can send keystrokes and mouse events using windows messages. E.g. See WM_KEYUP, WM_LBUTTONDOWN.
Because the wrapped application window is made invisible, you don't need to "block" that application, The user simply cannot access it's GUI. But you can still programmatically send input to it.