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

java@herr-der-mails.de java@herr-der-mails.de
Thu, 07 Dec 2006 14:34:53 +0100


Hi Paul,

way cooool - that works. I still have to understand why, but the groovy stuff does what I want.

I've added my code; feel free to do with it whatever you want..

Thanks again for you time and advice
Holger

<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/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"/>

		<groovy>
			import com.canoo.webtest.extension.dialogs.DialogHelper
			import com.canoo.webtest.engine.StepFailedException
			if (DialogHelper.getExpectedDialogsCount(step.context) == 0) {
   				throw new StepFailedException("Unexpected dialog")
			}	
		</groovy> 
            </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>


Paul King wrote:

>
> Ok, I think I understand what you are trying to achieve now. It is not the
> usual way to use these steps.
>
> You could try placing an expectDialog step before your clickButton
> step. Set the dialogType to either "confirm" or "prompt". Now if an
> alert occurs, it will be the wrong type. Don't use verifyNoDialogs now
> as you should have a leftover expected one which you now just ignore.
> This isn't very elegant. It probably seems almost in reverse to what
> you would expect. Secondly, it doesn't stop the page from popping up
> prompt or confirm dialogs in the future.
> As an alternative, use an expectDialog with dialogType="alert".
> Then use the following Groovy code (untested) to check that the
> expected dialog wasn't triggered off.
>
> <groovy>
> import com.canoo.webtest.extension.dialogs.DialogHelper
> import com.canoo.webtest.engine.StepFailedException
> if (DialogHelper.getExpectedDialogsCount(getContext()) == 0) {
>    throw new StepFailedException("Expected an untriggered dialog but none found!", this)
> }
> </groovy>
>
> Cheers, Paul.
>
> java@herr-der-mails.de wrote:
>
>> Hi Paul,
>>
>> maybe I am using the wrong step. What I want to do is ensure that no alert box (no dialog) has been opened. If you look at the html, it is always opening an alert box - that should cause the test to fail IMO.
>>
>> Thanks
>> Holger
>>
>>
>>> 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
>
>

-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer