1
resposta

Reproduzindo o exemplo do vídeo, quando utilizo na txtNome.submit(); na classe NovoUsuarioPage, retorna erro e não consegui identificar o porque.

package br.com.Caelum.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 UsuariosSystemTeste {

    private FirefoxDriver driver;

    @Before
    public void inicializa() {
        System.setProperty("webdriver.gecko.driver", "c:\\geckodriver.exe");
        this.driver = new FirefoxDriver();
    }

    @Test
    public void deveAdicionarUsuario() {

        UsuariosPage usuarios = new UsuariosPage(driver);

        usuarios.visita();
        usuarios.novo().cadastra("Angela Cristina Morato", "angela.morato@gmail.com");

        assertTrue(usuarios.existeNaListagem("Angela Cristina Morato", "angela.morato@gmail.com"));
    }

    @After
    public void finaliza() {
        driver.close();

    }
}
package br.com.Caelum.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.Caelum.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"));
        WebElement txtEmail = driver.findElement(By.name("usuario.email"));

        txtNome.sendKeys(nome);
        txtEmail.sendKeys(email);

        txtNome.submit();

        //driver.findElement(By.id("btnSalvar")).click();
    }
}
1 resposta

Olá, tudo bem ?

Consegue nos falar qual foi o erro que deu ?