aspose file tools*
The moose likes Servlets and the fly likes Automating Web GUI Testing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Automating Web GUI Testing" Watch "Automating Web GUI Testing" New topic
Author

Automating Web GUI Testing

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Hi all,

Is there a way to automate the testing of a web based GUI interface? I've looked into opensource tools like httpunit, htmlunit, jwebunit but none of these actually test the web interface. I would like to somehow record/playback the actions of a user on the webpage and replay those actions to run the tests.

Can anyone share some light on this?

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41516
    
  53
Selenium is a very powerful open source tool for this kind of thing.


Ping & DNS - my free Android networking tools app
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Originally posted by Ulf Dittmer:
Selenium is a very powerful open source tool for this kind of thing.


Thanks i tried selenium but it didnt seem to work for me due to redirections and https. Is there any other option?

I am also thinking of coding it myself but im not sure how/where to start. Is it better done in javascript or can some other technique be done? can some one please give me some pointer in this?

cheers..
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Since, as far as a web application is concerned, all GUI actions just result in requests, servlet testing can be separated from GUI testing.
Here is what I would do:
1. Write a filter to capture all details of requests and responses in some sort of general format. Be sure to capture all headers in a usable form. Choose a format for recording requests that will be easy to hand edit to create new scripts.
2. Have multiple users try the application as it is now, recording as above.
3. Write code to use HttpClient or one of the other client emulators to execute "scripts" based on your recorded sessions and your new scripts.

Bill
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Thanks for your reply. A couple of questions

Since, as far as a web application is concerned, all GUI actions just result in requests, servlet testing can be separated from GUI testing.


Yes this is ok because we do have separate unit tests which tests each servlet. The user interface is not involved at unit test level of the servlets.

My problem is i want to test the actual web pages. Forms, textboxes, listboxes text on the screen and so forth. The tools i mentioned earlier emulate the browser so my testing will not really be valid as i need the data to be sent by the browser that the user will use.

Tools like httpUnit, jwebunit dont actually use the forms but they send the requests to the servlets.


1. Write a filter to capture all details of requests and responses in some sort of general format. Be sure to capture all headers in a usable form. Choose a format for recording requests that will be easy to hand edit to create new scripts.
2. Have multiple users try the application as it is now, recording as above.
3. Write code to use HttpClient or one of the other client emulators to execute "scripts" based on your recorded sessions and your new scripts.


Im new to Java so ill need a slightly expanded explanation

- What exactly is a filter and how does it capture requests and responses?
- When you say recording do you mean recording the user's actions or the requests?
- Please explain point 3.

Thanks in advance
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
1. In the javax.servlet package we find the Filter interface. You can define a custom class implementing this interface and link it into a web application so that it sees all requests before they go to the application and all responses before they are sent to the client. This is typically done by "wrapping" the request and response objects created by the servlet container with extensions of HttpServletRequestWrapper and HttpServletResponseWrapper.

Your custom Filter can capture and record selected material from the request (as caused by the user's actions) and response (which creates the environment for the next action).
You should be able to find plenty of Filter examples by Googling. Hopefully one will be close to what you need.

With HttpClient or similar toolkit you can "Play" the recorded actions and/or actions you create by modifying an existing recorded input.
HttpClient essentially replicates the browser environment under your control as far as creating requests is concerned.

Warning, this will be non-trivial programming so approach carefully.

Bill
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41516
    
  53
Thanks i tried selenium but it didnt seem to work for me due to redirections and https.

It definitely does work with HTTPS; haven't tried it with redirects, but can't really see why it wouldn't support something as simple as that. It's a complex tool, though, so there is a definite learning curve.
 
wood burning stoves
 
subject: Automating Web GUI Testing