org.openqa.selenium.NoSuchElementException: Unable to locate element: #usuario.nome For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-
Classe SistemTeste package br.caleum.teste;
import Page.UsuarioPage; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.WebDriver; import org.junit.*; import static org.junit.Assert.assertTrue;
public class SistemTeste {
private WebDriver driver; private UsuarioPage usuarios;
@Before public void inicializacao(){ System.setProperty("webdriver.gecko.driver", "C:\Users\Daniel\Documents\Aplicativos\Automação de Teste\Ruby\geckodriver-v0.19.1-win64\geckodriver.exe"); // chama o firefox; this.driver = new FirefoxDriver(); this.usuarios = new UsuarioPage(driver); }
@Test public void incluiUser(){
usuarios.visita(); usuarios.novo().CadastraNovoUsuario("Daniel Proenca", "daniel.proenca@gft.com"); assertTrue(usuarios.existeNaListagem("Daniel Proenca", "daniel.proenca@gft.com")); }
@After public void finalizacao(){ driver.close(); } }
Classe UsuarioPage package Page;
import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; //import org.openqa.selenium.WebElement; //import org.junit.*; //import static org.junit.Assert.assertTrue;
public class UsuarioPage {
private WebDriver driver;
public UsuarioPage(WebDriver driver){ //System.setProperty("webdriver.gecko.driver", "C:\Users\Daniel\Documents\Aplicativos\Automação de Teste\Ruby\geckodriver-v0.19.1-win64\geckodriver.exe"); // chama o firefox; this.driver = new FirefoxDriver(); }
public void visita(){ driver.get("http://localhost:8080/usuarios"); }
public NovoUsuarioPage novo(){ //clicar no link novo usuário driver.findElement(By.linkText("Novo Usuário")).click(); return new NovoUsuarioPage(driver); }
public boolean existeNaListagem(String nome, String email){ return driver.getPageSource().contains(nome) && driver.getPageSource().contains(email); } }
Classe NovoUsuario package Page;
//import org.openqa.selenium.firefox.FirefoxDriver; //import org.openqa.selenium.remote.server.handler.FindElement; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement;
public class NovoUsuarioPage {
private WebDriver driver;
public NovoUsuarioPage(WebDriver driver){ //System.setProperty("webdriver.gecko.driver", "C:\Users\Daniel\Documents\Aplicativos\Automação de Teste\Ruby\geckodriver-v0.19.1-win64\geckodriver.exe"); // chama o firefox; this.driver = driver; }
public void CadastraNovoUsuario(String nome, String email){ WebElement txtnome = driver.findElement(By.id("usuario.nome")); WebElement txtemail = driver.findElement(By.id("usuario.email"));
txtnome.sendKeys(nome); txtemail.sendKeys(email);
txtnome.submit(); } }