List of usage examples for org.openqa.selenium By linkText
public static By linkText(String linkText)
From source file:ch.hearc.arcgames.tests.DBInteractionTest.java
@Test public void loggedUserTryAccessPages() throws Exception { // New user informations String username = "myUsername"; String mail = "myMail@gmail.com"; String location = "Neuchtel"; String firstName = "myFName"; String lastName = "myLName"; String passwd = "myPasswd"; // We open the web app driver.get(baseUrl + "/ArcGames/"); // SignUp with a test user signUp(username, mail, passwd, location, firstName, lastName); // Login as non-admin login(username, passwd);//from w w w .j a va 2s . c o m // Edit user String s = "edited"; driver.findElement(By.linkText(username)).click(); driver.findElement(By.id("j_idt19:username")).clear(); driver.findElement(By.id("j_idt19:username")).sendKeys(s); driver.findElement(By.id("j_idt19:mail")).clear(); driver.findElement(By.id("j_idt19:mail")).sendKeys(s); driver.findElement(By.id("j_idt19:passwd")).clear(); driver.findElement(By.id("j_idt19:passwd")).sendKeys(s); driver.findElement(By.id("j_idt19:passwdConfirm")).clear(); driver.findElement(By.id("j_idt19:passwdConfirm")).sendKeys(s); driver.findElement(By.id("j_idt19:location")).clear(); driver.findElement(By.id("j_idt19:location")).sendKeys(s); driver.findElement(By.id("j_idt19:firstName")).clear(); driver.findElement(By.id("j_idt19:firstName")).sendKeys(s); driver.findElement(By.id("j_idt19:lastName")).clear(); driver.findElement(By.id("j_idt19:lastName")).sendKeys(s); driver.findElement(By.id("j_idt19:submit")).click(); // Logout driver.findElement(By.linkText("logout")).click(); }
From source file:ch.hearc.arcgames.tests.DBInteractionTest.java
private void signUp(String username, String mail, String passwd, String location, String firstName, String lastName) {//from w ww.ja v a 2s .co m driver.findElement(By.linkText("Sign up")).click(); driver.findElement(By.id("j_idt18:username")).clear(); driver.findElement(By.id("j_idt18:username")).sendKeys(username); driver.findElement(By.id("j_idt18:mail")).clear(); driver.findElement(By.id("j_idt18:mail")).sendKeys(mail); driver.findElement(By.id("j_idt18:passwd")).clear(); driver.findElement(By.id("j_idt18:passwd")).sendKeys(passwd); driver.findElement(By.id("j_idt18:passwdConfirm")).clear(); driver.findElement(By.id("j_idt18:passwdConfirm")).sendKeys(passwd); driver.findElement(By.id("j_idt18:location")).clear(); driver.findElement(By.id("j_idt18:location")).sendKeys(location); driver.findElement(By.id("j_idt18:firstName")).clear(); driver.findElement(By.id("j_idt18:firstName")).sendKeys(firstName); driver.findElement(By.id("j_idt18:lastName")).clear(); driver.findElement(By.id("j_idt18:lastName")).sendKeys(lastName); driver.findElement(By.id("j_idt18:submit")).click(); }
From source file:ch.hearc.arcgames.tests.searchTest.java
@Test public void loggedUserTryAccessPages() throws Exception { // Non-admin user login informations String username = "nonAdmin"; String passwd = "nonAdminPassword"; // We open the web app driver.get(baseUrl + "/ArcGames/"); // SignUp with a test user String pattern = "fake"; signUp(pattern, pattern, pattern, pattern, pattern, pattern); // Login as non-admin login(username, passwd);//from ww w . j a v a 2s .com // Go to users page driver.findElement(By.linkText("Users")).click(); // Search user that matches "fake" pattern simpleSearch(pattern); // Check results String result = driver.findElement(By.xpath("//form[@id='j_idt21']/table/tbody[2]/tr/td")).getText(); assertTrue(result.contains(pattern)); // Search user that matches "fake" user advancedSearch(pattern); // Check results result = driver.findElement(By.xpath("//form[@id='j_idt21']/table/tbody[2]/tr/td")).getText(); assertTrue(result.contains(pattern)); // Logout driver.findElement(By.linkText("logout")).click(); }
From source file:cn.aozhi.songify.functional.gui.RegisterFT.java
License:Apache License
@Test public void register() { // /*from w ww.j ava 2 s . c om*/ s.open("/logout"); s.click(By.linkText("")); s.type(By.id("loginName"), "user2"); s.type(By.id("name"), "Kevin"); s.type(By.id("plainPassword"), "user2"); s.type(By.id("confirmPassword"), "user2"); s.click(By.id("submit_btn")); // s.waitForTitleContains(""); assertThat(s.getValue(By.name("username"))).isEqualTo("user2"); s.type(By.name("password"), "user2"); s.click(By.id("submit_btn")); // ? s.waitForTitleContains("?"); // s.open("/logout"); }
From source file:cn.aozhi.songify.functional.gui.TaskGuiFT.java
License:Apache License
/** * //?/.//www .ja v a 2s. c o m */ @Test @Category(Smoke.class) public void crudTask() { s.open("/task/"); // create s.click(By.linkText("")); Task task = TaskData.randomTask(); s.type(By.id("task_title"), task.getTitle()); s.click(By.id("submit_btn")); assertThat(s.isTextPresent("?")).isTrue(); // update s.click(By.linkText(task.getTitle())); assertThat(s.getValue(By.id("task_title"))).isEqualTo(task.getTitle()); String newTitle = TaskData.randomTitle(); s.type(By.id("task_title"), newTitle); s.click(By.id("submit_btn")); assertThat(s.isTextPresent("?")).isTrue(); // search s.type(By.name("search_LIKE_title"), newTitle); s.click(By.id("search_btn")); assertThat(s.getTable(By.id("contentTable"), 0, 0)).isEqualTo(newTitle); // delete s.click(By.linkText("")); assertThat(s.isTextPresent("?")).as("??").isTrue(); }
From source file:cn.aozhi.songify.functional.gui.TaskGuiFT.java
License:Apache License
@Test public void inputInValidateValue() { s.open("/task/"); s.click(By.linkText("")); s.click(By.id("submit_btn")); assertThat(s.getText(By.xpath("//fieldset/div/div/span"))).isEqualTo(""); }
From source file:co.edu.icesi.i2t.slrtools.bib.transformations.TransformBibACM.java
License:Open Source License
/** * Funcion principal para la transformacion de los archivos html en un solo * arhivo consolidado BIB, la funcion se encarga de extraer del html cada * link de articulo, despues de tener el listado de url se dispone con la * ayuda de selenium webdriver el ingreso a cada url y descargar el BIBtex * para finalizar con la union de todos en un solo archivo BIB * * @param sourceFilesPath String con la ruta de la carpeta donde se * encuentran los archivos html a transformas * @param targetFilePath String con la ruta fisica del directorio donde se * guardara el archivo consolodidao/* ww w . j a v a 2 s .c o m*/ * @param targetFileName */ public static boolean transformFiles(String sourceFilesPath, String targetFilePath, String targetFileName) { boolean bibFileCreated = false; System.out.println(""); System.out.println("-----------------------------"); System.out.println("Generating BibTeX for ACM Digital Library results..."); System.out.println(""); String bibContent = ""; List<String> urls = extractURL(sourceFilesPath); FirefoxProfile profile = new FirefoxProfile(); WebDriver webDriver = new FirefoxDriver(profile); for (int i = 0; i < urls.size(); i++) { try { System.out.println("[INFO] Retrieving BibTeX from URL: " + urls.get(i)); String idFile = urls.get(i).split("id=")[1].split("&")[0]; idFile = idFile.substring(idFile.indexOf(".") + 1, idFile.length()); String url = (urls.get(i)); webDriver.get(url); WebElement bibField = (new WebDriverWait(webDriver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.linkText("BibTeX"))); try { Thread.sleep(2000); } catch (InterruptedException e) { } bibField.click(); WebElement textBib = (new WebDriverWait(webDriver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.id(idFile))); String reference = textBib.getText(); String referenceAbstract = webDriver.findElement(By.id("abstract")).getText(); referenceAbstract = "abstract = {" + referenceAbstract + "}}" + System.lineSeparator(); bibContent += reference.substring(0, reference.length() - 2) + referenceAbstract; //Thread.sleep(10000); //tempurl.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } catch (TimeoutException e) { System.out.println( "[ERROR] Failed to retrieve BibTex. The application may have been blocked by ACM Digital Library. Try again later."); } catch (Exception e) { System.out.println("[ERROR] Failed to retrieve BibTeX. " + e.getMessage()); } } webDriver.quit(); try { saveBibFile(bibContent, targetFilePath, targetFileName); if (!bibContent.equals("")) { bibFileCreated = true; } } catch (Exception e) { System.out.println("[ERROR] Failed to create BibTeX file." + e.getMessage()); } System.out.println("-----------------------------"); return bibFileCreated; }
From source file:co.edu.icesi.i2t.slrtools.webdrivers.WebDriverACM.java
License:Open Source License
/** * Funcion que se encarga de realizar automaticamente la busqueda en la base * de datos ACM Digital Library conforme a una cadena de busqueda * introducida, ACM digital library no permite la descarga de ningun archivo * del resultado de la busqueda, por tal razn, se descarga el codigo fuente * de la pagina en el source del proyecto el cual posteriormente es usado * para la extraccin de la informacin y construccion del BIB con los * resultados obtenidos/*w w w . j a v a 2 s. co m*/ * * @param searchStrings este parametro es la cadena de busqueda que retorna * la funcion mixACM#mixWords2, cada cadena de busqueda esta separada por ; * @param url este paremetro es el URL de la busqueda avanzada de ACM * Digital Library * @see mixWords.mixACM#mixWords2(java.lang.String, java.lang.String) */ public static void searchWeb(String searchStrings, String url) { /* a esta funcion se debe mejorar * 1: validar el boton siguiente sin try catch, mejorar el manejo de las expeciones */ System.out.println(""); System.out.println("-----------------------------"); System.out.println("Searching ACM Digital Library..."); System.out.println("Search strings: " + searchStrings + ""); System.out.println(""); FirefoxProfile profile = new FirefoxProfile(); WebDriver webDriver = new FirefoxDriver(profile); String[] strings = searchStrings.split(";"); for (int i = 0; i < strings.length; i++) { try { webDriver.get(url); WebElement searchField = webDriver.findElement(By.name("within")); searchField.click(); searchField.sendKeys(strings[i]); WebElement buttonSearch = webDriver.findElement(By.name("Go")); buttonSearch.click(); List<WebElement> stringResult = webDriver .findElements(By.xpath("//span[contains(@style, 'background-color:yellow')]")); if (!stringResult.isEmpty()) { System.out.println( "[WARNING] Search string " + (i + 1) + ": " + strings[i] + " retrieves no results"); } else { int counter = 1; try { WebElement nextField = null; do { String sourceCode = webDriver.getPageSource(); File targetDirectory = new File("files" + File.separator + Database.ACM.getName()); targetDirectory.mkdir(); try (PrintWriter file = new PrintWriter( "files" + File.separator + Database.ACM.getName() + File.separator + "searchResults_" + i + "_" + counter + ".html", "UTF-8")) { file.print(sourceCode); } nextField = (new WebDriverWait(webDriver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.linkText("next"))); try { Thread.sleep(10000); } catch (InterruptedException e) { } nextField.click(); counter++; } while (true); } catch (NoSuchElementException | TimeoutException | NullPointerException e) { System.out.println("[INFO] Search string " + (i + 1) + ": " + strings[i] + " has " + counter + (counter == 1 ? " result" : " results") + "returned"); } } } catch (FileNotFoundException | UnsupportedEncodingException e) { System.out.println( "[ERROR] Search string " + (i + 1) + ": " + strings[i] + " failed. " + e.getMessage()); } catch (NoSuchElementException e) { System.out.println( "[ERROR] The application has been blocked by ACM Digital Library. Try again later."); } try { Thread.sleep(10000); } catch (InterruptedException e) { } } webDriver.quit(); System.out.println("[INFO] Finished search in ACM Digital Library"); System.out.println("-----------------------------"); }
From source file:co.edu.uniandes.csw.RigitalApp.test.CMSTest.java
@AfterClass public static void tearDown() throws Exception { driver.get(baseUrl + "/RigitalApp.web/cMS.html"); // Se selecciona la tabla para eliminar todos sus elementos List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table-striped')]/tbody/tr")); /**// w w w.ja v a2s. c o m * Se itera sobre los elementos de la tabla para eliminarlos */ for (WebElement webElement : table) { List<WebElement> elems = webElement.findElements(By.xpath("td")); elems.get(3).findElement(By.linkText("Eliminar")).click(); assertTrue(true); } // Se cierra el navegador. driver.quit(); // Se verifica que se haya cerrado efectivamente el navegador. String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } }
From source file:co.edu.uniandes.csw.RigitalApp.test.ContenedorWebTest.java
@AfterClass public static void tearDown() throws Exception { driver.get(baseUrl + "/RigitalApp.web/contenedorWeb.html"); // Se selecciona la tabla para eliminar todos sus elementos List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table-striped')]/tbody/tr")); /**/* www .jav a 2 s.c om*/ * Se itera sobre los elementos de la tabla para eliminarlos */ for (WebElement webElement : table) { List<WebElement> elems = webElement.findElements(By.xpath("td")); elems.get(5).findElement(By.linkText("Eliminar")).click(); assertTrue(true); } // Se cierra el navegador. driver.quit(); // Se verifica que se haya cerrado efectivamente el navegador. String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } }