Quando eu dou Debug no assertTrue o teste passa (OK). Mas quando executo normalmente o teste ele não passa (NOK).
Sem o Debug a execução passa direto pelo assertTrue e ele não tem retorno do método existeNaListagem.
package br.com.caellum.teste;
import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.firefox.FirefoxDriver;
public class UsuariosSistemTest {
private FirefoxDriver driver;
private UsuariosPage usuarios;
@Test
public void testeCadastroUsuario() {
usuarios.visita();
usuarios.novo().cadastra("Ronaldo Luiz de Albuquerque", "ronaldo2009@terra.com.br");
assertTrue(usuarios.existeNaListagem("Ronaldo Luiz de Albuquerque", "ronaldo2009@terra.com.br"));
}
@Before
public void inicializa() {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\guilherme.lima\\Desktop\\Alura\\Selenium\\geckodriver.exe");
this.driver = new FirefoxDriver();
this.usuarios = new UsuariosPage(driver);
// this.novoUsuario = new NovoUsuarioPage(driver);
}
@After
public void finaliza() {
this.driver.close();
}
}
package br.com.caellum.teste;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class UsuariosPage {
private WebDriver driver;
public UsuariosPage(WebDriver driver) {
this.driver = driver;
}
public void visita() {
driver.get("http://localhost:8080/usuarios");
}
public NovoUsuarioPage novo() {
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);
}
}
package br.com.caellum.teste;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class NovoUsuarioPage {
private final WebDriver driver;
public NovoUsuarioPage(WebDriver driver) {
this.driver = driver;
}
public void cadastra(String nome, String email) {
WebElement txtnome = driver.findElement(By.name("usuario.nome"));
txtnome.sendKeys(nome);
WebElement txtemail = driver.findElement(By.name("usuario.email"));
txtemail.sendKeys(email);
txtemail.submit();
}
}