background preloader

Testing

Facebook Twitter

Hamcrest - Hamcrest - library of matchers for building test expressions. DbUnit - About DbUnit. Infinitest. HtmlUnit - Getting Started with HtmlUnit. Introduction The dependencies page lists all the jars that you will need to have in your classpath. The class com.gargoylesoftware.htmlunit.WebClient is the main starting point. This simulates a web browser and will be used to execute all of the tests. Most unit testing will be done within a framework like JUnit so all the examples here will assume that we are using that. In the first sample, we create the web client and have it load the homepage from the HtmlUnit website. Imitating a specific browser Often you will want to simulate a specific browser. Specifying this BrowserVersion will change the user agent header that is sent up to the server and will change the behavior of some of the JavaScript. Finding a specific element Once you have a reference to an HtmlPage, you can search for a specific HtmlElement by one of 'get' methods, or by using XPath.

Below is an example of finding a 'div' by an ID, and getting an anchor by name: Using a proxy server Submitting a form. HttpUnit Cookbook. Here is a brief description of how you can use HttpUnit with JUnit to test your own web sites. Obtaining a web page response The center of HttpUnit is the WebConversation class, which takes the place of a browser talking to a single site. It is responsible for maintaining session context, which it does via cookies returned by the server.

To use it, one must create a request and ask the WebConversation for a response. For example: WebConversation wc = new WebConversation(); WebRequest req = new GetMethodWebRequest( " ); WebResponse resp = wc.getResponse( req ); The response may now be manipulated either as pure text (via the getText() method), as a DOM (via the getDOM() method), or by using the various other methods described below. WebConversation wc = new WebConversation(); WebResponse resp = wc.getResponse( " ); Examining and following links Image links can be found as well.

Using the table structure of a web page. Selenium web application testing system.