⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 documentscriptingtest.java

📁 这是远程web服务调用的一个包,可以将JSP直接作为服务
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public void testHashDestinationOnEvent() throws Exception {        defineResource(  "OnCommand.html",  "<html><head></head>" +                                            "<body>" +                                            "<form name='realform'><input name='color' value='blue'></form>" +                                            "<a href='#' onClick=\"document.realform.color.value='green';\">green</a>" +                                            "</body></html>" );        WebConversation wc = new WebConversation();        WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" );        WebForm form = response.getFormWithName( "realform" );        WebLink link = response.getLinks()[0];        assertEquals( "initial parameter value", "blue", form.getParameterValue( "color" ) );        response = link.click();        assertEquals( "changed parameter value", "green", response.getFormWithName( "realform" ).getParameterValue( "color" ) );    }    public void testLinkProperties() throws Exception {        defineResource( "somewhere.html?with=values", "you made it!" );        defineResource(  "OnCommand.html",  "<html><head></head>" +                                            "<body>" +                                            "<a name=target href='nowhere.html'>" +                                            "<a name=control href='#' onClick=\"document.target.href='somewhere.html?with=values';\">green</a>" +                                            "</body></html>" );        WebConversation wc = new WebConversation();        WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" );        WebLink link = response.getLinkWithName( "target" );        assertEquals( "initial value", "nowhere.html", link.getURLString() );        response.getLinkWithName( "control" ).click();        assertEquals( "changed reference", getHostPath() + "/somewhere.html?with=values", link.getRequest().getURL().toExternalForm() );        response = link.click();        assertEquals( "New page", "you made it!", response.getText() );    }    public void testLinkIndexes() throws Exception {        defineResource(  "OnCommand.html",  "<html><head><script language='JavaScript'>" +                                            "function alertLinks() { " +                                            "  for (var i=0; i < document.links.length; i++) {" +                                            "    alert( document.links[i].href );" +                                            "  }" +                                            "}" +                                            "</script></head>" +                                            "<body onLoad='alertLinks()'>" +                                            "<a href='demo.html'>green</a>" +                                            "<map name='map1'>" +                                            "  <area href='guide.html' alt='Guide' shape='rect' coords='0,0,118,28'>" +                                            "  <area href='search.html' alt='Search' shape='circle' coords='184,200,60'>" +                                            "</map>" +                                            "<a href='sample.html'>green</a>" +                                            "</body></html>" );        WebConversation wc = new WebConversation();        wc.getResponse( getHostPath() + "/OnCommand.html" );        assertEquals( "Alert message", getHostPath() + "/demo.html", wc.popNextAlert() );        assertEquals( "Alert message", getHostPath() + "/guide.html", wc.popNextAlert() );        assertEquals( "Alert message", getHostPath() + "/search.html", wc.popNextAlert() );        assertEquals( "Alert message", getHostPath() + "/sample.html", wc.popNextAlert() );        assertNull( "Alert should have been removed", wc.getNextAlert() );    }    public void testDocumentFindImages() throws Exception {        defineResource(  "OnCommand.html",  "<html><head><script language='JavaScript'>" +                                            "function getFound( object ) {\n" +                                            "  return (object == null) ? \"did not find \" : \"found \";\n" +                                            "  }\n" +                                            "function viewImages() { \n" +                                            "  alert( \"found \" + document.images.length + \" images(s)\" );\n" +                                            "  alert( getFound( document.realimage ) + \"image 'realimage'\" )\n;" +                                            "  alert( getFound( document.images['realimage'] ) + \"image 'images[realimage]'\" )\n;" +                                            "  alert( getFound( document.noimage ) + \"image 'noimage'\" );\n" +                                            "  alert( document.images[1].name ); }\n" +                                            "</script></head>\n" +                                            "<body onLoad='viewImages()'>\n" +                                            "<img name='realimage' src='pict1.gif'>\n" +                                            "<img name='2ndimage' src='pict2.gif'>\n" +                                            "</body></html>" );        WebConversation wc = new WebConversation();        wc.getResponse( getHostPath() + "/OnCommand.html" );        assertEquals( "Alert message", "found 2 images(s)", wc.popNextAlert() );        assertEquals( "Alert message", "found image 'realimage'", wc.popNextAlert() );        assertEquals( "Alert message", "found image 'images[realimage]'", wc.popNextAlert() );        assertEquals( "Alert message", "did not find image 'noimage'", wc.popNextAlert() );        assertEquals( "Alert message", "2ndimage", wc.popNextAlert() );        assertNull( "Alert should have been removed", wc.getNextAlert() );    }    public void testImageSwap() throws Exception {        defineResource(  "OnCommand.html",  "<html><head></head>" +                                            "<body>" +                                            "<img name='theImage' src='initial.gif'>" +                                            "<a href='#' onMouseOver=\"document.theImage.src='new.jpg';\">green</a>" +                                            "</body></html>" );        WebConversation wc = new WebConversation();        WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" );        WebImage image = response.getImageWithName( "theImage" );        WebLink link = response.getLinks()[0];        assertEquals( "initial image source", "initial.gif", image.getSource() );        link.mouseOver();        assertEquals( "changed image source", "new.jpg", image.getSource() );    }    public void testWriteToNewDocument() throws Exception {        defineWebPage( "OnCommand", "<a href='#' onclick=\"window.open( '', 'empty' );w = window.open( '', 'sample' );w.document.open( 'text/plain' ); w.document.write( 'You made it!' );w.document.close()\" >" );        WebConversation wc = new WebConversation();        WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" );        WebLink link = response.getLinks()[0];        link.click();        WebWindow ww = wc.getOpenWindow( "sample");        assertEquals( "Generated page", "You made it!", ww.getCurrentPage().getText() );        assertEquals( "Content Type", "text/plain", ww.getCurrentPage().getContentType() );        link.click();        assertEquals( "Generated page", "You made it!", ww.getCurrentPage().getText() );        assertEquals( "Empty page", "", wc.getOpenWindow("empty").getCurrentPage().getText() );    }    public void testSetDocumentReparse() throws Exception {        defineResource( "index.html",                        "<html><head>" +                        "<script language='JavaScript ' >document.title = 'New title';</script>" +                        "</head><body><form name=\"aForm\"></form>" +                        "<script language='JavaScript'>alert(\"No of forms: \" + document.forms.length);</script>" +                        "</body></html>");        WebConversation wc = new WebConversation();        WebResponse response = wc.getResponse( getHostPath() + "/index.html" );        assertEquals("No of forms", response.getForms().length, 1);        assertEquals("JavaScript no of forms", "No of forms: 1", wc.popNextAlert());    }    public void testTagProperty() throws Exception {        defineResource( "start.html",                "<html><head><script language='JavaScript'>" +                "function showFormsCount(oDOM){   " +                "   var forms = oDOM.getElementsByTagName('form');" +                "   for( i = 0; i < forms.length; i++) {" +                "     alert( 'form with number ' + i + ' has ' + forms[i].getElementsByTagName('input').length + ' inputs' );" +                "   }" +                "}" +                "function showAll() {" +                "    showFormsCount(document);" +                "}" +                "</script></head><body onLoad='showAll();'>" +                "<a href='somewhere' name='there' title=second>here</a>" +                "<form name='perform1' title=fifth><input type='text' name='input' title='input1'></form>" +                "<form name='perform2' title=fifth><input type='text' name='input' title='input1'>" +                "<input type='hidden' name='input' title='input2'><input type='submit' name='doIt' title=sixth></form>" +                "</body></html>"                        );        WebConversation wc = new WebConversation();        wc.getResponse( getHostPath() + "/start.html" );        assertElementTags( wc, "0", "1");        assertElementTags( wc, "1", "3");    }    private void assertElementTags( WebConversation wc, String number, final String counts) {        assertEquals( "form '" + number + "' message", "form with number " + number + " has " + counts +" inputs", wc.popNextAlert() );    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -