Download presentation
Presentation is loading. Please wait.
Published byCynthia Hamilton Modified over 8 years ago
1
HTTPUNIT
2
What is HTTPUNIT HttpUnit is an open source software testing framework used to perform testing of web sites without the need for a web browser. HttpUnit is an open source software testing framework used to perform testing of web sites without the need for a web browser. HttpUnit is primarily designed for "black-box" testing of web sites HttpUnit is primarily designed for "black-box" testing of web sites HttpUnit is free software available from [HttpUnitSite] that implements several useful unit testing methods together with classes for connecting to HTTP servers, processing HTML, and maintaining stateful sessions. HttpUnit is free software available from [HttpUnitSite] that implements several useful unit testing methods together with classes for connecting to HTTP servers, processing HTML, and maintaining stateful sessions.
3
BSD(Berkeley Software Distribution) license. BSD(Berkeley Software Distribution) license. Recent Version HttpUnit1.7 Recent Version HttpUnit1.7 JavaScript support is very basic at present. The near-term goal is full JavaScript 1.1 support. Currently, we do not plan to support browser-specific JavaScript. JavaScript support is very basic at present. The near-term goal is full JavaScript 1.1 support. Currently, we do not plan to support browser-specific JavaScript.
4
HttpUnit supports : o HTML form submission HTML o JavaScript JavaScript o automatic page redirection and cookies. cookies o Written in Java, HttpUnit allows Java test code to process returned pages as text, XML DOM, or containers of forms, tables and links JavaDOMJavaDOM
5
It is well suited to be used in combination with JUnit. It is well suited to be used in combination with JUnit.JUnit It easily write tests that verify the proper behaviour of a web site. It easily write tests that verify the proper behaviour of a web site. The use of HttpUnit allows for automated testing of web applications The use of HttpUnit allows for automated testing of web applications
6
The center of HttpUnit is the WebConversation class, which takes the place of a browser talking to a single site. The center of HttpUnit is the WebConversation class, which takes the place of a browser talking to a single site.WebConversation It is responsible for maintaining session context, which it does via cookies returned by the server. 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. To use it, one must create a request and ask the WebConversation for a response.request For Example: WebConversation wc = new WebConversation(); WebRequest req = new GetMethodWebRequest( "http://www.meterware.com/testpage.html" ); WebResponse resp = wc.getResponse( req );
7
The response may now be manipulated either as pure text (via the getText() method), as a DOM (via the getDOM() method) The response may now be manipulated either as pure text (via the getText() method), as a DOM (via the getDOM() method)response WebConversation wc = new WebConversation(); WebResponse resp = wc.getResponse( "http://www.meterware.com/testpage.html" ); WebConversation wc = new WebConversation(); WebResponse resp = wc.getResponse( "http://www.meterware.com/testpage.html" );
8
Some Drawbacks to HTTPUnit: Tests are tied to page structures. Tests are tied to page structures. If you change your page (say, reordering links or forms), you will break your tests. If you change your page (say, reordering links or forms), you will break your tests. Test assertions typically depend on the content of the page. Test assertions typically depend on the content of the page. If content changes, tests may break. If content changes, tests may break. Checking content is not completely sufficient for testing Grid portals. Checking content is not completely sufficient for testing Grid portals.
9
public WebConversation loginToPortal() throws Exception { //WebConversation objects are the cornerstone class. //WebConversation objects are the cornerstone class. WebConversation wc = new WebConversation(); WebConversation wc = new WebConversation(); //We will need to specify the user agent to simulate a browser. //We will need to specify the user agent to simulate a browser. ClientProperties cprops = wc.getClientProperties(); ClientProperties cprops = wc.getClientProperties(); cprops.setUserAgent("Mozilla/5.0"); cprops.setUserAgent("Mozilla/5.0"); WebResponse resp = wc.getResponse(portalUrl); WebResponse resp = wc.getResponse(portalUrl); // Find the login form. // Find the login form. // It's not named so we pick it out of an array // It's not named so we pick it out of an array String frontPage = resp.getText(); String frontPage = resp.getText();
10
//First make sure we are looking at the right web page. assertTrue("Failed to get front page", assertTrue("Failed to get front page", frontPage.indexOf("Please Login") != -1); frontPage.indexOf("Please Login") != -1); WebForm form = resp.getForms()[1]; WebForm form = resp.getForms()[1]; assertNotNull("No login form found", form); assertNotNull("No login form found", form); // Fill in form and submit // Fill in form and submit form.setParameter("userName", “admin”); form.setParameter("userName", “admin”); form.setParameter("password", “admin”); form.setParameter("password", “admin”); form.submit(); form.submit(); // Get logged in page // Get logged in page WebResponse resp2 = wc.getCurrentPage(); WebResponse resp2 = wc.getCurrentPage(); String page = resp2.getText(); String page = resp2.getText(); assertFalse("Failed to log in", assertFalse("Failed to log in", page.indexOf("Please Login") != -1); page.indexOf("Please Login") != -1); return wc; return wc; }
11
Assertion Statement Reference: There is the list of the different types of assertion statements that are used to test your code. Assertion Statement Reference: There is the list of the different types of assertion statements that are used to test your code. o assertNotNull("url: ", url, response) o assertFalse(message, condition) o assertNotNull(object) o assertNotSame(expected, actual) o assertNotSame(message, expected, actual) o assertNull(object) o assertNull(message, object) o assertSame(expected, actual) o assertSame(message, expected, actual) o assertTrue(condition) o assertTrue(message, condition) o fail() o fail(message)
12
Thank You
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.