2 messages in com.canoo.lists.webtest[Webtest] Browser support in Webtest/...
FromSent OnAttachments
nime...@mastek.com06 May 2005 07:39 
Marc Guillemot09 May 2005 00:23 
Subject:[Webtest] Browser support in Webtest/HTMLUnit
From:nime...@mastek.com (nime@mastek.com)
Date:05/06/2005 07:39:15 AM
List:com.canoo.lists.webtest

Hi,

Has anyone ran their scripts simulating Netscape as a browser?

When I am trying to playback the script even for Netscape as a browser it still
shows me that the browser is IE!

I have a sample HTML file whose source is <html> <head> <SCRIPT LANGUAGE="JavaScript"> function openWindow() { alert("Browser userAgent = " + navigator.userAgent); if(document.layers) { alert("Netscape browser"); } else if(document.all) { alert("Internet Explorer"); } } </SCRIPT> </head> <body> <FORM METHOD="POST" name="frmName"> <input type="button" name="hi" value = "ClickMe" onclick="openWindow();"> </FORM> </body> </html>

Webtest script as follows. <?xml version="1.0" encoding="UTF-8" ?>

<project name="CheckBrowser" basedir="." default="main"> <property name="webtest.home" value="${basedir}"/> <taskdef file="${webtest.home}/webtestTaskdefs.properties"> <classpath> <fileset dir="${webtest.home}" includes="**/lib/*.jar"/> <fileset dir="${webtest.home}/lib" includes="/*.jar"/> <fileset dir="${webtest.home}/lib" includes="**/optional/*.jar"/> <fileset dir="${webtest.home}/lib" includes="**/build/*.jar"/> </classpath> </taskdef> <target name="main"> <testSpec name="webtest test number 1"> <config host="localhost" port="8080" protocol="http" basepath="/" summary="true" saveresponse="true" resultpath="results" resultfile="TestResults.xml" > <header name="User-Agent" value="Mozilla/5.0 (Windows; U; Windows NT 5.0;
en-US;rv:0.9.4.1) Gecko/20020508 Netscape6/6.2.3"/> <!--<header name="User-Agent" value="4.0 (compatible; MSIE 6.0; Windows
98)"/>-->

</config> <steps> <invoke url="CheckBrowser.html" stepid=""/> <clickbutton label="ClickMe" stepid="Click the button" /> </steps> </testSpec>

</target> </project>

When I run the above script in debug mode I get Warnings for two alert messages.
Namely: [testSpec] WARN (com.gargoylesoftware.htmlunit.javascript.host.Window) -
window.alert("Browser userAgent = Mozilla/4.0 (compatible; MSIE 6.0b; Windows
98)") no alert handler installed [testSpec] WARN (com.gargoylesoftware.htmlunit.javascript.host.Window) -
window.alert("Internet Explorer") no alert handler installed

The second alert message is always window.alert("Internet Explorer") even if I
have set the User-Agent in the header as Netscape. In the debug mode it shows
that the browser being used is Netscape.

Can someone throw some light on this.

I am using release 1.7 (build 6xx) and htmlunit is of 03 Jan 2005.

My aim is to have one script and make it run as if the browser is IE and also
Netscape. So that with the help of the scripts I can easily check cross browser
compatibility of my application. Any solutions or ideas on this?

Thanks. Regards, - Nimesh

MASTEK "Making a valuable difference" Mastek in NASSCOM's 'India Top 20' Software Service Exporters List. In the US, we're called MAJESCO