Thursday, February 25, 2010

Watij - Web App Testing In Java

Watij: is a pure Java api created to allow for the automation of web applications through a real browser. It performs the same actions you would in a browser: filling out forms, navigating, clicking random stuff, and verifying results.

Did I mentioned, it was inspired by Watir - Web App testing in Ruby

Basic terminology that Watij follows is:
Container: Browser is a container.
Document: The webpage you view

To open new instance of IE, just see this or
IE ie = new IE();

To open new url:

Define URL =

IE ie = new IE();

To close instance:

You can find API:

How to find elements using watij ?

Elements can be found in watij using many approaches:
1. Symbols: name, url, id, href, value, caption, title, alt, src, action, method, text, xpath, tag like:


2. Finders: exist for each symbol and also allow for more flexibility in defining ways to find elements like:


3. Xpath: Watij provides support for using XPath as a Symbol or a Finder. Watij uses the local copy of the document for faster parsing like:

ie.button(xpath, "//INPUT[@value='Hate Me']”);

4. Reg Ex: Watij also provides support for finding elements using regular expressions like:

ie.button(value, “/Hate Me/”);

Watij provides direct support for Javascript alerts, confirm pop ups, file download dialogs and prompt dialogs.

Here is an example of JS alert:
AlertDialog alertDialog = ie.alertDialog();

While automation there are a few things that everyone should keep in mind:

1.Ensure that you are following good design principles.
2.Try to model the application under test using a layer of abstraction.
3. Your tests should be readable by your customer.

The drawback is it only supports Windows and IE..hmmm

No comments:

Post a Comment