Menu

Preseted-Parameter-Probs (TestCases availabl)

2003-05-13
2003-05-15
  • Jens Mühlenhoff

    Hello,

    first of all I was very pleased to note that in the 1.5.3 version the javascript which was placed in the href of a link worked. Thank you.

    But now we have problems with presetted-parameters. I have four testcases. The testcases without preseted parameters work and with preseted-parameters doesn't work.

    I'm glad on any hint to solve the problem.

    By

    Jens

        public void testSubmitGetWithHRefAndJavaScript() throws Exception
        {
            defineResource("DoIt?nr=0300000018", "You made it!");
            defineResource(
                "OnCommand.html",
                "<html><head><script language=JavaScript>"
                    + "  function nextPage(nr) {"
                    + "    window.document.formular.nr.value = nr;"
                    + "    window.document.formular.action='DoIt';"
                    + "    window.document.formular.submit ();"
                    + "}"
                    + "</script></head><body>"
                    + "<form name='formular' action=''>"
                    + "  <input type='hidden' name='nr' value='not set!' />"
                    + "</form>"
                    + "  <a href=\"javascript:nextPage('0300000018')\">0300000018</a>"
                    + "</body></html>");

            WebConversation wc = new WebConversation();
            WebResponse response = wc.getResponse(getHostPath() + "/OnCommand.html");
            response.getLinks()[0].click();
            assertEquals("Result of submit", "You made it!", wc.getCurrentPage().getText());
        }

        public void testSubmitGetWithHRefAndJavaScriptAndPresettedParameter() throws Exception
        {
            defineResource("DoIt?nr=0300000018", "You made it!");
            defineResource(
                "OnCommand.html?nr=0000000000",
                "<html><head><script language=JavaScript>"
                    + "  function nextPage(nr) {"
                    + "    window.document.formular.nr.value = nr;"
                    + "    window.document.formular.action='DoIt';"
                    + "    window.document.formular.submit ();"
                    + "}"
                    + "</script></head><body>"
                    + "<form name='formular' action=''>"
                    + "  <input type='hidden' name='nr' value='not set!' />"
                    + "</form>"
                    + "  <a id='go' href=\"javascript:nextPage('0300000018')\">0300000018</a>"
                    + "</body></html>");

            WebConversation wc = new WebConversation();
            WebResponse response = wc.getResponse(getHostPath() + "/OnCommand.html?nr=0000000000");
            response.getLinks()[0].click();
            assertEquals("Result of submit", "You made it!", wc.getCurrentPage().getText());
        }

        public void testSubmitPostWithHRefAndJavaScript() throws Exception
        {
            defineResource("/DoIt", new PseudoServlet()
            {
                public WebResource getPostResponse() throws IOException
                {

                    String[] nr = getParameter("nr");
                    assertEquals(1, nr.length);
                    return new WebResource(nr[0], "text/plain");
                }
            });

            defineResource(
                "OnCommand.html",
                "<html><head><script language=JavaScript>"
                    + "  function nextPage(nr) {"
                    + "    window.document.formular.nr.value = nr;"
                    + "    window.document.formular.action='DoIt';"
                    + "    window.document.formular.submit ();"
                    + "}"
                    + "</script></head><body>"
                    + "<form name='formular' action='' method='post'>"
                    + "  <input type='hidden' name='nr' value='not set!' />"
                    + "</form>"
                    + "  <a href=\"javascript:nextPage('0300000018')\">0300000018</a>"
                    + "</body></html>");

            WebConversation wc = new WebConversation();
            WebResponse response = wc.getResponse(getHostPath() + "/OnCommand.html");
            response.getLinks()[0].click();
            assertEquals("Result of submit", "0300000018", wc.getCurrentPage().getText());
        }

        public void testSubmitPostWithHRefAndJavaScriptAndPresettedParameter() throws Exception
        {
            defineResource("/DoIt", new PseudoServlet()
            {
                public WebResource getPostResponse() throws IOException
                {

                    String[] nr = getParameter("nr");
                    assertEquals(1, nr.length);
                    return new WebResource(nr[0], "text/plain");
                }
            });

            defineResource(
                "OnCommand.html?nr=0000000000",
                "<html><head><script language=JavaScript>"
                    + "  function nextPage(nr) {"
                    + "    window.document.formular.nr.value = nr;"
                    + "    window.document.formular.action='DoIt';"
                    + "    window.document.formular.submit ();"
                    + "}"
                    + "</script></head><body>"
                    + "<form name='formular' action='' method='post'>"
                    + "  <input type='hidden' name='nr' value='not set!' />"
                    + "</form>"
                    + "  <a href=\"javascript:nextPage('0300000018')\">0300000018</a>"
                    + "</body></html>");

            WebConversation wc = new WebConversation();
            WebResponse response = wc.getResponse(getHostPath() + "/OnCommand.html?nr=0000000000");
            response.getLinks()[0].click();
            assertEquals("Result of submit", "0300000018", wc.getCurrentPage().getText());
        }

     
    • Jens Mühlenhoff

      After several test I got the trouble maker. the problem occurrence in the following situation.

      - you call a side with a parameter seted, e.g. index.jsp?nr=000000

      - the called site cotains a form, which attribute action is set to an empty string

      - you call a javascript (no matter if with href or onclick) which set's some varibales and the action-field of the form.

      - every things works fine, if the action-attribute of the form ist set to something else than the empty-string

      I got several test-case which test'S several contitions. If any one is interested, give me a call. I will send them to you.

      After severl debug-sessions, I currently have no hint very the bug is.

      By Jens

       

Log in to post a comment.

Auth0 Logo