<< DWR news round-up | Home | Comet talk from FoWA >>

Embedded Web Testing

The web testing puzzle is a jigsaw with 3 pieces, and for a long time the 3rd piece has been hiding down the side of the sofa, but I think Simon Stewart just found it. He's called it WebDriver - it needs dusting off, but it's looking like it's going to be the right fit.

The problem with testing websites is that it has always been messy. It's bound to be hard coordinating 3 tasks (browser, server, set of tests) across at least 2 processes on different hardware setups, and maybe even different platform architectures.

The set-of-tests piece of the puzzle is well understood; JUnit, TestNG, blah blah.

The well behaved server piece is solved for Java by Jetty - you can fire up an embedded server as easy as new Server(); (example).

Now we can make browsers be as well behaved - we can remote control web browsers from within a Java program. WebDriver currently supports Internet Explorer, Firefox and HtmlUnit for totally embedded work.

WebDriver driver = new FirefoxDriver();
driver.get("http://localhost:8080/dwr/simpletext/index.html");

driver.selectElement("id=demoName").setValue("World");
driver.selectElement("id=demoSend").click();

// Give the browser a chance to do the onclick
Thread.sleep(500);

WebElement reply = driver.selectElement("id=demoReply");
assertEquals("Hello, World", reply.getText());

Scott McMaster has some more examples.

Just to be clear HtmlUnit has existed for a while, and it's great for testing the sunny day case where browsers work according to a spec. It's complete enough to be able to run DWR for example, but it won't help you test the weird corner cases. WebDriver helps by reusing the weirdness directly from the browsers.

Update: Patrick Lightbody points out that Selenium Remote Control does something similar. The core Selenium controller class actually looks to be more capable than the WebDriver version, I try it out to see if it embeds as well.



Re: Embedded Web Testing

Thanks for sharing this tool Joe ;) Web unit testing was a nightmare, maybe not any more... I'll try ! Regards, Thomas

Re: Embedded Web Testing

hey joe it is impossible to just quickly submit a bug to dwr. one page leads to the other and i never get to where i can just type and paste my error log and short question.. eyal AT u812.net

Add a comment Send a TrackBack