List of usage examples for org.openqa.selenium WebDriver getTitle
String getTitle();
From source file:com.gargoylesoftware.htmlunit.javascript.host.Window3Test.java
License:Apache License
/** * Variables that are defined inside JavaScript should be accessible through the * window object (ie window.myVariable). Test that this works. * @throws Exception if the test fails//ww w.j ava 2 s . c o m */ @Test @Alerts({ "parent.myVariable = second", "top.myVariable = first" }) public void javascriptVariableFromTopAndParentFrame() throws Exception { final URL urlThird = new URL(URL_FIRST, "third/"); final String firstContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title></head><body><script>\n" + "myVariable = 'first'" + " </script><iframe name='left' src='" + URL_SECOND + "'></iframe>\n" + "</body></html>"; final String secondContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>Second</title></head><body><script>\n" + "myVariable = 'second'" + " </script><iframe name='innermost' src='" + urlThird + "'></iframe>\n" + "</body></html>"; getMockWebConnection().setResponse(URL_SECOND, secondContent); final String thirdContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>Third</title><script>\n" + "myVariable = 'third';\n" + "function doTest() {\n" + "alert('parent.myVariable = ' + parent.myVariable);\n" + "alert('top.myVariable = ' + top.myVariable);\n" + "}\n" + "</script></head>\n" + "<body onload='doTest()'></body></html>"; getMockWebConnection().setResponse(urlThird, thirdContent); final WebDriver driver = loadPageWithAlerts2(firstContent); assertEquals("First", driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.Window3Test.java
License:Apache License
/** * Variables that are defined inside JavaScript should be accessible through the * window object (ie window.myVariable). Test that this works. * @throws Exception if the test fails//w ww . j a v a 2 s . co m */ @Test @Alerts({ "parent.second.myVariable = second", "parent.third.myVariable = third" }) public void javascriptVariableFromNamedFrame() throws Exception { final URL urlThird = new URL(URL_FIRST, "third/"); final URL urlFourth = new URL(URL_FIRST, "fourth/"); final String firstContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>first</title></head>\n" + "<frameset cols='20%,80%'>\n" + " <frameset rows='30%,70%'>\n" + " <frame src='" + URL_SECOND + "' name='second'>\n" + " <frame src='" + urlThird + "' name='third'>\n" + " </frameset>\n" + " <frame src='" + urlFourth + "' name='fourth'>\n" + "</frameset></html>"; final String secondContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>second</title></head><body><script>\n" + "myVariable = 'second';\n" + "</script><p>second</p></body></html>"; getMockWebConnection().setResponse(URL_SECOND, secondContent); final String thirdContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>third</title></head><body><script>\n" + "myVariable = 'third';\n" + "</script><p>third</p></body></html>"; getMockWebConnection().setResponse(urlThird, thirdContent); final String fourthContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>fourth</title></head><body onload='doTest()'><script>\n" + "myVariable = 'fourth';\n" + "function doTest() {\n" + "alert('parent.second.myVariable = ' + parent.second.myVariable);\n" + "alert('parent.third.myVariable = ' + parent.third.myVariable);\n" + "}\n" + "</script></body></html>"; getMockWebConnection().setResponse(urlFourth, fourthContent); final WebDriver driver = loadPageWithAlerts2(firstContent); assertEquals("first", driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.Window3Test.java
License:Apache License
/** * @throws Exception if the test fails/*w ww . ja v a 2 s . c o m*/ */ @Test @Alerts({ "fourth-second=URL2", "fourth-third=URL3" }) public void getFrameByName() throws Exception { final URL urlThird = new URL(URL_FIRST, "third/"); final URL urlFourth = new URL(URL_FIRST, "fourth/"); final String firstContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>first</title></head>\n" + "<frameset cols='20%,80%'>\n" + " <frameset rows='30%,70%'>\n" + " <frame src='" + URL_SECOND + "' name='second'>\n" + " <frame src='" + urlThird + "' name='third'>\n" + " </frameset>\n" + " <frame src='" + urlFourth + "' name='fourth'>\n" + "</frameset></html>"; final String secondContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>second</title></head><body><p>second</p></body></html>"; getMockWebConnection().setResponse(URL_SECOND, secondContent); final String thirdContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>third</title></head><body><p>third</p></body></html>"; getMockWebConnection().setResponse(urlThird, thirdContent); final String fourthContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>fourth</title></head><body onload='doTest()'><script>\n" + "function doTest() {\n" + "alert('fourth-second='+parent.second.document.location);\n" + "alert('fourth-third='+parent.third.document.location);\n" + "}\n" + "</script></body></html>"; getMockWebConnection().setResponse(urlFourth, fourthContent); final String[] expectedAlerts = getExpectedAlerts(); for (int i = 0; i < expectedAlerts.length; i++) { expectedAlerts[i] = expectedAlerts[i].replaceAll("URL2", URL_SECOND.toExternalForm()) .replaceAll("URL3", urlThird.toExternalForm()); } setExpectedAlerts(expectedAlerts); final WebDriver driver = loadPageWithAlerts2(firstContent); assertEquals("first", driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.Window3Test.java
License:Apache License
/** * @throws Exception if the test fails/*from ww w. j a va 2 s .c o m*/ */ @Test @Alerts(DEFAULT = "First", IE = "Second") public void navigate() throws Exception { final String firstContent = "<html><head><title>First</title><script>\n" + " function test() {\n" + " if (window.navigate) {\n" + " window.navigate('" + URL_SECOND + "');\n" + " }\n" + " }\n" + "</script></head><body onload='test()'>\n" + "</body></html>"; final String secondContent = "<html><head><title>Second</title></head><body></body></html>"; getMockWebConnection().setResponse(URL_SECOND, secondContent); final WebDriver driver = loadPage2(firstContent, URL_FIRST); assertEquals(getExpectedAlerts()[0], driver.getTitle()); }
From source file:com.giri.target.svr.cmd.ISCommandProcessor.java
License:Open Source License
private String resolve(String string, WebDriver selenium) { String output = string;//w ww . j ava 2 s . c o m if (string == "title") { output = selenium.getTitle(); } else if (string == "url") { output = selenium.getCurrentUrl(); } return output; }
From source file:com.github.mfriedenhagen.phantomjstest.JenkinsHomePage.java
public static JenkinsHomePage create(final WebDriver driver) { final JenkinsHomePage jenkinsHomePage = new JenkinsHomePage(driver); assertEquals(TITLE, driver.getTitle()); return jenkinsHomePage; }
From source file:com.github.mfriedenhagen.phantomjstest.JobPage.java
public static JobPage create(WebDriver driver, String name) { final JobPage jobPage = new JobPage(driver, name); assertEquals(name + " [Jenkins]", driver.getTitle()); assertTrue(jobPage.hasChangesLink()); return jobPage; }
From source file:com.github.seleniumpm.pagemodel.WebPage.java
License:Apache License
public WebPage waitForTitle(String title) { WebDriver driver = sel.getDriver();//from w ww.ja va2 s . c om final String ftitle = title.toLowerCase(); (new WebDriverWait(driver, TimeUnit.MILLISECONDS.toSeconds(elementWaitTime))) .until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith(ftitle); } }); return this; }
From source file:com.github.seleniumpm.WebPage.java
License:Apache License
public WebPage waitForTitle(String title) { final String ftitle = title.toLowerCase(); (new WebDriverWait(driver, TimeUnit.MILLISECONDS.toSeconds(elementWaitTime))) .until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith(ftitle); }//w w w . j a v a 2 s . com }); return this; }
From source file:com.google.caja.plugin.BrowserTestCase.java
License:Apache License
/** * Do what should be done with the browser. *///from ww w . j a va 2s .c om protected String driveBrowser(final WebDriver driver) { // long timeout: something we're doing is leading to huge unpredictable // slowdowns in random test startup; perhaps we're holding onto a lot of ram // and we're losing on swapping/gc time. unclear. countdown(10000, 200, new Countdown() { @Override public String toString() { return "startup"; } public int run() { List<WebElement> readyElements = driver.findElements(By.className("readytotest")); return readyElements.size() == 0 ? 1 : 0; } }); // 4s because test-domado-dom-events has non-click tests that can block // for a nontrivial amount of time, so our clicks aren't necessarily // processed right away. countdown(4000, 200, new Countdown() { private List<WebElement> clickingList = null; @Override public String toString() { return "clicking done (Remaining elements = " + renderElements(clickingList) + ")"; } public int run() { clickingList = driver.findElements(By.xpath("//*[contains(@class,'clickme')]/*")); for (WebElement e : clickingList) { // TODO(felix8a): webdriver fails if e has been removed e.click(); } return clickingList.size(); } }); // override point waitForCompletion(driver); // check the title of the document String title = driver.getTitle(); assertTrue("The title shows " + title, title.contains("all tests passed")); return title; }