1 38 package com.gargoylesoftware.htmlunit.html; 39 40 import java.util.ArrayList; 41 import java.util.Arrays; 42 import java.util.List; 43 44 import com.gargoylesoftware.htmlunit.WebTestCase; 45 46 52 public class HtmlButtonInputTest extends WebTestCase { 53 58 public HtmlButtonInputTest( final String name ) { 59 super( name ); 60 } 61 62 63 66 public void testClick_onClick() throws Exception { 67 final String htmlContent 68 = "<html><head><title>foo</title></head><body>" 69 + "<form id='form1' onSubmit='alert(\"bar\")'>" 70 + " <input type='button' name='button' id='button' " 71 + "onClick='alert(\"foo\")'>Push me</button>" 72 + "</form></body></html>"; 73 final List collectedAlerts = new ArrayList(); 74 final HtmlPage page = loadPage(htmlContent, collectedAlerts); 75 final HtmlButtonInput button = ( HtmlButtonInput )page.getHtmlElementById( "button" ); 76 77 final HtmlPage secondPage = (HtmlPage)button.click(); 78 79 final List expectedAlerts = Arrays.asList( new String[]{"foo"} ); 80 assertEquals( expectedAlerts, collectedAlerts ); 81 82 assertSame( page, secondPage ); 83 } 84 } 85 | Popular Tags |