Reputation: 131
I am working on writing automation to test application. Most of the things are already done. Now I need to do some GUI automation. Installing the application is one of the part of this, where I need to write Java code which will launch application installer and selects the proper options and install application. In case there are any application pop-ups thrown then catch and respond to those pop-up . Catch any error Or warning in UI. This all things needs to be developed in Java, I am not allowed to use any existing third party tool.
Just want to know whats the best way to do this thing. I was reading http://docs.oracle.com/javase/tutorial/uiswing/components/button.html#radiobutton , is there any other best or easy way to achieve this. Any idea or article around this will be helpful.
Upvotes: 2
Views: 1965
Reputation: 10143
You cannot gain a direct access to another's application controls (like buttons, checkboxes, list and other UI elements) even if it is written in Java, unless that application provide some options to control its UI (and i doubt many applications provide such a thing).
So there could be just two ways (both are equally bad i guess): 1. Use some 3rd party native library to interact with application, but there will be a lot of pain and problems in that case depending on the tested application. 2. Use Robot and emulate key and mouse events over that application window to do something (like pressing a button, filling a textfield or scrolling a list), but that will require exact coordinates for components which you also can't retrieve, so you might only hardcode these coordinates and pray that noone moves/resizes the tested window while test is running.
To summ up - it is not the best thing to write UI test application using Java. Actually i bet it might be a pain to write it using other languages aswell in some cases.
Maybe i am terribly wrong and someone can share a way to do such things in Java in a better way...
P.S. Small robot example (filling abstract login form):
public static void main ( String[] args )
{
fillForm ();
}
private static void fillForm ()
{
try
{
Robot r = new Robot ();
// Set to true so we will wait for events to process
// Still we might need some delays to let application take the input in some cases
r.setAutoWaitForIdle ( true );
// Login
typeKey ( r, KeyEvent.VK_A );
typeKey ( r, KeyEvent.VK_D );
typeKey ( r, KeyEvent.VK_M );
typeKey ( r, KeyEvent.VK_I );
typeKey ( r, KeyEvent.VK_N );
// Tab to password field
typeKey ( r, KeyEvent.VK_TAB );
// Password
typeKey ( r, KeyEvent.VK_P );
typeKey ( r, KeyEvent.VK_A );
typeKey ( r, KeyEvent.VK_S );
typeKey ( r, KeyEvent.VK_S );
// Process form
typeKey ( r, KeyEvent.VK_ENTER );
}
catch ( AWTException e )
{
e.printStackTrace ();
}
}
private static void typeKey ( Robot r, int a )
{
r.keyPress ( a );
r.keyRelease ( a );
}
Upvotes: 1
Reputation: 51445
Probably the best way would be to write a Java application to record what a user does when using the application you want to test.
That means recording all mouse movements and all keystrokes.
Later, your application would play back all of the mouse movements and all of the keystrokes.
You would also have to record the image on the monitor (screen) every time a mouse movement starts, a mouse movement ends, a keystroke sequence starts, and a keystroke sequence ends.
Your Java application would have to compare these images to the images seen during playback. Your Java application would throw an error if the images are too different. Good luck determining how much difference is too different.
The tool I used years ago had a process where the user could go through the playback images, and mark out images that were likely to change, like date and time displays.
Your time would be much better spent if you chose one of the GUI testing tools from the linked Wikipedia list. Some are open source and some are proprietary.
As in most things in life, you're lucky if you get what you pay for,
Upvotes: 2