Using HttpUnit

First Download Apache from http://tomcat.apache.org/download-70.cgi.

Configure Apache for Eclipse by following the below steps:

 

 

(i)Go to Windows->Preferences->Servers->RunTime Environment.

(ii)Click Add->Apache Tomcat v7.0 and specify Tomcat Installation Directory.

After this start the server as below:

Go to Windows->Show View->Servers.

You will be able to see Tomcat Server.Start this server.

Once done create a new Project as Web Dynamic Project.

Create the below example.jsp

<%@ page language=”java” contentType=”text/html; charset=ISO-8859-1″
pageEncoding=”ISO-8859-1″%>
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”&gt;
<html>
<head>
<title>I am Example 1</title>
</head>
<body>
<p>Example 1: Welcome to the example 1.</p>
</body>
</html>

 

Now create a new test file test.java:

 

package test;
import com.meterware.httpunit.*;

public class test {

public static void main(String[] args) {

try
{

WebConversation wc=new WebConversation();
WebRequest request=new GetMethodWebRequest(“http://localhost:8080/temp/example.jsp&#8221;);
WebResponse response=wc.getResource(request);
System.out.println(“Title of the page is “+response.getTitle());
System.out.println(“Response of the page is “+response.getResponseMessage());
System.out.println(“URL of the page is “+response.getURL());
}

catch(Exception e)
{
System.out.println(“Exception is “+e);
}

}

}

 

Compile and run the file.

 

You should see the below output:

Title of the page is I am Example 1
Response of the page is OK
URL of the page is http://localhost:8080/temp/example.jsp

 

 

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s