[Webtest] Cannot make verifyNoDialogs work for simple submit button+alert box

Paul King Paul King <paulk@asert.com.au>
Wed, 06 Dec 2006 07:09:01 +1000


Why are you expecting it to fail?

Paul.

java@herr-der-mails.de wrote:
> Hi,
> 
> thanks for the reply and your time. Looks like I have to add a "expectDialog" element before clickButton !?;  but still the ant build succeeds - I think it should fail.
> 
> Here's an updated version of my test. The two files are a complete test, so if you have time, you can try them out.
> 
> build file localTest.xml:
> 
> <project name="InstallationCheck" basedir="." default="all">
> 
>     <property name="webtest.home" value="/temp/webtest"/>
>     <import file="${webtest.home}/lib/taskdef.xml"/>
> 
>     <target name="all" depends="mayPrintANTError, checkWebTest"/>
> 
>     <target name="checkWebTest">
>         <echo message="webtest.home is ${webtest.home}"/>
>         <webtest name="Test">
>             <config
>                 host=""
>                 port="0"
>                 basepath=""
>                 summary="false"
>                 saveresponse="false"
>                 haltonfailure="true"
>                 protocol="file"/>
>             <steps>
>                 <enableJavaScript enable="true"/>
> 
>                 <invoke url="${basedir}/localTest.html"/>
>                 <verifyText text="Test"/>
> 
>                 <selectForm name="TestForm"/>
> 
> 		<expectDialog dialogType="alert" saveProperty="simpleDialog" />
> 		
>                 <clickButton name="TestButton"/>
> 
>                 <verifyNoDialogs description="Check alert dialog was used" />
>             </steps>
>         </webtest>
>     </target>
> 
>     <target name="checkANT">
>         <available classname="org.apache.tools.ant.ProjectComponent"
>             property="ant.version.ok"/>
>     </target>
> 
>     <target name="mayPrintANTError" unless="ant.version.ok" depends="checkANT">
>         <echo message="You have a non-compliant version of ANT"/>
>         <echo message="Consider moving WEBTESTHOME/lib/ant.jar"/>
>         <echo message="to ANT_HOME/lib."/>
>     </target>
> 
> </project>
> 
> 
> HTML localTest.html:
> 
> <html>
>   <head>
>     <script LANGUAGE="JAVASCRIPT">
> 	    function buttonClick() {
> 	    	alert ("buttonClick called");
> 	    	return false;
>     	}
>     </script>
>   </head>
> 
>   <body>
>     <form name="TestForm" action="TestResult.html" method="post">
>       <input name="TestButton" type="submit" value="TestButton" onClick="return buttonClick();">
>     </form>
>   </body>
> </html>
> 
> 
> Paul King wrote:
> 
>> verifyNoDialogs should be used in conjunction with expectDialog or expectDialogs.
>> I couldn't see one in your test after a quick scan. Because the test is automated,
>> you provide ahead of time an expected user response so that for complicated dialogs
>> you can test out various behaviours, e.g. hitting the OK vs the Cancel button.
>> For your simple dialog, there isn't a wide range of behaviours available but
>> you still need to provide the expectation. For more details, check out:
>>
>> http://webtest.canoo.com/webtest/manual/expectDialog.html
>>
>> The expectation is simply placed before the action which will fire off
>> the JavaScript that triggers the dialog. (If you are into Agile development
>> this technique is very similar to a concept called mocking).
>>
>> Cheers, Paul.
>>
>> java@herr-der-mails.de wrote:
>>
>>> Hi,
>>>
>>> it's actually a prettry simple test, but I cannot make it work. I've tried both canoo 2.1 and the latest snapshot.
>>>
>>> The below given test should fail in my opinion, but it does not. The HTML page simply has a button which will call a function onClick(). This function always opens an alert dialog. Thus, verifyNoDialogs should fail, but it doesn't.
>>>
>>> Any help is greatly appreciated.
>>>
>>> <html>
>>>   <head>
>>>     <script LANGUAGE="JAVASCRIPT">
>>>         function buttonClick() {
>>>             alert ("buttonClick called");
>>>             return false;
>>>         }
>>>     </script>
>>>   </head>
>>>
>>>   <body>
>>>     <form name="TestForm" action="TestResult.html" method="post">
>>>       <input name="TestButton" type="submit" value="TestButton" onClick="return buttonClick();">
>>>     </form>
>>>   </body>
>>> </html>
>>>
>>> ----
>>>
>>> <project name="InstallationCheck" basedir="." default="all">
>>>
>>>     <property name="webtest.home" value="/temp/canoo-2.1"/>
>>>     <import file="${webtest.home}/lib/taskdef.xml"/>
>>>
>>>     <target name="all" depends="mayPrintANTError, checkWebTest"/>
>>>
>>>     <target name="checkWebTest">
>>>         <echo message="webtest.home is ${webtest.home}"/>
>>>         <webtest name="Test">
>>>             <config
>>>                 host=""
>>>                 port="0"
>>>                 basepath=""
>>>                 summary="false"
>>>                 saveresponse="false"
>>>                 haltonfailure="true"
>>>                 protocol="file"/>
>>>             <steps>
>>>                 <enableJavaScript enable="true"/>
>>>
>>>                 <invoke url="${basedir}/localTest.html"/>
>>>                 <verifyText text="Test"/>
>>>
>>>                 <selectForm name="TestForm"/>
>>>
>>>         <verifyNoDialogs description="Check alert dialog was used" />
>>>                 <clickButton name="TestButton"/>
>>>                 <verifyNoDialogs description="Check alert dialog was used" />
>>>             </steps>
>>>         </webtest>
>>>     </target>
>>>
>>>     <target name="checkANT">
>>>         <available classname="org.apache.tools.ant.ProjectComponent"
>>>             property="ant.version.ok"/>
>>>     </target>
>>>
>>>     <target name="mayPrintANTError" unless="ant.version.ok" depends="checkANT">
>>>         <echo message="You have a non-compliant version of ANT"/>
>>>         <echo message="Consider moving WEBTESTHOME/lib/ant.jar"/>
>>>         <echo message="to ANT_HOME/lib."/>
>>>     </target>
>>>
>>> </project>
>>>
>> _______________________________________________
>> WebTest mailing list
>> WebTest@lists.canoo.com
>> http://lists.canoo.com/mailman/listinfo/webtest
>>
>>
>