Watij – Web Application Testing in Java

Watij (pronounced wattage) stands for Web Application Testing in Java. Watij is a Java API created to allow for the automation of web applications. Inspired by the simplicity of Watir and enhanced by the power of Java, Watij automates functional testing of web applications through real web browsers.

Watij’s new WebSpec API supports the following respective browsers on Windows, Mac, and Linux:

  • Internet Explorer
  • Mozilla
  • Safari

You can also use JRuby!  Watij’s WebSpec API provides a JRuby extension so you get the power of Ruby and Java combined.

Please join our Google group for Watij and post any questions you may have or just browse the topics to see what is possible!

It’s so easy!

Just download Watij’s WebSpec, unzip, install in your favorite IDE and you are ready to start scripting your tests.

See how easy it is to script a search on Google:

Java using Mozilla

WebSpec spec = new WebSpec().mozilla();
spec.open("http://www.google.com");
spec.find.input().with.name("q").set.value("Watij");
spec.find.input().with.type("button").with.value("Google Search").click();
//check results
spec.find.a().with.href("http://watij.com/").shouldExist();

JRuby using Internet Explorer

spec = WebSpec.new.ie
spec.open "http://www.google.com"
spec.input.name('q').value = "Watij"
spec.input.type("button").value("Google Search").click
#check results
spec.a.href("http://watij.com/").should_exist

Now don’t stop here! Take a look at the WebSpec API Documentation and begin writing your Watij test scripts in test runners like JUnit, TestNG, or rspec.

Interactive Ruby Console

WebSpec makes it easy to use JRuby’s IRB shell for interacting with the browser in real-time.

On Windows
From the windows command prompt go to the root directory of WebSpec and run:

console

On Mac
From the Terminal prompt go to the root directory of WebSpec and run:

./console.sh

Once you run the above command you will get the irb prompt. A var
called @spec will already be available to use. So now you can drive
WebSpec from the irb prompt. Try something like the following,
hitting enter after each line:

@spec.open "http://www.google.com"
@spec.input.name("q").value = "Watij"
@spec.input.value("Google Search").click
@spec.a("Watij").all.flash