2

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.

3
  • i think you should ask if its okay to use any freeware after someone else takes a look at it. have wore=ked in very restrictive cos but even there freeware eas okay as long as its testes by an architect. but we had to go thru same for plugins. do not try to build your own Commented Apr 26, 2013 at 13:06
  • Thanks for the suggestion. But I am sure I wont get any approval to use any other tool. I am still searching for the best option to develop this thing. Commented Apr 26, 2013 at 13:11
  • There are several versions of this question about -- I'm referring people to this Open source tools for automation of Java GUI application testing from now on. It has good responses and I want to encourage Thinking Q/A. Commented Jul 14, 2017 at 4:47

2 Answers 2

2

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,

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Gilbert for the reply. Unfortunately I can not use any readymade tool. And even if I use I will have to really struggle hard to get the approval for the same. I was under impression that writing Java code for installing any application (like click next and then click install and catch all the pop-ups) will not be difficult. But looks like I have to really think through it to find some easy Or doable solution. Isn't there any other option which Java provides to handle UI clicks and get the UI text.
Check out the Robot class. docs.oracle.com/javase/7/docs/api/java/awt/Robot.html Writing a GUI tester would be extremely difficult for even the most talented Swing programmers. If we got together the top ten Swing answerers on Stack Overflow, we might be able to produce a GUI tester in about a year.
Thanks for the link. I will go through it. At least I have to give a best try before I give up.
1

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 );
}

4 Comments

Thanks Mikle for your input . Let me at least give a best try on Robot class. So at least I will have better data to share with my management. In the past I tried automating this type of cases using Perl and its quite easy in perl/python. But Java is still new to me, so I am still in learning phase. I am not sure how difficult it is going to be, but let me give it a try.
java.awt.Robot is very is easy to program. tuff part is as mentioned by Mikle - what happens when UI changes etc. Can make data drivesn robots easily -use a property file to tell the robot what to do (move mouse, click, souble click, send keys etc) just google for samples and you can get started quick. but there will be bottle necks later on :)
Yes, you actually need to try on your own to see if Java fits your needs or not :) Anyway, you can easily emulate real keyboard keys and mouse clicks using Robot class - see the small example i have added into answer...
You might want to look at the open-source library, Abbot [A Better BOT]. It has classes that will search JPanels for JButtons. It has a scripting language, named Costello, of course.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.