[Webtest] Browser support in Webtest/HTMLUnit

webtest@lists.canoo.com webtest@lists.canoo.com
Fri, 6 May 2005 20:09:37 +0530


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 s=
till shows me that the browser is IE!

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

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

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

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

</target>
</project>

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

The second alert message is always window.alert("Internet Explorer") even i=
f 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 al=
so 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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not that =
of Mastek Limited, unless specifically indicated to that effect. Mastek Lim=
ited does not accept any responsibility or liability for it. This e-mail an=
d attachments (if any) transmitted with it are confidential and/or privileg=
ed and solely for the use of the intended person or entity to which it is a=
ddressed. Any review, re-transmission, dissemination or other use of or tak=
ing of any action in reliance upon this information by persons or entities =
other than the intended recipient is prohibited. This e-mail and its attach=
ments have been scanned for the presence of computer viruses. It is the res=
ponsibility of the recipient to run the virus check on e-mails and attachme=
nts before opening them. If you have received this e-mail in error, kindly =
delete this e-mail from all computers.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~