com.gargoylesoftware.htmlunit.html.HtmlButtonInput Java Examples
The following examples show how to use
com.gargoylesoftware.htmlunit.html.HtmlButtonInput.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaScriptEngineTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * Test case for bug 707134. Currently I am unable to reproduce the problem. * @throws Exception if the test fails */ @Test public void functionDefinedInSameFile() throws Exception { final String htmlContent = "<html><head><title>First</title><script>\n" + "function showFoo(foo) {\n" + " alert('Foo is: |' + foo + '|');\n" + "}\n" + "</script>\n" + "</head><body><form name='form1'>\n" + "<input name='text1' type='text'>\n" + "<input name='button1' type='button' onclick='showFoo(document.form1.text1.value);'>\n" + "</form></body></html>"; final List<String> collectedAlerts = new ArrayList<>(); final HtmlPage page = loadPage(htmlContent, collectedAlerts); assertEquals("First", page.getTitleText()); final HtmlForm form = page.getFormByName("form1"); final HtmlTextInput textInput = form.getInputByName("text1"); textInput.setValueAttribute("flintstone"); final HtmlButtonInput button = form.getInputByName("button1"); assertEquals(Collections.EMPTY_LIST, collectedAlerts); button.click(); assertEquals(new String[] {"Foo is: |flintstone|"}, collectedAlerts); }
Example #2
Source File: RawServerTest.java From wildfly-samples with MIT License | 5 votes |
@Test public void testEndpoint() throws IOException, ServletException, DeploymentException, InterruptedException { UndertowWebSocketServer server = new UndertowWebSocketServer(); server.start(); WebClient webClient = new WebClient(); HtmlPage page = webClient.getPage(BASE + "/index.html"); HtmlForm dataForm = page.getForms().get(0); HtmlButtonInput sendMessageButton = dataForm.getInputByName("button"); sendMessageButton.click(); System.out.println(page.getElementById("div").getTextContent()); server.stop(); }
Example #3
Source File: WebClientTest.java From htmlunit with Apache License 2.0 | 4 votes |
/** * Tests that the JavaScript parent scope is set correctly when shuffling windows around. * @throws Exception if test fails */ @Test public void maintainJavaScriptParentScope() throws Exception { final String basicContent = "<html><head>\n" + "<title>basicContentTitle</title>\n" + "</head><body>\n" + "<p>Hello World</p>\n" + "</body></html>"; final String jsContent = "<html><head>\n" + "<title>jsContentTitle</title>\n" + "<script>function foo() {alert('Ran Here')}</script>\n" + "<script>function bar() {}</script>\n" + "</head><body onload='bar()'>\n" + "<input type='button' id='button' onclick='foo()'/>" + "</body></html>"; final HtmlPage jsPage = loadPage(jsContent); final WebClient webClient = jsPage.getWebClient(); final WebWindow firstWindow = webClient.getCurrentWindow(); getMockConnection(jsPage).setResponse(URL_SECOND, basicContent); final CollectingAlertHandler alertHandler = new CollectingAlertHandler(); webClient.setAlertHandler(alertHandler); final HtmlButtonInput buttonBefore = jsPage.getHtmlElementById("button"); final WebWindow secondWindow = webClient.openWindow(null, "second window"); webClient.setCurrentWindow(secondWindow); webClient.getPage(URL_SECOND); webClient.setCurrentWindow(firstWindow); final HtmlPage currentPage = (HtmlPage) webClient.getCurrentWindow().getEnclosedPage(); final HtmlButtonInput buttonAfter = currentPage.getHtmlElementById("button"); assertSame(buttonBefore, buttonAfter); buttonAfter.click(); assertEquals(1, alertHandler.getCollectedAlerts().size()); assertEquals("Ran Here", alertHandler.getCollectedAlerts().get(0)); }
Example #4
Source File: WindowTest.java From htmlunit with Apache License 2.0 | 4 votes |
/** * Basic test for the <tt>showModelessDialog</tt> method. See bug #703. * @throws Exception if an error occurs */ @Test @Alerts(DEFAULT = "", IE = {"[object Window]", "a"}) public void showModelessDialog() throws Exception { final String html1 = "<html><head><script>\n" + " var userName = '';\n" + " function test() {\n" + " if (window.showModelessDialog) {\n" + " var newWindow = showModelessDialog('myDialog.html', window, 'status:false');\n" + " alert(newWindow);\n" + " }\n" + " }\n" + " function update() { alert(userName); }\n" + "</script></head><body>\n" + " <input type='button' id='b' value='Test' onclick='test()'>\n" + "</body></html>"; final String html2 = "<html><head><script>\n" + "function update() {\n" + " var w = dialogArguments;\n" + " w.userName = document.getElementById('name').value;\n" + " w.update();\n" + "}\n" + "</script></head><body>\n" + " Name: <input id='name'><input value='OK' id='b' type='button' onclick='update()'>\n" + "</body></html>"; final WebClient client = getWebClient(); final List<String> actual = new ArrayList<>(); client.setAlertHandler(new CollectingAlertHandler(actual)); final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, html1); conn.setResponse(new URL(URL_FIRST, "myDialog.html"), html2); client.setWebConnection(conn); final HtmlPage page = client.getPage(URL_FIRST); final HtmlElement button = page.getHtmlElementById("b"); final HtmlPage dialogPage = button.click(); if (!dialogPage.getUrl().equals(URL_FIRST)) { final HtmlInput input = dialogPage.getHtmlElementById("name"); input.setValueAttribute("a"); final HtmlButtonInput button2 = (HtmlButtonInput) dialogPage.getHtmlElementById("b"); button2.click(); assertEquals(getExpectedAlerts(), actual); } }