Search in sources :

Example 6 with HtmlScript

use of com.gargoylesoftware.htmlunit.html.HtmlScript in project htmlunit by HtmlUnit.

the class JavaScriptEngineTest method externalScript.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("got here")
public void externalScript() throws Exception {
    final String html = "<html><head><title>foo</title><script src='/foo.js' id='script1'/>\n" + "</head><body>\n" + "<p>hello world</p>\n" + "<form name='form1'>\n" + "  <input type='text' name='textfield1' id='textfield1' value='foo' />\n" + "  <input type='text' name='textfield2' id='textfield2'/>\n" + "</form>\n" + "</body></html>";
    final String jsContent = "alert('got here');\n";
    getMockWebConnection().setResponse(new URL(URL_FIRST, "foo.js"), jsContent, "text/javascript");
    final HtmlPage page = loadPageWithAlerts(html);
    final HtmlScript htmlScript = page.getHtmlElementById("script1");
    assertNotNull(htmlScript);
}
Also used : HtmlScript(com.gargoylesoftware.htmlunit.html.HtmlScript) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) URL(java.net.URL) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Aggregations

HtmlScript (com.gargoylesoftware.htmlunit.html.HtmlScript)6 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)4 Formatter (java.util.Formatter)3 URL (java.net.URL)2 CollectingAlertHandler (com.gargoylesoftware.htmlunit.CollectingAlertHandler)1 WebClient (com.gargoylesoftware.htmlunit.WebClient)1 HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)1 HtmlDivision (com.gargoylesoftware.htmlunit.html.HtmlDivision)1 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)1 HtmlHeading2 (com.gargoylesoftware.htmlunit.html.HtmlHeading2)1 HtmlParagraph (com.gargoylesoftware.htmlunit.html.HtmlParagraph)1 HtmlSection (com.gargoylesoftware.htmlunit.html.HtmlSection)1 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)1 Alerts (com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 PlexusExtension.getTestFile (org.codehaus.plexus.testing.PlexusExtension.getTestFile)1 Test (org.junit.Test)1