17.08.2016 Views

Apache Maven 3 Cookbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 2<br />

}<br />

super.tearDown();<br />

protected DefaultSelenium createSeleniumClient(String url) throws<br />

Exception {<br />

return new DefaultSelenium("localhost", 4444, "*firefox", url);<br />

}<br />

}<br />

@Test<br />

public void testHelloWorld() throws Exception {<br />

try {<br />

selenium.open("http://localhost:8080/mywebapp/index.jsp");<br />

assertEquals("Hello, World", selenium.getText("//h1"));<br />

} catch (SeleniumException ex) {<br />

fail(ex.getMessage());<br />

throw ex;<br />

}<br />

}<br />

It's all set! Stir up that command line, navigate to the project base directory, and execute the<br />

following command:<br />

$ mvn integration-test<br />

How it works...<br />

If you look at the preceding configuration, the Selenium and Jetty plugins are configured to<br />

start in the pre-integration test phase. Thus, when the integration-test build phase is reached,<br />

Jetty and Selenium are ready and available.<br />

Now the execution of our test case begins. In the setup(), we create a Selenium client.<br />

The client is the used in the test case testHelloWorld() to load a web page and assert a<br />

simple condition, based on the response of that web page, thus simulating a user loading a<br />

web page on his / her browser and asserting a condition.<br />

See also<br />

Test driven development section in Chapter 2, Software Engineering Techniques<br />

43

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!