1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.html;
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20 import org.htmlunit.HttpMethod;
21 import org.htmlunit.MockWebConnection;
22 import org.htmlunit.Page;
23 import org.htmlunit.SimpleWebTestCase;
24 import org.htmlunit.junit.BrowserRunner;
25 import org.htmlunit.util.NameValuePair;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28
29
30
31
32
33
34
35
36 @RunWith(BrowserRunner.class)
37 public class HtmlIsIndexTest extends SimpleWebTestCase {
38
39
40
41
42 @Test
43 public void formSubmission() throws Exception {
44 final String html
45 = "<html><head><title>foo</title></head><body>\n"
46 + "<form id='form1' method='post'>\n"
47 + " <isindex prompt='enterSomeText'></isindex>\n"
48 + " <input type='submit' id='clickMe'>\n"
49 + "</form></body></html>";
50 final HtmlPage page = loadPage(html);
51 final MockWebConnection webConnection = getMockConnection(page);
52
53 final HtmlForm form = page.getHtmlElementById("form1");
54
55 final HtmlElement element = form.getElementsByAttribute(
56 "isindex", "prompt", "enterSomeText").get(0);
57 if (element instanceof HtmlIsIndex) {
58 final HtmlIsIndex isInput = (HtmlIsIndex) element;
59 isInput.setValue("Flintstone");
60 final Page secondPage = page.getHtmlElementById("clickMe").click();
61
62 final List<NameValuePair> expectedParameters = new ArrayList<>();
63 expectedParameters.add(new NameValuePair("enterSomeText", "Flintstone"));
64
65 assertEquals("url", URL_FIRST, secondPage.getUrl());
66 assertSame("method", HttpMethod.POST, webConnection.getLastMethod());
67 assertEquals("parameters", expectedParameters, webConnection.getLastParameters());
68 }
69 }
70 }