List of usage examples for org.openqa.selenium WebDriver getTitle
String getTitle();
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElementTest.java
License:Apache License
/** * @throws Exception if an error occurs/* w w w .j ava 2 s . c o m*/ */ @Test public void dispatchEvent_submitOnFormChild() throws Exception { final String html = "<html><head><title>page 1</title></head><body>\n" + "<form action='page2'><span id='foo'/></form>\n" + "<script>\n" + "try {\n" + " var e = document.createEvent('HTMLEvents');\n" + " e.initEvent('submit', true, false);\n" + " document.getElementById('foo').dispatchEvent(e);\n" + "} catch(e) { alert('exception'); }\n" + "</script></body></html>"; final WebDriver webDriver = loadPageWithAlerts2(html); assertEquals("page 1", webDriver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElementTest.java
License:Apache License
/** * Regression test for https://sourceforge.net/tracker/?func=detail&aid=2022578&group_id=47038&atid=448266. * @throws Exception if the test fails// www. ja va2 s . co m */ @Test public void stackOverflowWithInnerHTML() throws Exception { final String html = "<html><head><title>Recursion</title></head>\n" + "<body>\n" + "<script>\n" + " document.body.innerHTML = unescape(document.body.innerHTML);\n" + "</script></body></html>"; final WebDriver webDriver = loadPageWithAlerts2(html); assertEquals("Recursion", webDriver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLFormElementTest.java
License:Apache License
/** * For IE8: calling form.submit() immediately triggers a request but only the * last response for a page is parsed./*from w w w .j a v a2 s . c o m*/ * For FF10+ and Chrome: only one request, the last one. * @throws Exception if the test fails */ @Test @Alerts(DEFAULT = { "", "foo4", "script4.js" }, IE = { "", "foo0", "foo1", "foo2", "foo3", "foo4", "script4.js" }) @NotYetImplemented({ FF, CHROME }) public void submitTriggersRequestNotParsed() throws Exception { final String html = "<html><head><script>\n" + "function test() {\n" + " var f = document.forms[0];\n" + " for (var i = 0; i < 5; i++) {\n" + " f.action = 'foo' + i;\n" + " f.submit();\n" + " }\n" + "}\n" + "</script></head><body onload='test()'>\n" + "<form>\n" + "<input name='foo'>\n" + "</form></body></html>"; final MockWebConnection connection = getMockWebConnection(); for (int i = 0; i < 5; i++) { final String htmlX = "<html><head>\n" + "<title>Page " + i + "</title>\n" + "<script src='script" + i + ".js'></script>\n" + "<script>alert('page" + i + "');</script>\n" + "</head></html>"; connection.setResponse(new URL(URL_FIRST, "foo" + i), htmlX); connection.setResponse(new URL(URL_FIRST, "script" + i + ".js"), "", JAVASCRIPT_MIME_TYPE); } final String[] expectedRequests = getExpectedAlerts(); setExpectedAlerts("page4"); final WebDriver driver = loadPageWithAlerts2(html); // forces to wait, what is needed for FFdriver // NB: comparing the sequence order here is not 100% safe with a real browser assertEquals(expectedRequests, getMockWebConnection().getRequestedUrls(URL_FIRST)); assertEquals("Page 4", driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLFrameElement2Test.java
License:Apache License
private void location(final String jsExpr) throws Exception { final String firstContent = "<html><head><title>first</title></head>\n" + "<frameset cols='*' onload='" + jsExpr + "'>\n" + " <frame name='Frame1' src='subdir/frame.html'>\n" + "</frameset></html>"; final String defaultContent = "<html><head><script>alert(location)</script></head></html>"; getMockWebConnection().setDefaultResponse(defaultContent); final WebDriver driver = loadPage2(firstContent); expandExpectedAlertsVariables(URL_FIRST); verifyAlerts(driver, getExpectedAlerts()); assertEquals("first", driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLFrameElement2Test.java
License:Apache License
/** * @throws Exception if the test fails/*from w ww . j a va 2 s . c o m*/ */ @Test @Alerts({ "OnloadTest", "header -> content -> frameSet", "content\nClick for new frame content with onload", "header -> content -> frameSet -> onloadFrame", "onloadFrame\nNew content loaded..." }) @NotYetImplemented public void windowLocationReplaceOnload() throws Exception { final String html = "<html><head><title>OnloadTest</title></head>\n" + "<frameset rows='50,*' onLoad=\"top.header.addToFrameOrder('frameSet');\">\n" + " <frame name='header' src='header.html'>\n" + " <frame name='content' id='content' " + "src=\"javascript:window.location.replace('content.html')\">\n" + "</frameset>\n" + "</html>"; final String headerFrame = "<html><head><title>headerFrame</title></head>\n" + "<script type='text/javascript'>\n" + " function addToFrameOrder(frame) {\n" + " var spacer = ' -> ';\n" + " var frameOrder = document.getElementById('frameOrder').innerHTML;\n" + " if (frameOrder == '') {spacer = '';}\n" + " document.getElementById('frameOrder').innerHTML = frameOrder + spacer + frame;\n" + " }\n" + "</script>\n" + "<body onload=\"addToFrameOrder('header');\">\n" + " <div id=\"frameOrder\"></div>\n" + "</body></html>"; final String contentFrame = "<html><head><title>contentFrame</title></head>\n" + "<body onload=\"top.header.addToFrameOrder('content');\">\n" + " <h3>content</h3>\n" + " <a name='onloadFrameAnchor' href='onload.html' " + "target='content'>Click for new frame content with onload</a>\n" + "</body></html>"; final String onloadFrame = "<html><head><title>onloadFrame</title></head>\n" + "<body onload=\"alert('Onload alert.');top.header.addToFrameOrder('onloadFrame');\">\n" + " <script type='text/javascript'>\n" + " alert('Body alert.');\n" + " </script>\n" + " <h3>onloadFrame</h3>\n" + " <p id='newContent'>New content loaded...</p>\n" + "</body></html>"; getMockWebConnection().setResponse(new URL(URL_FIRST, "header.html"), headerFrame); getMockWebConnection().setResponse(new URL(URL_FIRST, "content.html"), contentFrame); getMockWebConnection().setResponse(new URL(URL_FIRST, "onload.html"), onloadFrame); final WebDriver driver = loadPage2(html); // top frame assertEquals(getExpectedAlerts()[0], driver.getTitle()); // header frame driver.switchTo().frame("header"); assertEquals(getExpectedAlerts()[1], driver.findElement(By.id("frameOrder")).getText()); // content frame driver.switchTo().defaultContent(); driver.switchTo().frame("content"); assertEquals(getExpectedAlerts()[2], driver.findElement(By.tagName("body")).getText()); driver.findElement(By.name("onloadFrameAnchor")).click(); final boolean ie = getBrowserVersion().isIE(); verifyAlerts(driver, "Body alert."); if (!ie) { verifyAlerts(driver, "Onload alert."); } driver.switchTo().defaultContent(); if (ie) { verifyAlerts(driver, "Onload alert."); } driver.switchTo().frame("header"); assertEquals(getExpectedAlerts()[3], driver.findElement(By.id("frameOrder")).getText()); driver.switchTo().defaultContent(); driver.switchTo().frame("content"); assertEquals(getExpectedAlerts()[4], driver.findElement(By.tagName("body")).getText()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLFrameElement2Test.java
License:Apache License
/** * @throws Exception if the test fails// www .j a v a 2 s . c o m */ @Test @Alerts({ "OnloadTest", "header -> content -> frameSet", "content\nClick for new frame content with onload", "header -> content -> frameSet -> onloadFrame", "onloadFrame\nNew content loaded..." }) @NotYetImplemented public void windowLocationAssignOnload() throws Exception { final String html = "<html><head><title>OnloadTest</title></head>\n" + "<frameset rows='50,*' onLoad=\"top.header.addToFrameOrder('frameSet');\">\n" + " <frame name='header' src='header.html'>\n" + " <frame name='content' id='content' " + "src=\"javascript:window.location.assign('content.html')\">\n" + "</frameset>\n" + "</html>"; final String headerFrame = "<html><head><title>headerFrame</title></head>\n" + "<script type='text/javascript'>\n" + " function addToFrameOrder(frame) {\n" + " var spacer = ' -> ';\n" + " var frameOrder = document.getElementById('frameOrder').innerHTML;\n" + " if (frameOrder == '') {spacer = '';}\n" + " document.getElementById('frameOrder').innerHTML = frameOrder + spacer + frame;\n" + " }\n" + "</script>\n" + "<body onload=\"addToFrameOrder('header');\">\n" + " <div id='frameOrder'></div>\n" + "</body></html>"; final String contentFrame = "<html><head><title>contentFrame</title></head>\n" + "<body onload=\"top.header.addToFrameOrder('content');\">\n" + " <h3>content</h3>\n" + " <a name='onloadFrameAnchor' href='onload.html' " + "target='content'>Click for new frame content with onload</a>\n" + "</body></html>"; final String onloadFrame = "<html><head><title>onloadFrame</title></head>\n" + "<body onload=\"alert('Onload alert.');top.header.addToFrameOrder('onloadFrame');\">\n" + " <script type='text/javascript'>\n" + " alert('Body alert.');\n" + " </script>\n" + " <h3>onloadFrame</h3>\n" + " <p id='newContent'>New content loaded...</p>\n" + "</body></html>"; getMockWebConnection().setResponse(new URL(URL_FIRST, "header.html"), headerFrame); getMockWebConnection().setResponse(new URL(URL_FIRST, "content.html"), contentFrame); getMockWebConnection().setResponse(new URL(URL_FIRST, "onload.html"), onloadFrame); final WebDriver driver = loadPage2(html); // top frame assertEquals(getExpectedAlerts()[0], driver.getTitle()); // header frame driver.switchTo().frame("header"); assertEquals(getExpectedAlerts()[1], driver.findElement(By.id("frameOrder")).getText()); // content frame driver.switchTo().defaultContent(); driver.switchTo().frame("content"); assertEquals(getExpectedAlerts()[2], driver.findElement(By.tagName("body")).getText()); driver.findElement(By.name("onloadFrameAnchor")).click(); final boolean ie = getBrowserVersion().isIE(); verifyAlerts(driver, "Body alert."); if (!ie) { verifyAlerts(driver, "Onload alert."); } driver.switchTo().defaultContent(); if (ie) { verifyAlerts(driver, "Onload alert."); } driver.switchTo().frame("header"); assertEquals(getExpectedAlerts()[3], driver.findElement(By.id("frameOrder")).getText()); driver.switchTo().defaultContent(); driver.switchTo().frame("content"); assertEquals(getExpectedAlerts()[4], driver.findElement(By.tagName("body")).getText()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLFrameElement2Test.java
License:Apache License
/** * @throws Exception if the test fails/*from w ww. j av a 2s.c o m*/ */ @Test @Alerts({ "OnloadTest", "header -> content -> frameSet", "content\nClick for new frame content with onload", "header -> content -> frameSet -> onloadFrame", "onloadFrame\nNew content loaded..." }) @NotYetImplemented public void windowLocationSetOnload() throws Exception { final String html = "<html><head><title>OnloadTest</title></head>\n" + "<frameset rows='50,*' onLoad=\"top.header.addToFrameOrder('frameSet');\">\n" + " <frame name='header' src='header.html'>\n" + " <frame name='content' id='content' " + "src=\"javascript:window.location='content.html'\">\n" + "</frameset>\n" + "</html>"; final String headerFrame = "<html><head><title>headerFrame</title></head>\n" + "<script type='text/javascript'>\n" + " function addToFrameOrder(frame) {\n" + " var spacer = ' -> ';\n" + " var frameOrder = document.getElementById('frameOrder').innerHTML;\n" + " if (frameOrder == '') {spacer = '';}\n" + " document.getElementById('frameOrder').innerHTML = frameOrder + spacer + frame;\n" + " }\n" + "</script>\n" + "<body onload=\"addToFrameOrder('header');\">\n" + " <div id='frameOrder'></div>\n" + "</body></html>"; final String contentFrame = "<html><head><title>contentFrame</title></head>\n" + "<body onload=\"top.header.addToFrameOrder('content');\">\n" + " <h3>content</h3>\n" + " <a name='onloadFrameAnchor' href='onload.html' " + "target='content'>Click for new frame content with onload</a>\n" + "</body></html>"; final String onloadFrame = "<html><head><title>onloadFrame</title></head>\n" + "<body onload=\"alert('Onload alert.');top.header.addToFrameOrder('onloadFrame');\">\n" + " <script type='text/javascript'>\n" + " alert('Body alert.');\n" + " </script>\n" + " <h3>onloadFrame</h3>\n" + " <p id='newContent'>New content loaded...</p>\n" + "</body></html>"; getMockWebConnection().setResponse(new URL(URL_FIRST, "header.html"), headerFrame); getMockWebConnection().setResponse(new URL(URL_FIRST, "content.html"), contentFrame); getMockWebConnection().setResponse(new URL(URL_FIRST, "onload.html"), onloadFrame); final WebDriver driver = loadPage2(html); // top frame assertEquals(getExpectedAlerts()[0], driver.getTitle()); // header frame driver.switchTo().frame("header"); assertEquals(getExpectedAlerts()[1], driver.findElement(By.id("frameOrder")).getText()); // content frame driver.switchTo().defaultContent(); driver.switchTo().frame("content"); assertEquals(getExpectedAlerts()[2], driver.findElement(By.tagName("body")).getText()); if (StringUtils.isNotEmpty(getExpectedAlerts()[2])) { driver.findElement(By.name("onloadFrameAnchor")).click(); driver.switchTo().defaultContent(); driver.switchTo().frame("header"); assertEquals(getExpectedAlerts()[3], driver.findElement(By.id("frameOrder")).getText()); driver.switchTo().defaultContent(); driver.switchTo().frame("content"); assertEquals(getExpectedAlerts()[4], driver.findElement(By.tagName("body")).getText()); } }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLInputElementTest.java
License:Apache License
/** * Test that field delegates submit to the containing form. * @throws Exception if the test fails/*from w w w. j a va 2s .com*/ */ @Test public void onChangeCallsFormSubmit() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "</head>\n" + "<body>\n" + " <form name='test' action='foo'>\n" + " <input name='field1' onchange='submit()'>\n" + " <img src='unknown.gif'>\n" + " </form>\n" + "</body></html>"; getMockWebConnection().setDefaultResponse("<html><title>page 2</title><body></body></html>"); final WebDriver driver = loadPage2(html); driver.findElement(By.name("field1")).sendKeys("bla"); driver.findElement(By.tagName("img")).click(); assertEquals("page 2", driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.Location2Test.java
License:Apache License
/** * Test for <tt>replace</tt>. * @throws Exception if the test fails// w w w . java2s . com */ @Test public void replace() throws Exception { final String html = "<html><head><title>First</title><script>\n" + "function doTest() {\n" + " location.replace('" + URL_SECOND + "');\n" + "}\n" + "</script></head><body onload='doTest()'>\n" + "</body></html>"; final String secondContent = "<html><head><title>Second</title></head><body></body></html>"; getMockWebConnection().setResponse(URL_SECOND, secondContent); final WebDriver webdriver = loadPageWithAlerts2(html); assertEquals("Second", webdriver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.Location2Test.java
License:Apache License
/** * Test for <tt>replace</tt>. * @throws Exception if the test fails/* ww w.jav a 2 s. co m*/ */ @Test public void replaceLastInHistory() throws Exception { final String startContent = "<html><head><title>First Page</title></head><body></body></html>"; final String secondContent = "<html><head><title>Second Page</title><script>\n" + "function doTest() {\n" + " location.replace('" + URL_THIRD + "');\n" + "}\n" + "</script></head><body onload='doTest()'>\n" + "</body></html>"; final String thirdContent = "<html><head><title>Third Page</title></head><body></body></html>"; getMockWebConnection().setResponse(URL_SECOND, secondContent); getMockWebConnection().setResponse(URL_THIRD, thirdContent); final WebDriver webdriver = loadPageWithAlerts2(startContent); webdriver.get(URL_SECOND.toExternalForm()); assertEquals("Third Page", webdriver.getTitle()); // navigate back webdriver.navigate().back(); assertEquals("First Page", webdriver.getTitle()); }