1 HTTPUNIT Lauri Peterson Technology Partners, Inc

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
The Web Warrior Guide to Web Design Technologies
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
DT211/3 Internet Application Development JSP: Processing User input.
Forms cs105. More Interactive web-pages So far what we have seen was to present the information. (Ex: tables. Lists,….). But it is not enough. We want.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
Basic HTML. Guide to HTML code Not case sensitive Use tag for formatting output: new line, paragraph, text size, color, font type, etc. Can be a single.
Dreamweaver Basics In this section you will learn how to:
Information Technology Center Hany Abdelwahab Computer Specialist.
There is a certain way that an HTML file should be set up. The HTML section declares a beginning and an ending. Within the HTML, there should be a HEAD.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Lesson 8 Creating Forms with JavaScript
CST JavaScript Validating Form Data with JavaScript.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
JavaScript Form Validation
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
HTML Forms/Events (Instructor Lesson) The Event model HTML Forms Custom Events 1.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Server vs Client-side validation. JavaScript JavaScript is an object-based language. JavaScript is based on manipulating objects by modifying an object’s.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
HTML, XHTML, and CSS Chapter 12 Creating and Using XML Documents.
Execution Environment for JavaScript " Java Script Window object represents the window in which the browser displays documents. " The Window object provides.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 6.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
© 2010 Delmar, Cengage Learning Chapter 8 Collecting Data with Forms.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
ITCS373: Internet Technology Lecture 5: More HTML.
JavaScript - A Web Script Language Fred Durao
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
7 Chapter Seven Client-side Scripts. 7 Chapter Objectives Create HTML forms Learn about client-side scripting languages Create a client-side script using.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
INTRODUCTORY GUIDE TO SURPLUS LINE INFORMATION PORTAL 2.0 (SLIP) CALIFORNIA’S ELECTRONIC FILING SYSTEM THE SURPLUS LINE ASSOCIATION OF CALIFORNIA Quick.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Website Forms / Data Acquisition.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
Introduction to HTML. _______________________________________________________________________________________________________________ 2 Outline Key issues.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
HTTPUNIT. 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.
Unit 2 — The Exciting World of JavaScript Lesson 7 — Creating Forms with JavaScript.
HTML Creating Forms on a Web Page. 2 Objectives  Discuss the process of creating a form  Distinguish between data input controls and text input controls.
Basic HTML.
Quick Test Professional 9.2. Testing Process Preparing to Record Recording Enhancing a Test Debugging Running the Test and Analyzing the Results Reporting.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
1 Web Engineering Forms Lecture 05. FORMS Its how HTML does interactivity. There are quite new feature in HTML5. But the fundamental idea does not change.
Learning Aim C.  In this section we will look at how text, tables, forms and frames can be used in web pages.
Education And Training CTC IT DIVISION PivotLink User Training April 2010.
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
JavaScript, Third Edition 1 SELECTION LIST Demo. JavaScript, Third Edition 2 Description This web page will edit the slection to ensure an option was.
JavaScript, Sixth Edition
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
How to Write Web Forms By Mimi Opkins.
Basic XHTML Tables XHTML tables—a frequently used feature that organizes data into rows and columns. Tables are defined with the table element. Table.
Web Programming– UFCFB Lecture 17
Unit I: Collecting Data with Forms
Unit 27 - Web Server Scripting
© 2015, Mike Murach & Associates, Inc.
Presentation transcript:

1 HTTPUNIT Lauri Peterson Technology Partners, Inc

2 Topics Covered What is Httpunit WebConversation Simple example Working with forms Working with tables Web navigation Javascript When output is XML Demos ServletUnit Not Covered Summary

3 What Is Httpunit? Way to dynamically test web pages –Does a link take me to the right page? –Did the page render correctly? –Did Javascript enable the button? Java API for web interaction –WebWindow, WebForm, WebLink Browser emulation –Don’t need a browser running –Do need a web server (i.e. Apache/Tomcat) –Some support for Javascript

4 What Is Httpunit (cont)? Free! –Not perfect, but it is useful –Inconsistently named classes & methods –Javascript not fully supported Compliments JUnit tests –Black box testing –Automation of testing user interaction with web pages –Business logic should still be tested elsewhere ServletUnit test Servlets without container –Mocks out the servlet container

5 WebConversation Emulates the request/response WebConversation converstaion = new WebConversation(); WebRequest request = new PostMethodWebRequest(“URL”); WebResponse webResponse = conversation.getResponse(request); If web authorization is needed conversation.setAuthorization(“userName”, “password”); As when this is used in Apache: AuthType Basic AuthName “Please log in" AuthUserFile dir/user.pass require valid-user

6 Simple Example WebConversation converstaion = new WebConversation(); WebRequest request = new PostMethodWebRequest(" webResponse = conversation.getResponse(request); assertEquals("HTTPUnit Example: Intro Page 1", webResponse.getTitle()); //get raw HTML for the page so we can check for some basic things we are expecting String pageText = webResponse.getText(); assertTrue(pageText.indexOf("Intro Page 1") > -1); // also want to make sure some special formatting was there assertTrue(pageText.indexOf(" HTTPUnit Example: Intro Page 1 ") > -1); // may want to test that some thing (like an error message?) does NOT appear on the screen assertTrue(pageText.indexOf("Fatal error occurred:") == -1); // if order of information on the screen was important int locationOfString1 = pageText.indexOf("Intro Page 1"); int locationOfString2 = pageText.indexOf("Different Kinds of Form Inputs"); assertTrue((locationOfString1 > -1) && (locationOfString1 < locationOfString2)); Tests see if text is on page or not

7 Forms – 3 ways to find it WebForm formFromArray = webResponse.getForms()[0]; assertNotNull(formFromArray); // or modify your html to add id= to the form tag // WebForm formFromId = webResponse.getFormWithID(FORM_ID); assertNotNull(formFromId); // or modify your html to add name= to the form tag // WebForm formFromName = webResponse.getFormWithName("FormName"); assertNotNull(formFromName); If you know the order the forms appear on the page By name or id where possible

8 Forms - Text Looks just like HttpRequest // assertEquals("", webForm.getParameterValue(“textInput”)); assertTrue(webForm.isTextParameter(“textInput”)); assertFalse(webForm.isDisabledParameter(“textInput”)); assertFalse(webForm.isReadOnlyParameter(“textInput”)); Values can be modified too webForm.setParameter(“textInput”, "newValue"); assertEquals("newValue", webForm.getParameterValue(“textInput”));

9 Forms – Text (cont) Disabled and Readonly too // assertEquals("this is disabled", webForm.getParameterValue("textInputDisabled")); assertTrue(webForm.isTextParameter("textInputDisabled")); assertTrue(webForm.isDisabledParameter("textInputDisabled")); assertTrue(webForm.isReadOnlyParameter("textInputDisabled")); //??? webForm.setParameter("textInputDisabled", "newValue"); // assertEquals("this is readonly", webForm.getParameterValue("textInputReadonly")); assertTrue(webForm.isTextParameter("textInputReadonly")); assertFalse(webForm.isDisabledParameter("textInputReadonly")); assertTrue(webForm.isReadOnlyParameter("textInputReadonly")); webForm.setParameter("textInputReadonly", "newValue"); Why? Wrong!

10 Forms – password & hidden Just like a text field // assertEquals("", webForm.getParameterValue("passwordInput")); assertTrue(webForm.isTextParameter("passwordInput")); webForm.setParameter("passwordInput", "newValue"); assertEquals("newValue", webForm.getParameterValue("passwordInput")); // assertEquals("hiddenValue", webForm.getParameterValue("hiddenInput")); assertTrue(webForm.isHiddenParameter("hiddenInput")); assertFalse(webForm.isReadOnlyParameter("hiddenInput")); //??? webForm.setParameter(HIDDEN_INPUT, "newValue"); Why? Wrong!

11 Forms - checkboxes Has own setter method using setParameter throws an exception // check box 1 // check box 2 // check box 3 assertEquals("true", webForm.getParameterValue("checkBoxInput1")); webForm.setParameter("checkBoxInput1", "false"); webForm.setCheckbox("checkBoxInput1", false); assertEquals(null, webForm.getParameterValue("checkBoxInput1")); Wrong!

12 Forms – checkboxes (cont) When names are the same // 1 // 2 // 3 assertEquals("checkBoxA", webForm.getParameterValue("aCheckbox")); assertEquals(3, webForm.getParameterValues("aCheckbox").length); webForm.setCheckbox("aCheckbox", "checkBoxB", false); String[] nowChecked = webForm.getParameterValues("aCheckbox"); assertEquals("checkBoxA", nowChecked[0]); assertEquals("checkBoxC", nowChecked[1]); webForm.setCheckbox("aCheckbox", false); Works, but just Get first value?? Extra param Throws exception

13 Forms – radio buttons No special setter for radio buttons // radio button 1 // radio button 2 assertEquals("radio1", webForm.getParameterValue("radioInput")); webForm.setParameter("radioInput", "radio2"); assertEquals("radio2", webForm.getParameterValue("radioInput")); webForm.setParameter("radioInput", "junk"); String[] tryToSetBoth = {"radio1", "radio2"}; webForm.setParameter("radioInput", tryToSetBoth); webForm.setCheckbox("radioInput", "radio1", true); Throws exceptions

14 Forms – Select // // Option Number 1 // Option Number 2 // Option Number 3 // assertEquals("", webForm.getParameterValue("selectSingle")); assertFalse(webForm.isMultiValuedParameter("selectSingle")); webForm.setParameter("selectSingle", "opt2"); assertEquals("opt2", webForm.getParameterValue("selectSingle")); webForm.setParameter(("selectSingle", "junk"); webForm.setParameter("selectSingle", ""); String[] tryToSetTwo = {"opt1", "opt2"}; webForm.setParameter(("selectSingle", tryToSetTwo); Didn’t like this: Wrong!

15 Forms – Select (cont) // // Option Number 1 // Option Number 2 // Option Number 3 assertEquals("", webForm.getParameterValue("selectMultiple")); assertEquals(1, webForm.getParameterValues("selectMultiple").length); assertTrue(webForm.isMultiValuedParameter("selectMultiple")); webForm.setParameter("selectMultiple", "opt2"); String[] currentValues = webForm.getParameterValues("selectMultiple"); assertEquals(1, currentValues.length); assertEquals("opt2", currentValues[0]); webForm.setParameter("selectMultiple", {"opt1", "opt2"}); currentValues = webForm.getParameterValues("selectMultiple"); assertEquals(2, currentValues.length); Didn’t like this: Changes, does not add to selection Select all at once

16 Forms - TextArea Treats as a single string // assertEquals("", webForm.getParameterValue("textArea")); assertTrue(webForm.isTextParameter("textArea")); webForm.setParameter("textArea", "newValue\nline 2"); assertEquals("newValue\nline 2", webForm.getParameterValue("textArea"));

17 Forms - buttons Many ways to find the button Button buttonById = webForm.getButtonWithID("resetButtonId"); Button[] allButtons = webForm.getButtons(); Button buttonByName = webForm.getSubmitButton("submitButtonName"); Button buttonById = webForm.getSubmitButtonWithID("submitButtonId"); In the order they appear on the form, But that is not stated in the documentation Why Button instead of WebButton? Why no getButtonWithName? Special forms for submit buttons Shouldn’t this be getSubmitButtonWithName?

18 Forms - submit Button click – must refresh WebResponse Button buttonByName = webForm.getSubmitButton("submitButtonName"); buttonByName.click(); webResponse = conversation.getCurrentPage(); Form submit – returns WebResponse webResponse = webForm.submit(); webForm.submit(buttonByName); // if there is more than 1 submit button on the form Must get a handle to the New WebResponse

19 Tables Multiple ways to find a table WebTable[] allTables = webResponse.getTables(); assertEquals(2, allTables.length); WebTable tableData1 = allTables[0]; WebTable tableData4 = webResponse.getTableWithID("tableId"); WebTable tableData2 = webResponse.getTableStartingWith("first table, first row, column 1"); WebTable tableData3 = webResponse.getTableStartingWithPrefix("first table"); In the order they appear on the page By value of the first part of the first cell By value of the first cell Why no getTableWithName?

20 Tables - cells Better way to test data order String value1 = tableData.getCellAsText(2,2)); String value2 = tableData.getCellAsText(3,2)); Can also check table format TableCell cell = tableData.getTableCell(2,2); assertEquals(1, cell.getRowSpan()); assertEquals(1, cell.getColSpan()); Index is zero based

21 Navigation - links Find the link by the text WebLink link = webResponse.getLinkWith(“text that user sees on the screen"); webResponse = link.click(); Button.click did not return the webResponse But link does…

22 Navigation (cont) When the new page opens in a new browser window // buttonByName.click(); webResponse = conversation.getCurrentPage(); WebWindow[] windows = conversation.getOpenWindows(); assertEquals(2, windows.length); webResponse = windows[1].getCurrentPage(); webResponse = conversation.getOpenWindow("window2").getCurrentPage(); webResponse = webForm.submit(); the new response opened in a new window, but doing this just gives the original window Need to do this or this In this case this returns the new window

23 Javascript Support for window.alert function validateForm() { window.alert("this is a javascript alert!"); return false; } assertEquals("this is a javascript alert!", conversation.popNextAlert()); Returns “” (empty string) when there are no alerts

24 Javascript Support for window.open function openWindow(url) { window.open(url, "dialog", "width=200,height=150,status=no,resizable=no,top=200,left=200"); } simple dialog WebLink link = webResponse.getLinkWith("simple dialog"); webResponse = link.click(); webResponse = getNewlyOpenedBrowserWindow(); // my convenience method WebForm webForm = webResponse.getFormWithID(“formId); webForm.getButtonWithID("close me").click(); WebWindow[] windows = conversation.getOpenWindows(); assertEquals(1, windows.length); In this case it does NOT return the new window

25 XML responses Will return the XML in DOM format Document dom = webResponse.getDOM(); NodeList nodeList = dom.getElementsByTagName("item1"); …

26 Other Features Support for cookies Support for frames

27 Other tidbits Forget to start webserver Changes to test do not require redeploy Changes to source code DO Forgetting conversation.getCurrentPage Compression bug // get: java.io.EOFException: Unexpected end of ZLIB input stream conversation.getClientProperties().setAcceptGzip(false); For example in apache: SetOutputFilter DEFLATE

28 More Info Httpunit.sourceforge.net Cookbook FAQ Javadocs