List of usage examples for org.openqa.selenium By linkText
public static By linkText(String linkText)
From source file:com.epam.jdi.uitests.web.selenium.elements.pageobjects.annotations.WebAnnotationsUtil.java
License:Open Source License
public static By findByToBy(JFindBy locator) { if (locator == null) return null; 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.partialLinkText())) return By.partialLinkText(locator.partialLinkText()); if (!"".equals(locator.tagName())) return By.tagName(locator.tagName()); if (!"".equals(locator.text())) return By.xpath(".//*/text()[normalize-space(.) = " + Quotes.escape(locator.text()) + "]/parent::*"); if (!"".equals(locator.attribute().name())) return getAttribute(locator.attribute().name(), locator.attribute().value()); if (!"".equals(locator.id())) return By.id(locator.id()); if (!"".equals(locator.className())) return By.className(locator.className()); if (!"".equals(locator.name())) return By.name(locator.name()); if (!"".equals(locator.value())) return getAttribute("value", locator.value()); if (!"".equals(locator.title())) return getAttribute("title", locator.title()); if (!"".equals(locator.type())) return getAttribute("type", locator.title()); if (!"".equals(locator.model())) return getAttribute("ng-model", locator.model()); if (!"".equals(locator.binding())) return getAttribute("ng-binding", locator.binding()); if (!"".equals(locator.repeat())) return getAttribute("ng-repeat", locator.repeat()); return null;/* w w w . j ava 2s . c o m*/ }
From source file:com.evolveum.midpoint.testing.schrodinger.labs.ImportResourceTest.java
License:Apache License
@Test(groups = { "lab_3_1" }, dependsOnMethods = { "test001ImportCsvResource" }, priority = 2) public void test003showUsingWizard() { ResourceWizardPage resourceWizard = navigateToViewResourcePage().clickShowUsingWizard(); //wizard should appear Assert.assertTrue(//w w w .j a v a2 s . co m $(By.className("wizard")).waitUntil(Condition.appear, MidPoint.TIMEOUT_DEFAULT_2_S).exists()); Assert.assertTrue($(Schrodinger.byDataId("readOnlyNote")) .waitUntil(Condition.appear, MidPoint.TIMEOUT_DEFAULT_2_S).exists()); //Configuration tab resourceWizard.clickOnWizardTab("Configuration"); Assert.assertTrue($(Schrodinger.byDataId("configuration")) .waitUntil(Condition.appear, MidPoint.TIMEOUT_DEFAULT_2_S).exists()); //Schema tab resourceWizard.clickOnWizardTab("Schema"); Assert.assertTrue($(Schrodinger.byElementValue("a", "Schema")).shouldBe(Condition.visible).exists()); $(By.linkText(ACCOUNT_OBJECT_CLASS_LINK)).shouldBe(Condition.visible).click(); //Attributes table visibility check Assert.assertTrue($(Schrodinger.byDataId("attributeTable")).shouldBe(Condition.visible).exists()); //check resource attributes are present RESOURCE_ATTRIBUTES.forEach(attr -> Assert.assertTrue($(Schrodinger.byElementValue("div", attr)) .waitUntil(Condition.visible, MidPoint.TIMEOUT_DEFAULT_2_S).exists())); }
From source file:com.example.getstarted.basicactions.UserJourneyTestIT.java
License:Apache License
private WebElement checkLandingPage() throws Exception { WebElement button = driver.findElement(By.cssSelector("a.btn")); assertEquals("Add book", button.getText()); WebElement heading = driver.findElement(By.cssSelector("body>.container h3")); assertEquals("Books", heading.getText()); WebElement list = driver.findElement(By.cssSelector("body>.container p")); assertEquals("No books found", list.getText()); WebElement loginButton = driver.findElement(By.linkText("Login")); assertTrue(null != loginButton);// w w w .j a v a 2s . c o m return button; }
From source file:com.example.getstarted.basicactions.UserJourneyTestIT.java
License:Apache License
private WebElement checkLandingPage(String email) throws Exception { WebElement logout = driver.findElement(By.linkText(email)); assertTrue(null != logout);/* w ww . j av a2s . co m*/ WebElement button = driver.findElement(By.cssSelector("a.btn")); assertEquals("Add book", button.getText().trim()); WebElement heading = driver.findElement(By.cssSelector("body>.container h3")); assertEquals("Books", heading.getText()); WebElement list = driver.findElement(By.cssSelector("body>.container p")); assertEquals("No books found", list.getText()); return button; }
From source file:com.example.getstarted.basicactions.UserJourneyTestIT.java
License:Apache License
private void logout(String email) { WebElement button = driver.findElement(By.linkText(email)); button.click(); }
From source file:com.example.getstarted.basicactions.UserJourneyTestIT.java
License:Apache License
@Test public void userJourney() throws Exception { // Do selenium tests on the deployed version, if applicable String endpoint = "http://localhost:8080"; if (!LOCAL_TEST) { endpoint = String.format("https://%s-dot-%s.appspot.com", APP_VERSION, APP_ID); }/*w w w .j ava 2 s . co m*/ System.out.println("Testing endpoint: " + endpoint); driver.get(endpoint); try { WebElement button = checkLandingPage(); if (LOCAL_TEST) { WebElement loginButton = driver.findElement(By.linkText("Login")); loginButton.click(); (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches("login")); login(EMAIL); (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches("/books")); button = checkLandingPage(EMAIL); button.click(); (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/create$")); checkAddBookPage(); submitForm(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION); (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/read\\?id=[0-9]+$")); checkReadPage(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION, EMAIL); logout(EMAIL); (new WebDriverWait(driver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.linkText("Login"))); } else { button.click(); (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/create$")); checkAddBookPage(); submitForm(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION); (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/read\\?id=[0-9]+$")); checkReadPage(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION, "Anonymous"); // Now check the list of books for the one we just submitted driver.findElement(By.linkText("Books")).click(); (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/$")); checkBookList(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION); } } catch (Exception e) { System.err.println(driver.getPageSource()); throw e; } }
From source file:com.example.selenium.DashBoard.java
/** * * @return/*w w w . ja va 2s. c o m*/ */ public int validateMenu() { String menu = menuElements.getText(); System.out.println("#### Menu Elements ####" + menu); List<String> menuElementList = Arrays.asList(menu.split("\n")); for (String menuElement : menuElementList) { try { selenium.findElement(By.linkText(menuElement)).click(); Thread.sleep(1500); } catch (InterruptedException ex) { Logger.getLogger(DashBoard.class.getName()).log(Level.SEVERE, null, ex); } } return menuElementList.size(); }
From source file:com.example.selenium.find.elements.FindElementsTest.java
@Test public void findByLinkTest() { try {// www. j a v a2 s .c om WebElement element = selenium.findElement(By.linkText("Login")); System.out.println("Element Attrbutes =" + element.getAttribute("href")); Assert.assertNotNull(element); } catch (NoSuchElementException ex) { Logger.getLogger(FindElementsTest.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.example.selenium.grid.SeleniumGridChrome.java
@Test(dataProvider = "xlsTest") public void testLogin(String useName, String password) throws InterruptedException { driver.get("http://localhost:8080/WebApplication/pages/login.html"); WebElement userNameText = driver.findElement(By.name("email")); userNameText.sendKeys(useName);/*from w w w. j av a 2 s .c o m*/ WebElement passwordText = driver.findElement(By.id("password")); passwordText.sendKeys(password); WebElement loginButton = driver.findElement(By.linkText("Login")); loginButton.click(); if (driver.getTitle().equals("SB Admin 2 - Bootstrap Admin Theme")) { assertTrue(true); } else { assertTrue(false); } }
From source file:com.example.selenium.grid.SeleniumGridIE.java
@Test(dataProvider = "xlsTest") public void testLogin(String useName, String password) throws InterruptedException { driver.get("http://localhost:8080/WebApplication/pages/login.html"); Thread.sleep(2000);/*w w w.j a va 2 s . co m*/ WebElement userNameText = driver.findElement(By.name("email")); userNameText.sendKeys(useName); WebElement passwordText = driver.findElement(By.id("password")); passwordText.sendKeys(password); WebElement loginButton = driver.findElement(By.linkText("Login")); loginButton.click(); if (driver.getTitle().equals("SB Admin 2 - Bootstrap Admin Theme")) { assertTrue(true); } else { assertTrue(false); } }