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.SimpleWebTestCase;
21 import org.htmlunit.junit.BrowserRunner;
22 import org.htmlunit.junit.annotation.Alerts;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25
26
27
28
29
30
31 @RunWith(BrowserRunner.class)
32 public class HtmlButtonInputTest extends SimpleWebTestCase {
33
34
35
36
37 @Test
38 @Alerts("foo")
39 public void click_onClick() throws Exception {
40 final String htmlContent = DOCTYPE_HTML
41 + "<html>\n"
42 + "<head></head>\n"
43 + "<body>\n"
44 + "<form id='form1' onSubmit='alert(\"bar\")'>\n"
45 + " <input type='button' name='button' id='button' onClick='alert(\"foo\")'>Push me</button>\n"
46 + "</form>\n"
47 + "</body></html>";
48
49 final List<String> collectedAlerts = new ArrayList<>();
50 final HtmlPage page = loadPage(htmlContent, collectedAlerts);
51 final HtmlButtonInput button = page.getHtmlElementById("button");
52
53 final HtmlPage secondPage = button.click();
54
55 assertEquals(getExpectedAlerts(), collectedAlerts);
56
57 assertSame(page, secondPage);
58 }
59 }