Menu

How to click OK on a javascript confirm popup

kauffman
2007-08-24
2013-04-26
  • kauffman

    kauffman - 2007-08-24

    Hi all,

    I'm new using httpunit. I've to test a webpage that deletes an item. When you click on the delete button, a confirmation's popup is shown with two button (Accept and reject). To go on testing the whole website, I need to click on the accept button and I don't know how to do this. Could anyone help me please?

    Let me type some code to ilustrate the case.

    //This is the delete button as is written in the html's form tag

    buch of code
    <input type="button" class="button" value="delete" onclick="verify.onBorrar(this.form)"/>
    bunch of code

    //This is the javascript that handles the onclick event

    function verify_onBorrar(form){
        for(var i = 0;i<form.selection[i].length;i++){
            if(form.selection[i].checked){
                if(confirm('blablabla'){
                      form.action = 'ConsAlmBorrar.jsp?';
                      form.submit();
                }
             }
        }
    }
    verify.onBorrar = verify_onBorrar;

    note that selection is the name of a group of radio buttons

    With the httpunit java class that I've made, I'm able to select the item I want to delete, click on the delete button, and here is where the popup window appear and I can't go further.

    Thank you Indeed.

     
    • SmartParesh

      SmartParesh - 2008-01-07

      Hello
      I face the same problem.
      If u get solution to it.
      Please send me

      Thanks
      Bye

       
      • kauffman

        kauffman - 2008-01-08

        I gave up httpunit. I couldn´t solve the problem so I changed to another framework called Selenenium to test my web applications. Have a look to http://www.openqa.org/selenium/

         
    • Wolfgang Fahl

      Wolfgang Fahl - 2008-03-30

      Thank you for your feedback on httpunit - your message was posted in a period where the development of httpunit had slowed down to almost zero.
      The development community is gaining momentum again and the 1.7 and 2.0 releases are in the works. You might want to follow the developers mailing list to stay tuned. This forum was very seldomly looked at recently - but this may improve again now - so be encouraged to post again!

      Please find below the test case I added for your feedback - indeed the current javascript implementation handles the case a bit poorly. The new DomScripting engine in 2.0 is supposed to do much better - you might want to stay tuned.

      Yours Wolfgang

          /**
           * @see https://sourceforge.net/forum/forum.php?thread_id=1808696&forum_id=20294
           * by kauffman81
           */
          public void testJavaScriptConfirmPopUp() throws Exception {
              String target="<html><body>After click we want to see this!</body></html>";
            defineResource( "Target.html",  target);       
            defineResource( "Popup.html","<html><head><script language='JavaScript'>"+          
             "//     This is the javascript that handles the onclick event\n"+           
             "function verify_onBorrar(form){\n"+
             "  alert(form.id);\n"+      
             /* TODO check this javascript code
              * if uncommented it will throw
                com.meterware.httpunit.ScriptException: Event 'verify_onBorrar(this.form)' failed: org.mozilla.javascript.EcmaError: TypeError: Cannot read property "0" from undefined (httpunit#3)
             "    for(var i = 0;i<form.selection[i].length;i++){\n"+
             "        if(form.selection[i].checked){\n"+
             "            if(confirm('blablabla')){\n"+
             "                form.action = 'Target.html';\n"+ 
             "                form.submit(); \n"+
             "            } // if\n"+       
             "        } // if\n"+       
             "    } // for\n"+       
             */
             "} // verify_onBorrar\n"+       
             "</script></head>\n"+       
             "<body>\n"+
             "    <form id='someform' name='someform'>"+
             "        <input type='button' id='button1' class='button' value='say hi' onclick=\"alert('hi')\"/>"+
             "        <input type='button' id='delete' class='button' value='delete' onclick='verify_onBorrar(this.form)'/></form>\n"+
             "    </form>\n"+
             "</body></html>");
            WebConversation wc = new WebConversation();
            WebResponse response = wc.getResponse( getHostPath() + "/Popup.html" );
            Button button1 = (Button) response.getElementWithID( "button1" );
            button1.click();
            String alert1=wc.popNextAlert();
            assertEquals("hi",alert1);
            Button button2 = (Button) response.getElementWithID( "delete" );
            button2.click();
            String alert2=wc.popNextAlert();
            // TODO activate this check
            // System.err.println("alert 2 is "+alert2);
            // assertEquals("someform",alert2);
          }

       

Log in to post a comment.

Monday.com Logo