Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // put these three files in the default package together
- // IFrameTests.java
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertNotNull;
- import java.net.URL;
- import org.junit.Test;
- import com.gargoylesoftware.htmlunit.BrowserVersion;
- import com.gargoylesoftware.htmlunit.WebClient;
- import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
- import com.gargoylesoftware.htmlunit.html.HtmlInlineFrame;
- import com.gargoylesoftware.htmlunit.html.HtmlPage;
- import com.gargoylesoftware.htmlunit.html.HtmlParagraph;
- public class IFrameTests {
- @Test
- public void testIFrameCreatedWithInnerHTML() throws Exception {
- WebClient client = new WebClient(BrowserVersion.FIREFOX_3);
- URL url = getClass().getResource("container.html");
- assertNotNull(url);
- HtmlPage page = client.getPage(url);
- HtmlAnchor theLink = (HtmlAnchor) page.getElementById("theLink");
- theLink.click();
- int remaining = page.getEnclosingWindow().getJobManager().waitForJobsStartingBefore(100);
- assertEquals(0, remaining);
- HtmlInlineFrame theIFrame = (HtmlInlineFrame) page.getElementById("theIFrame");
- HtmlPage enclosedPage = (HtmlPage) theIFrame.getEnclosedPage();
- HtmlParagraph theParagraph = (HtmlParagraph) enclosedPage.getElementById("theParagraph");
- assertNotNull(theParagraph);
- assertEquals("Hello, world!", theParagraph.getTextContent());
- }
- }
- /* container.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <title>Container</title>
- <script type="text/javascript">
- function main() {
- var receptacle = document.getElementById('receptacle');
- receptacle.innerHTML = '<iframe id="theIFrame" src="content.html"></iframe>';
- }
- </script>
- </head>
- <body>
- <div id="receptacle"></div>
- <p><a id="theLink" href="javascript:main();">Click Me</a></p>
- </body>
- </html>
- */
- /* content.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <title>Content</title>
- </head>
- <body>
- <p id="theParagraph">Hello, world!</p>
- </body>
- </html>
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement