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 IE:
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
Simple Watij WebSpec Demo
import static org.junit.Assert.*;
import org.junit.Test;
import org.watij.webspec.dsl.Tag;
import org.watij.webspec.dsl.WebSpec;
/**
* Simple Demo of a watij webspec.
* More about webspec and watij see http://watij.com/webspec-api/
*/
public class WebspecDemoTest {
@Test
public void testSearchWikipedia() throws Exception {
WebSpec spec = new WebSpec().safari();
spec.open("http://de.wikipedia.org/wiki/Wikipedia:Hauptseite");
spec.find.input().with.id("searchInput").set.value("Softwaretest");
spec.find.button().with.id("searchButton").click();
assertEquals("Softwaretest", spec.find.h1().with.id("firstHeading").get.innerText());
spec.find.a().with.innerText("Qualität").click();
assertEquals("Softwarequalität", spec.find.h1().with.id("firstHeading").get.innerText());
}
}
Simple Watij WebSpec Demo
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.watij.webspec.dsl.WebSpec;
/**
* Simple Demo of a watij webspec JUnit test.
* More about webspec and watij see http://watij.com/webspec-api/
*/
public class WebspecDemoTest {
WebSpec spec;
@Before
public void setup(){
spec = new WebSpec().safari();
}
@After
public void tearDown(){
spec.browser().close();
}
@Test
public void testSearchWikipedia() throws Exception {
spec.open("http://de.wikipedia.org/wiki/Wikipedia:Hauptseite");
spec.find.input().with.id("searchInput").set.value("Softwaretest");
spec.find.button().with.id("searchButton").click();
assertEquals("Softwaretest", spec.find.h1().with.id("firstHeading").get.innerText());
spec.find.a().with.innerText("Qualität").click();
assertEquals("Softwarequalität", spec.find.h1().with.id("firstHeading").get.innerText());
}
@Test
public void testOpenGoogle() throws Exception {
spec.open("http://www.google.de/");
spec.jquery("input[name='q']").set.value("Testing");
spec.find.input().with.name("btnG").click();
assertTrue(spec.find.div().with.id("res").find.a().get.innerText()
.startsWith("Software testing"));
}
}
Comments
Regression testing a complex enterprise level web app
I have been testing Watij for a couple of months now, looking at the feasibility of regression testing a complex enterprise level web app. So far I am very impressed. It has handled most things that I throw at it, including popup windows in iFrames and dojo. There still seem to be some holes in it, but there is a lot here that makes a lot of sense.
[etherline, 03/22/2010]