[Httpunit-commit] CVS: httpunit/test/com/meterware/httpunit/javascript ScriptingTest.java,1.15,1.16
Brought to you by:
russgold
From: Russell G. <rus...@us...> - 2002-08-21 19:06:30
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv25069/test/com/meterware/httpunit/javascript Modified Files: ScriptingTest.java Log Message: Added support for prompt() and confirm() Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- ScriptingTest.java 20 Aug 2002 15:09:28 -0000 1.15 +++ ScriptingTest.java 21 Aug 2002 19:06:27 -0000 1.16 @@ -57,6 +57,47 @@ } + public void testConfirmationDialog() throws Exception { + defineWebPage( "OnCommand", "<a href='NextPage' id='go' onClick='return confirm( \"go on?\" );'>" ); + defineResource( "NextPage", "Got the next page!" ); + + WebConversation wc = new WebConversation(); + WebResponse wr = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.setDialogResponder( new DialogAdapter() { + public boolean getConfirmation( String confirmationPrompt ) { + assertEquals( "Confirmation prompt", "go on?", confirmationPrompt ); + return false; + } + } ); + wr.getLinkWithID( "go" ).click(); + assertEquals( "Current page", wr, wc.getCurrentPage() ); + wc.setDialogResponder( new DialogAdapter() ); + wr.getLinkWithID( "go" ).click(); + assertEquals( "Page after confirmation", "Got the next page!", wc.getCurrentPage().getText() ); + } + + + public void testPromptDialog() throws Exception { + defineWebPage( "OnCommand", "<a href='NextPage' id='go' onClick='return \"yes\" == prompt( \"go on?\", \"no\" );'>" ); + defineResource( "NextPage", "Got the next page!" ); + + WebConversation wc = new WebConversation(); + WebResponse wr = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wr.getLinkWithID( "go" ).click(); + assertEquals( "Current page", wr, wc.getCurrentPage() ); + + wc.setDialogResponder( new DialogAdapter() { + public String getUserResponse( String prompt, String defaultResponse ) { + assertEquals( "Confirmation prompt", "go on?", prompt ); + assertEquals( "Default response", "no", defaultResponse ); + return "yes"; + } + } ); + wr.getLinkWithID( "go" ).click(); + assertEquals( "Page after confirmation", "Got the next page!", wc.getCurrentPage().getText() ); + } + + public void testFunctionCallOnLoad() throws Exception { defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + "<!-- " + |