List of usage examples for org.openqa.selenium By linkText
public static By linkText(String linkText)
From source file:com.gargoylesoftware.htmlunit.javascript.host.dom.DocumentTest.java
License:Apache License
/** * @throws Exception if the test fails//from w w w. ja v a 2 s . c o m */ @Test @Alerts("URL") public void referrer() throws Exception { final String firstHtml = "<html><head><title>First</title></head><body>\n" + "<a href='" + URL_SECOND + "'>click me</a></body></html>"; final String secondHtml = "<html><head><title>Second</title></head><body onload='alert(document.referrer);'>\n" + "</form></body></html>"; getMockWebConnection().setResponse(URL_SECOND, secondHtml); final WebDriver driver = loadPage2(firstHtml); driver.findElement(By.linkText("click me")).click(); expandExpectedAlertsVariables(URL_FIRST); verifyAlerts(driver, getExpectedAlerts()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLAnchorElement2Test.java
License:Apache License
/** * @throws Exception if an error occurs//from www .j a va2 s . co m */ @Test @Alerts(DEFAULT = {}, CHROME = "PING") public void ping() throws Exception { final String html = "<html><body>\n" + " <a href='" + URL_SECOND + "' ping='test2?h'>clickMe</a>\n" + "</body></html>"; final Map<String, Class<? extends Servlet>> servlets = new HashMap<>(); servlets.put("/test2", PingServlet.class); PingServlet.HEADERS_.clear(); PingServlet.BODY_ = null; getMockWebConnection().setResponse(URL_SECOND, "something"); final WebDriver driver = loadPage2(html, servlets); driver.findElement(By.linkText("clickMe")).click(); final String[] expectedAlerts = getExpectedAlerts(); final String firstString; final String secondString; final String body; if (expectedAlerts.length != 0) { firstString = URL_FIRST.toString(); secondString = URL_SECOND.toString(); body = PingServlet.BODY_; } else { firstString = null; secondString = null; body = null; } assertEquals(firstString, PingServlet.HEADERS_.get("Ping-From")); assertEquals(secondString, PingServlet.HEADERS_.get("Ping-To")); assertEquals(body, PingServlet.BODY_); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocumentWrite2Test.java
License:Apache License
/** * Regression test for bug 2884585.//from ww w .ja v a2s .c o m * As of HtmlUnit-2.7-SNAPSHOT 17.01.2010 <script src="..."... written * by document.write was not loaded and executed after the </script> * when the page was loaded as result of a click. * @throws Exception if the test fails */ @Test @Alerts("HelloHello") public void writeExternalScriptAfterClick() throws Exception { final String html = "<html><head>\n" + "<script>\n" + "document.write('<scr'+'ipt src=\"script.js\"></scr'+'ipt>');\n" + "</script>\n" + "<script>\n" + "window.name += window.foo;\n" + "</script>\n" + "</head>\n" + "<body>\n" + "<a href='?again'>a link</a>\n" + "<div id='clickMe' onclick='alert(window.name)'>click me</div>\n" + "</body>\n" + "</html>"; getMockWebConnection().setDefaultResponse("window.foo = 'Hello'", JAVASCRIPT_MIME_TYPE); final WebDriver driver = loadPage2(html); driver.findElement(By.linkText("a link")).click(); driver.findElement(By.id("clickMe")).click(); verifyAlerts(driver, getExpectedAlerts()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocumentWriteTest.java
License:Apache License
/** * Regression test for bug 2884585.//w w w . j a v a 2 s .c o m * As of HtmlUnit-2.7-SNAPSHOT 17.01.2010 <script src="..."... written * by document.write was not loaded and executed after the </script> * when the page was loaded as result of a click. * @throws Exception if the test fails */ @Test @Alerts("HelloHello") public void writeExternalScriptAfterClick() throws Exception { final String html = "<html><head>\n" + "<script>\n" + "document.write('<scr'+'ipt src=\"script.js\"></scr'+'ipt>');\n" + "</script>\n" + "<script>\n" + "window.name += window.foo;\n" + "</script>\n" + "</head>\n" + "<body>\n" + "<a href='?again'>a link</a>\n" + "<div id='clickMe' onclick='alert(window.name)'>click me</div>\n" + "</body>\n" + "</html>"; getMockWebConnection().setDefaultResponse("window.foo = 'Hello'", JAVASCRIPT_MIME_TYPE); final WebDriver driver = loadPage2(html); driver.findElement(By.linkText("a link")).click(); driver.findElement(By.id("clickMe")).click(); assertEquals(getExpectedAlerts(), getCollectedAlerts(driver)); }
From source file:com.gargoylesoftware.htmlunit.libraries.MochiKitTest.java
License:Apache License
private void doTest(final String testName) throws Exception { final String url = URL_FIRST + "tests/test_MochiKit-" + testName + ".html"; assertNotNull(url);/*from w ww .java 2s . co m*/ final WebDriver driver = getWebDriver(); driver.get(url); // make single test results visible driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.findElement(By.linkText("Toggle passed tests")).click(); driver.findElement(By.linkText("Toggle failed tests")).click(); driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); String expected = loadExpectation(testName); expected = expected.trim(); expected = StringUtils.replace(expected, "\r\n", "\n"); final WebElement div = driver.findElement(By.xpath("//div[@class = 'tests_report']")); assertNotNull(div); String actual = div.getText().trim(); actual = StringUtils.replace(actual, "\n\n", "\n"); assertEquals(expected.trim(), actual); }
From source file:com.ggasoftware.jdiuitest.web.selenium.elements.pageobjects.annotations.WebAnnotationsUtil.java
License:Open Source License
public static By getFindByLocator(FindBy locator) { if (locator == null) return null; if (!"".equals(locator.id())) return By.id(locator.id()); if (!"".equals(locator.className())) return By.className(locator.className()); if (!"".equals(locator.xpath())) return By.xpath(locator.xpath()); if (!"".equals(locator.css())) return By.cssSelector(locator.css()); if (!"".equals(locator.linkText())) return By.linkText(locator.linkText()); if (!"".equals(locator.name())) return By.name(locator.name()); if (!"".equals(locator.partialLinkText())) return By.partialLinkText(locator.partialLinkText()); if (!"".equals(locator.tagName())) return By.tagName(locator.tagName()); return null;//from w w w.ja v a 2s.co m }
From source file:com.github.fscheffer.arras.demo.DropdownIT.java
License:Apache License
@Test public void testDropdownInZone() { element(By.linkText("trigger zone")).click(); waitForAjaxRequestsToComplete();/*from ww w . j a v a 2s . c om*/ waitUntil(containsText("#dropdownZone", "Dropdown In Zone")); element(By.linkText("Dropdown In Zone")).click(); waitUntil(containsText(dropdownItem(1), "Apache HTTP Server")); waitUntil(containsText(dropdownItem(2), "Apache Tapestry 5")); waitUntil(containsText(dropdownItem(3), "Apache Felix")); }
From source file:com.github.fscheffer.arras.demo.LightboxIT.java
License:Apache License
@Test public void testBasic() { openLightbox(By.linkText("Bridge over river")); assertImageInLightbox("/arras/assets/meta/b9626ecd/photos/landscape/bridge-over-river.jpg"); waitUntil(containsText("#cboxTitle", "Bridge over river")); closeLightbox();//from w ww. j a va 2s . com }
From source file:com.github.fscheffer.arras.demo.LightboxIT.java
License:Apache License
@Test public void testGroup() { // group example openLightbox(By.linkText("Rocky cliffs")); assertImageInLightbox("/arras/assets/meta/d45fddff/photos/landscape/pointarena_rockycliffs.jpg"); click("#cboxLoadedContent > img"); assertImageInLightbox("/arras/assets/meta/3aad432/photos/landscape/san-joaquin-river-view.jpg"); click("#cboxLoadedContent > img"); assertImageInLightbox("/arras/assets/meta/dedf595e/photos/landscape/man_point-arena-stornetta.jpg"); click("#cboxLoadedContent > img"); assertImageInLightbox("/arras/assets/meta/d45fddff/photos/landscape/pointarena_rockycliffs.jpg"); closeLightbox();/* w ww. j a v a 2 s . c om*/ }
From source file:com.github.fscheffer.arras.demo.LightboxIT.java
License:Apache License
@Test public void testFixedSize() { // fixed size openLightbox(By.linkText("San Joaquin River (Fixed size)")); WebElement wrapper = element("#cboxWrapper"); Assert.assertEquals(wrapper.getCssValue("height"), "700px"); Assert.assertEquals(wrapper.getCssValue("width"), "500px"); closeLightbox();// w w w .j av a 2s . c om Dimension viewport = viewport(); // fixed size in percent openLightbox(By.linkText("Rocky cliffs (Fixed size in percent)")); assertPixelValue(wrapper.getCssValue("width"), viewport.width * 0.5); assertPixelValue(wrapper.getCssValue("height"), viewport.height * 0.75); closeLightbox(); }