List of usage examples for org.openqa.selenium WebDriver getTitle
String getTitle();
From source file:com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput2Test.java
License:Apache License
/** * @throws Exception if the test fails//from w w w . j a v a2 s. c o m */ @Test @Alerts("Second") public void setChecked() throws Exception { final String firstHtml = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title></head><body>\n" + "<form>\n" + "<input id='myCheckbox' type='checkbox' onchange=\"window.location.href='" + URL_SECOND + "'\">\n" + "</form>\n" + "</body></html>"; final String secondHtml = "<html><head><title>Second</title></head><body></body></html>"; getMockWebConnection().setDefaultResponse(secondHtml); final WebDriver driver = loadPage2(firstHtml); driver.findElement(By.id("myCheckbox")).click(); assertEquals(getExpectedAlerts()[0], driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput2Test.java
License:Apache License
/** * @throws Exception if the test fails/*from ww w . j av a2 s . co m*/ */ @Test @Alerts("Second") public void setChecked2() throws Exception { final String firstHtml = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title></head><body>\n" + "<form>\n" + "<input id='myCheckbox' type='checkbox' onchange=\"window.location.href='" + URL_SECOND + "'\">\n" + "<input id='myInput' type='text'>\n" + "</form>\n" + "</body></html>"; final String secondHtml = "<html><head><title>Second</title></head><body></body></html>"; getMockWebConnection().setDefaultResponse(secondHtml); final WebDriver driver = loadPage2(firstHtml); driver.findElement(By.id("myCheckbox")).click(); assertEquals(getExpectedAlerts()[0], driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlInlineFrame2Test.java
License:Apache License
/** * Test, the right frame is used for a target, even if some frames * have the same name.// w w w . ja v a2 s .co m * * @throws Exception if the test fails */ @Test public void targetResolution() throws Exception { final String framesContent = "<html><head><title>Top Page</title></head>\n" + "<body><div id='content'>Body of top frame</div>\n" + " <iframe src='left.html' id='id-left' name='left'></iframe>\n" + " <iframe src='right.html' id='id-right' name='right'></iframe>\n" + "</body>\n" + "</html>"; final String rightFrame = "<html><head><title>Right Frame</title></head>\n" + "<body><div id='content'>Body of right frame</div></body>\n" + "</html>"; final String leftFrame = "<html><head><title>Left Frame</title></head>\n" + "<body>\n" + " <div id='content'>Body of left frame</div>\n" + " <a id='link' name='link' href='new_inner.html' target='right'>Click link</a>\n" + " <iframe id='id-inner' name='right' width='100' height='100' src='inner.html'></iframe>\n" + "</body>\n" + "</html>"; final String innerFrame = "<html><head><title>Inner Frame</title></head>\n" + "<body><div id='content'>Body of inner frame</div></body>\n" + "</html>"; final String newInnerFrame = "<html><head><title>New inner Frame</title></head>\n" + "<body><div id='content'>Body of new inner frame</div></body>\n" + "</html>"; final String baseUrl = URL_FIRST.toString(); final URL leftFrameUrl = new URL(baseUrl + "left.html"); final URL rightFrameUrl = new URL(baseUrl + "right.html"); final URL innerFrameURL = new URL(baseUrl + "inner.html"); final URL newInnerFrameURL = new URL(baseUrl + "new_inner.html"); final MockWebConnection webConnection = getMockWebConnection(); webConnection.setResponse(leftFrameUrl, leftFrame); webConnection.setResponse(rightFrameUrl, rightFrame); webConnection.setResponse(innerFrameURL, innerFrame); webConnection.setResponse(newInnerFrameURL, newInnerFrame); final WebDriver driver = loadPage2(framesContent); // top frame assertEquals("Top Page", driver.getTitle()); assertEquals("Body of top frame", driver.findElement(By.id("content")).getText()); // left frame driver.switchTo().frame("id-left"); assertEquals("Body of left frame", driver.findElement(By.id("content")).getText()); // inner frame driver.switchTo().frame("id-inner"); assertEquals("Body of inner frame", driver.findElement(By.id("content")).getText()); // right frame driver.switchTo().defaultContent(); driver.switchTo().frame("id-right"); assertEquals("Body of right frame", driver.findElement(By.id("content")).getText()); // clicking on a link which contains a target 'right'. But this target frame is defined two times. driver.switchTo().defaultContent(); driver.switchTo().frame("id-left"); driver.findElement(By.id("link")).click(); // left frame driver.switchTo().defaultContent(); driver.switchTo().frame("id-left"); assertEquals("Body of left frame", driver.findElement(By.id("content")).getText()); // inner frame driver.switchTo().frame("id-inner"); assertEquals("Body of new inner frame", driver.findElement(By.id("content")).getText()); // right frame driver.switchTo().defaultContent(); driver.switchTo().frame("id-right"); assertEquals("Body of right frame", driver.findElement(By.id("content")).getText()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlPage3Test.java
License:Apache License
/** * @exception Exception If the test fails *//*w w w. j a v a2s .co m*/ @Test public void constructor() throws Exception { final String html = "<html>\n" + "<head><title>foo</title></head>\n" + "<body>\n" + "<p>hello world</p>\n" + "<form id='form1' action='/formSubmit' method='post'>\n" + " <input type='text' NAME='textInput1' value='textInput1'/>\n" + " <input type='text' name='textInput2' value='textInput2'/>\n" + " <input type='hidden' name='hidden1' value='hidden1'/>\n" + " <input type='submit' name='submitInput1' value='push me'/>\n" + "</form>\n" + "</body></html>"; final WebDriver driver = loadPageWithAlerts2(html); assertEquals("foo", driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput2Test.java
License:Apache License
/** * @throws Exception if the test fails/*w ww . j a v a2 s. com*/ */ @Test @Alerts("Second") public void setChecked() throws Exception { final String firstHtml = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title></head><body>\n" + "<form>\n" + "<input type='radio' name='radioGroup' id='radio'" + " onchange=\"window.location.href='" + URL_SECOND + "'\">\n" + "</form>\n" + "</body></html>"; final String secondHtml = "<html><head><title>Second</title></head><body></body></html>"; getMockWebConnection().setDefaultResponse(secondHtml); final WebDriver driver = loadPage2(firstHtml); driver.findElement(By.id("radio")).click(); assertEquals(getExpectedAlerts()[0], driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput2Test.java
License:Apache License
/** * @throws Exception if the test fails//from w w w. j ava 2 s . c o m */ @Test @Alerts("Second") public void setChecked2() throws Exception { final String firstHtml = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title></head><body>\n" + "<form>\n" + "<input type='radio' name='radioGroup' id='radio'" + " onchange=\"window.location.href='" + URL_SECOND + "'\">\n" + "<input id='myInput' type='text'>\n" + "</form>\n" + "</body></html>"; final String secondHtml = "<html><head><title>Second</title></head><body></body></html>"; getMockWebConnection().setDefaultResponse(secondHtml); final WebDriver driver = loadPage2(firstHtml); driver.findElement(By.id("radio")).click(); assertEquals(getExpectedAlerts()[0], driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlSubmitInputTest.java
License:Apache License
/** * @throws Exception if the test fails/* ww w. j av a 2 s .c om*/ */ @Test public void submit() throws Exception { final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1' method='post'>\n" + "<input type='submit' name='aButton' value='foo'/>\n" + "<input type='suBMit' name='button' value='foo'/>\n" + "<input type='submit' name='anotherButton' value='foo'/>\n" + "</form></body></html>"; final WebDriver wd = loadPageWithAlerts2(html); final WebElement button = wd.findElement(By.name("button")); button.click(); assertEquals("foo", wd.getTitle()); assertEquals(Collections.singletonList(new NameValuePair("button", "foo")), getMockWebConnection().getLastParameters()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlSubmitInputTest.java
License:Apache License
/** * @throws Exception if the test fails// w w w.j a va 2 s. com */ @Test public void click_onClick_JavascriptReturnsTrue() throws Exception { final String html = "<html><head><title>First</title></head><body>\n" + "<form name='form1' method='get' action='foo.html'>\n" + "<input name='button' type='submit' value='PushMe' id='button1'" + "onclick='return true'/></form>\n" + "</body></html>"; final String secondHtml = "<html><head><title>Second</title></head><body></body></html>"; getMockWebConnection().setResponse(new URL(URL_FIRST, "foo.html"), secondHtml); final WebDriver wd = loadPageWithAlerts2(html); final WebElement button = wd.findElement(By.id("button1")); button.click(); assertEquals("Second", wd.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlSubmitInputTest.java
License:Apache License
/** * @throws Exception if the test fails/*ww w . j a va2 s . c o m*/ */ @Test public void doubleSubmissionWithRedirect() throws Exception { final String html = "<html><body>\n" + "<script>\n" + "function submitForm(btn) {\n" + " btn.form.submit();\n" + " btn.disabled = true;\n" + "}\n" + "</script>\n" + "<form method='post' action='test'>\n" + " <input name='text' type='text'>\n" + " <input name='btn' type='submit' onclick='submitForm(this);'>\n" + "</form>\n" + "</body></html>"; final MockWebConnection mockWebConnection = getMockWebConnection(); final List<NameValuePair> redirectHeaders = Arrays.asList(new NameValuePair("Location", "/nextPage")); mockWebConnection.setResponse(new URL(URL_FIRST, "test"), "", 302, "Found", null, redirectHeaders); mockWebConnection.setResponse(new URL(URL_FIRST, "nextPage"), "<html><head><title>next page</title></head></html>"); final WebDriver wd = loadPageWithAlerts2(html); final WebElement input = wd.findElement(By.name("btn")); input.click(); assertEquals("next page", wd.getTitle()); assertEquals(3, mockWebConnection.getRequestCount()); }
From source file:com.gargoylesoftware.htmlunit.html.MalformedHtmlTest.java
License:Apache License
/** * Tests that wrong formed HTML code is parsed like browsers do. * @throws Exception if the test fails//from w w w.jav a 2 s .co m */ @Test @Alerts("12345") public void wrongHtml_TagBeforeHtml() throws Exception { final String html = "<div>\n" + "<html>\n" + "<head><title>foo</title>\n" + "<script>\n" + "var toto = 12345;\n" + "</script>\n" + "</head>\n" + "<body onload='alert(toto)'>\n" + "blabla" + "</body>\n" + "</html>"; final WebDriver webdriver = loadPageWithAlerts2(html); assertEquals("foo", webdriver.getTitle()); }