c# print barcode zebra DEVELOPING FOR THE WEB in Java

Drawing ECC200 in Java DEVELOPING FOR THE WEB

CHAPTER 1 2
DataMatrix Maker In Java
Using Barcode creator for Java Control to generate, create Data Matrix ECC200 image in Java applications.
www.OnBarcode.com
Data Matrix Reader In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
DEVELOPING FOR THE WEB
EAN-13 Supplement 5 Printer In Java
Using Barcode creation for Java Control to generate, create GS1 - 13 image in Java applications.
www.OnBarcode.com
Printing Barcode In Java
Using Barcode printer for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
going to write a few simple WebTest steps. The pages we will walk through are shown in figures 12.3 through 12.5.
Making UPC-A Supplement 2 In Java
Using Barcode creator for Java Control to generate, create UPC A image in Java applications.
www.OnBarcode.com
Print QR In Java
Using Barcode encoder for Java Control to generate, create QR Code JIS X 0510 image in Java applications.
www.OnBarcode.com
Figure 12.3 Login page of our example web application
Draw EAN13 In Java
Using Barcode creation for Java Control to generate, create EAN-13 Supplement 5 image in Java applications.
www.OnBarcode.com
Paint Leitcode In Java
Using Barcode drawer for Java Control to generate, create Leitcode image in Java applications.
www.OnBarcode.com
Figure 12.4 The search page of our web application. Note the powerful Google-like expression that is used for searching Ant s documentation.
Data Matrix Encoder In None
Using Barcode generator for Excel Control to generate, create ECC200 image in Office Excel applications.
www.OnBarcode.com
Making ECC200 In Java
Using Barcode generation for Java Control to generate, create ECC200 image in Java applications.
www.OnBarcode.com
Figure 12.5 The results page of our web application
Quick Response Code Generation In None
Using Barcode drawer for Software Control to generate, create QR Code JIS X 0510 image in Software applications.
www.OnBarcode.com
Read Code 128 Code Set B In C#.NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
As mentioned in section 12.6.6, writing HttpUnit tests is a low-level exercise and likely involves rework and recompilation when site navigation changes. WebTest provides a higher-level way to describe functional web tests. Listing 12.6 shows our build file to test these three pages.
Code 128 Code Set A Encoder In Java
Using Barcode generator for BIRT reports Control to generate, create Code 128 Code Set A image in Eclipse BIRT applications.
www.OnBarcode.com
Generate QR Code In Visual C#
Using Barcode maker for .NET framework Control to generate, create Quick Response Code image in Visual Studio .NET applications.
www.OnBarcode.com
Listing 12.6 WebTest example build file
Painting UCC.EAN - 128 In None
Using Barcode printer for Software Control to generate, create GTIN - 128 image in Software applications.
www.OnBarcode.com
GTIN - 128 Generator In None
Using Barcode encoder for Font Control to generate, create GS1 128 image in Font applications.
www.OnBarcode.com
<!DOCTYPE project [ <!ENTITY properties SYSTEM "file:../properties.xml"> ]> <project name="canoo" default="main"> &properties; <taskdef name="testSpec" classname="com.canoo.webtest.ant.TestSpecificationTask">
Creating Quick Response Code In None
Using Barcode printer for Font Control to generate, create Quick Response Code image in Font applications.
www.OnBarcode.com
EAN 13 Maker In C#.NET
Using Barcode encoder for VS .NET Control to generate, create EAN13 image in VS .NET applications.
www.OnBarcode.com
TESTING WEB APPLICATIONS WITH HTTPUNIT
Print Linear 1D Barcode In VB.NET
Using Barcode generator for Visual Studio .NET Control to generate, create Linear image in .NET applications.
www.OnBarcode.com
Make Barcode In Objective-C
Using Barcode encoder for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
<classpath> <fileset dir="${webtest.dist.dir}" includes="*.jar"/> </classpath> </taskdef> <property name="output.dir" location="build/canoo"/> <property name="xsl.file" location="xdocs/stylesheets/canoo.xsl"/> <property <property <property <property <property name="app.context" value="antbook"/> name="app.port" value="8080"/> name="app.host" value="localhost"/> name="app.username" value="erik"/> name="app.password" value="hatcher"/>
Defines the WebTest task
<property name="query" value="(http AND wait) -title:API"/> <property name="expected" value="WaitFor Task"/> <target name="init"> <mkdir dir="${output.dir}"/> </target> <target name="clean"> <delete dir="${output.dir}"/> </target> <target name="main"> <testSpec name="test our site"> Begins testing steps <config host="${app.host}" port="${app.port}" protocol="http" basepath="${app.context}" summary="true" verbose="false" saveresponse="true" resultpath="${output.dir}" haltonerror="true" haltonfailure="true"/> <steps> <invoke stepid="go to login page" url="login.jsp"/> <setinputfield stepid="set user name" name="username" value="${app.username}" /> <setinputfield stepid="set password" name="password" value="${app.password}" /> <clickbutton stepid="login" name="submit"/> <setinputfield stepid="set query" name="query" value="${query}"/> <clickbutton stepid="search" name="submit"/> <verifytext stepid="${expected} found" text="${expected}"/>
Defines default query and expected result
CHAPTER 1 2
DEVELOPING FOR THE WEB
</steps> </testSpec> <xslt basedir="${output.dir}" destdir="${output.dir}" includes="TestSummary*xml" extension=".html" style="${xsl.file}" /> </target> </project>
Transforms results into HTML
The <testSpec> task encapsulates a series of steps, and in our case the steps are:
1 2 3 4
Navigate to the login page. Fill in the username and password fields, then submit the form. Enter a query into the search form and submit it. Verify that the results page includes the expected text.
Ant properties are used to represent our query (${query}) and a string expected (${expected}) to be on the results page. We could easily rerun a test for a different query and expected result, for example:
> ant -f canoo.xml -Dquery="+steve +anger" -Dexpected="Ant in Danger"1 Buildfile: canoo.xml main: BUILD FAILED Failure: Test "test our site" failed at step "Ant in Danger found" with message "Step "Ant in Danger found" (8/9): Text not found in page. Expected <Ant in Danger>" Total time: 3 seconds
It is beyond the scope of this book to cover the Canoo s WebTest task in more detail. The WebTest distribution found at http://webtest.canoo.com contains robust documentation and examples. One of the very handy things that can be done with WebTest, thanks to Ant s XML build file format, is to transform another XML file into a complete WebTest build file or build file fragment. A friend of ours, David Eric Pugh, has done this very thing by automating the construction of functional test cases from a DBForms model into WebTest steps. DBForms2 is an open-source project to
The actual document is called Ant in Anger. http://www.dbforms.org
TESTING WEB APPLICATIONS WITH HTTPUNIT
generate Model-View-Controller-style JSP pages from an XML descriptor (which can be generated from database metadata). The <xslt> task, a task we will cover in chapter 13, is used to turn the results written from the <testSpec> task into an easily navigable HTML file. One of the great benefits to WebTest is its capturing of the pages as it executes the steps. It saves each page it encounters to a separate HTML file in the resultpath directory, allowing you to see exactly what WebTest sees as it is executing. Then, with the <xslt> task, Ant creates an index for all these pages for easy analysis.
SERVER-SIDE TESTING WITH CACTUS
Cactus is the Jakarta project s J2EE container unit testing framework for unit testing server-side code. It deals with the thorny issues of testing server-side code that is dependent upon container-provided services, ranging from J2EE to SQL database access. It deals with this in a way that is simpler to describe than to implement: by running all the unit tests on the server. For example, we have developed a utility method that returns a specific parameter or attribute from an HttpServletRequest object. This is a useful utility for cases where either the URL (or form POST) contains a parameter or it has been injected into the request scope attributes during server-side forwards. There is no single method to retrieve the parameter regardless of which of these two scopes it is in, so we have to write one:
package org.example.antbook; import javax.servlet.http.HttpServletRequest; public class RequestUtil { public static final String getValue (HttpServletRequest request, String key) { String value = request.getParameter(key); if (value != null) { return value; } value = (String) request.getAttribute(key); if (value != null) { return value; } return null; } }
Having written a class, we now need to test it. How can we test this class and its getValue method with JUnit There are two popular methods: Mock Objects and Cactus. Mock Objects are emulations of objects such as the servlet API, which you can then use inside normal <junit> tests to invoke code inside a mock server. They 310
Copyright © OnBarcode.com . All rights reserved.