package Caelum;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class UsuariosPage {
private WebDriver driver;
public UsuariosPage(WebDriver driver) {
this.driver = driver;
}
public void visita(){
driver.get("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 Caelum;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.firefox.FirefoxDriver;
import static org.junit.Assert.assertTrue;
public class UsuariosSystemTest {
private FirefoxDriver driver;
@Before
public void inicializa() {
System.setProperty("webdriver.gecko.driver", "c:\\geckodriver.exe");
this.driver = new FirefoxDriver();
driver.get("http://localhost:8080/usuarios");
}
@Test
public void deveAdicionarUmUsuario() {
UsuariosPage usuarios = new UsuariosPage(driver);
usuarios.novo().cadastra("Ronaldo Luiz de Albuquerque","ronaldo2009@terra.com.br");
assertTrue(usuarios.existeNaListagem("Ronaldo Luiz de Albuquerque","ronaldo2009@terra.com.br"));
}
@After
public void finaliza() {
driver.close();
}
}
package Caelum;
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();
}
}