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