From af6e75be99c0dd600583f1a2c42c64f9a89d7b66 Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Sun, 13 Dec 2015 23:19:50 +0100 Subject: Add JUnit3 based HtmlUnit-Testsuite --- .classpath | 23 +++++++ .settings/org.eclipse.wst.common.component | 4 +- lib/commons-codec-1.8.jar | Bin 0 -> 263865 bytes lib/commons-collections-3.2.1.jar | Bin 0 -> 575389 bytes lib/commons-io-2.4.jar | Bin 0 -> 185140 bytes lib/commons-lang3-3.1.jar | Bin 0 -> 315805 bytes lib/commons-logging-1.1.3.jar | Bin 0 -> 62050 bytes lib/cssparser-0.9.11.jar | Bin 0 -> 354562 bytes lib/htmlunit-2.13.jar | Bin 0 -> 1289147 bytes lib/htmlunit-core-js-2.13.jar | Bin 0 -> 1032764 bytes lib/httpclient-4.3.1.jar | Bin 0 -> 585602 bytes lib/httpcore-4.3.jar | Bin 0 -> 282160 bytes lib/httpmime-4.3.1.jar | Bin 0 -> 37078 bytes lib/jetty-http-8.1.12.v20130726.jar | Bin 0 -> 96042 bytes lib/jetty-io-8.1.12.v20130726.jar | Bin 0 -> 104233 bytes lib/jetty-util-8.1.12.v20130726.jar | Bin 0 -> 287536 bytes lib/jetty-websocket-8.1.12.v20130726.jar | Bin 0 -> 125946 bytes lib/nekohtml-1.9.19.jar | Bin 0 -> 124915 bytes lib/sac-1.3.jar | Bin 0 -> 15808 bytes lib/serializer-2.7.1.jar | Bin 0 -> 278281 bytes lib/xalan-2.7.1.jar | Bin 0 -> 3176148 bytes lib/xercesImpl-2.11.0.jar | Bin 0 -> 1367760 bytes lib/xml-apis-1.4.01.jar | Bin 0 -> 220536 bytes test/htmlunit/JCatalogTest.java | 101 +++++++++++++++++++++++++++++ 24 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 lib/commons-codec-1.8.jar create mode 100644 lib/commons-collections-3.2.1.jar create mode 100644 lib/commons-io-2.4.jar create mode 100644 lib/commons-lang3-3.1.jar create mode 100644 lib/commons-logging-1.1.3.jar create mode 100644 lib/cssparser-0.9.11.jar create mode 100644 lib/htmlunit-2.13.jar create mode 100644 lib/htmlunit-core-js-2.13.jar create mode 100644 lib/httpclient-4.3.1.jar create mode 100644 lib/httpcore-4.3.jar create mode 100644 lib/httpmime-4.3.1.jar create mode 100644 lib/jetty-http-8.1.12.v20130726.jar create mode 100644 lib/jetty-io-8.1.12.v20130726.jar create mode 100644 lib/jetty-util-8.1.12.v20130726.jar create mode 100644 lib/jetty-websocket-8.1.12.v20130726.jar create mode 100644 lib/nekohtml-1.9.19.jar create mode 100644 lib/sac-1.3.jar create mode 100644 lib/serializer-2.7.1.jar create mode 100644 lib/xalan-2.7.1.jar create mode 100644 lib/xercesImpl-2.11.0.jar create mode 100644 lib/xml-apis-1.4.01.jar create mode 100644 test/htmlunit/JCatalogTest.java diff --git a/.classpath b/.classpath index 0168508..931fd8a 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,7 @@ + @@ -12,5 +13,27 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 320180b..4c63d6e 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,8 +1,8 @@ - - + + diff --git a/lib/commons-codec-1.8.jar b/lib/commons-codec-1.8.jar new file mode 100644 index 0000000..32f84c9 Binary files /dev/null and b/lib/commons-codec-1.8.jar differ diff --git a/lib/commons-collections-3.2.1.jar b/lib/commons-collections-3.2.1.jar new file mode 100644 index 0000000..c35fa1f Binary files /dev/null and b/lib/commons-collections-3.2.1.jar differ diff --git a/lib/commons-io-2.4.jar b/lib/commons-io-2.4.jar new file mode 100644 index 0000000..90035a4 Binary files /dev/null and b/lib/commons-io-2.4.jar differ diff --git a/lib/commons-lang3-3.1.jar b/lib/commons-lang3-3.1.jar new file mode 100644 index 0000000..a85e539 Binary files /dev/null and b/lib/commons-lang3-3.1.jar differ diff --git a/lib/commons-logging-1.1.3.jar b/lib/commons-logging-1.1.3.jar new file mode 100644 index 0000000..ab51254 Binary files /dev/null and b/lib/commons-logging-1.1.3.jar differ diff --git a/lib/cssparser-0.9.11.jar b/lib/cssparser-0.9.11.jar new file mode 100644 index 0000000..49eea5c Binary files /dev/null and b/lib/cssparser-0.9.11.jar differ diff --git a/lib/htmlunit-2.13.jar b/lib/htmlunit-2.13.jar new file mode 100644 index 0000000..c233adb Binary files /dev/null and b/lib/htmlunit-2.13.jar differ diff --git a/lib/htmlunit-core-js-2.13.jar b/lib/htmlunit-core-js-2.13.jar new file mode 100644 index 0000000..ad61e8b Binary files /dev/null and b/lib/htmlunit-core-js-2.13.jar differ diff --git a/lib/httpclient-4.3.1.jar b/lib/httpclient-4.3.1.jar new file mode 100644 index 0000000..cdd1e38 Binary files /dev/null and b/lib/httpclient-4.3.1.jar differ diff --git a/lib/httpcore-4.3.jar b/lib/httpcore-4.3.jar new file mode 100644 index 0000000..ddfe6da Binary files /dev/null and b/lib/httpcore-4.3.jar differ diff --git a/lib/httpmime-4.3.1.jar b/lib/httpmime-4.3.1.jar new file mode 100644 index 0000000..2b26d7a Binary files /dev/null and b/lib/httpmime-4.3.1.jar differ diff --git a/lib/jetty-http-8.1.12.v20130726.jar b/lib/jetty-http-8.1.12.v20130726.jar new file mode 100644 index 0000000..30adfb5 Binary files /dev/null and b/lib/jetty-http-8.1.12.v20130726.jar differ diff --git a/lib/jetty-io-8.1.12.v20130726.jar b/lib/jetty-io-8.1.12.v20130726.jar new file mode 100644 index 0000000..e37e715 Binary files /dev/null and b/lib/jetty-io-8.1.12.v20130726.jar differ diff --git a/lib/jetty-util-8.1.12.v20130726.jar b/lib/jetty-util-8.1.12.v20130726.jar new file mode 100644 index 0000000..41a76e0 Binary files /dev/null and b/lib/jetty-util-8.1.12.v20130726.jar differ diff --git a/lib/jetty-websocket-8.1.12.v20130726.jar b/lib/jetty-websocket-8.1.12.v20130726.jar new file mode 100644 index 0000000..1b93315 Binary files /dev/null and b/lib/jetty-websocket-8.1.12.v20130726.jar differ diff --git a/lib/nekohtml-1.9.19.jar b/lib/nekohtml-1.9.19.jar new file mode 100644 index 0000000..979ffde Binary files /dev/null and b/lib/nekohtml-1.9.19.jar differ diff --git a/lib/sac-1.3.jar b/lib/sac-1.3.jar new file mode 100644 index 0000000..39b92b1 Binary files /dev/null and b/lib/sac-1.3.jar differ diff --git a/lib/serializer-2.7.1.jar b/lib/serializer-2.7.1.jar new file mode 100644 index 0000000..99f98db Binary files /dev/null and b/lib/serializer-2.7.1.jar differ diff --git a/lib/xalan-2.7.1.jar b/lib/xalan-2.7.1.jar new file mode 100644 index 0000000..458fa73 Binary files /dev/null and b/lib/xalan-2.7.1.jar differ diff --git a/lib/xercesImpl-2.11.0.jar b/lib/xercesImpl-2.11.0.jar new file mode 100644 index 0000000..0aaa990 Binary files /dev/null and b/lib/xercesImpl-2.11.0.jar differ diff --git a/lib/xml-apis-1.4.01.jar b/lib/xml-apis-1.4.01.jar new file mode 100644 index 0000000..4673346 Binary files /dev/null and b/lib/xml-apis-1.4.01.jar differ diff --git a/test/htmlunit/JCatalogTest.java b/test/htmlunit/JCatalogTest.java new file mode 100644 index 0000000..a1c8f40 --- /dev/null +++ b/test/htmlunit/JCatalogTest.java @@ -0,0 +1,101 @@ +package htmlunit; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; + +import junit.framework.TestCase; + +import org.xml.sax.SAXException; + +import com.gargoylesoftware.htmlunit.BrowserVersion; +import com.gargoylesoftware.htmlunit.BrowserVersionFeatures; +import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.HtmlAnchor; +import com.gargoylesoftware.htmlunit.html.HtmlForm; +import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput; +import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; +import com.gargoylesoftware.htmlunit.html.HtmlTextInput; + +public class JCatalogTest extends TestCase +{ + public void testWelcomePage() throws Exception + { + HtmlPage page = gotoHomePage(); + assertEquals("JCatalog Application", page.getTitleText()); + + List forms = (List) page.getForms(); + assertEquals(1, forms.size()); + assertEquals("navcontainer", forms.get(0).getId()); + } + + public void testLinkToLoginPage() throws Exception + { + HtmlPage response = navigateToLoginPage(); + assertEquals("JCatalog Login", response.getTitleText()); + } + + public void testLoginPage() throws Exception + { + HtmlPage response = login(); + assertEquals("JCatalog Welcome", response.getTitleText()); + } + + /** + * Test logout link, does not work correctly. + * + * @throws Exception + */ + public void testLogout() throws Exception + { + HtmlPage response = login(); + HtmlAnchor login = response.getAnchorByText("Logout"); + //getFirstAnchorByText("Logout"); + response = (HtmlPage) login.click(); + // test fails, clicking on links with href="#" seems not to work + // unfortunately JSF generates lots of them :-( + assertEquals("JCatalog Application", response.getTitleText()); + } + + private HtmlPage gotoHomePage() throws FailingHttpStatusCodeException, + IOException + { + WebClient webClient = new WebClient(BrowserVersion.CHROME); +// webClient.setJavaScriptEnabled(true); + //webClient.setRedirectEnabled(true); // does not work :-( + URL url = new URL("http://localhost:8080/JCatalog/pages/home.jsf"); + return (HtmlPage) webClient.getPage(url); + } + + private HtmlPage navigateToLoginPage() throws MalformedURLException, + IOException, SAXException + { + // HtmlPage response = gotoHomePage(); + // HtmlAnchor login = response.getFirstAnchorByText("Login"); + // return (HtmlPage) login.click(); + WebClient webClient = new WebClient(); + //webClient.setRedirectEnabled(true); // does not work :-( + URL url = new URL("http://localhost:8080/JCatalog/pages/login.jsf"); + return (HtmlPage) webClient.getPage(url); + } + + private HtmlPage login() throws MalformedURLException, IOException, + SAXException + { + HtmlPage response = navigateToLoginPage(); + HtmlForm form = response.getFormByName("loginForm"); + HtmlTextInput username = (HtmlTextInput) form + .getInputByName("loginForm:username"); + username.setValueAttribute("admin"); + HtmlPasswordInput password = (HtmlPasswordInput) form + .getInputByName("loginForm:password"); + password.setValueAttribute("masterkey"); + + HtmlSubmitInput button = (HtmlSubmitInput) form + .getInputByName("loginForm:submit"); + return (HtmlPage) button.click(); + } +} -- cgit v1.2.3-70-g09d2