java.lang.NullPointerException at br.com.alura.leilao.acceptance.steps.LoginSteps.éredirecionadopara_a_pagina_de_leiloes(LoginSteps.java:40) at ✽.é redirecionado para a pagina de leiloes(classpath:features/login.feature:8)
public class LoginSteps {
private Browser browser;
private LoginPage loginPage;
private LeiloesPage leiloesPage;
@Dado("o usuario valido")
public void o_usuario_valido() {
browser = new Browser();
browser.seed();
loginPage = browser.getLoginPage();
}
@Dado("o usuario invalido")
public void o_usuario_invalido() {
}
@Quando("realiza login")
public void realiza_login() {
this.loginPage.realizaLoginComo("fulano", "pass");
}
@Quando("tenta se logar")
public void tenta_se_logar() {
}
@Entao("é redirecionado para a pagina de leiloes")
public void é_redirecionado_para_a_pagina_de_leiloes() {
Assert.assertTrue(this.leiloesPage.estaNaPaginaDeLeiloes());
}
@Entao("continua na página de login")
public void continua_na_página_de_login() {
}
}
public class LeiloesPage {
private WebDriver driver;
private static String PAGE_URL = "http://localhost:8080/leiloes";
public LeiloesPage(WebDriver driver) {
this.driver = driver;
}
public void visita() {
driver.get(PAGE_URL);
}
public boolean existe(String nomeProduto, String valor, String usuario) {
return driver.getCurrentUrl().endsWith("/leiloes") && driver.getPageSource().contains(nomeProduto) &&
driver.getPageSource().contains(valor);
}
public boolean estaNaPaginaDeLeiloes() {
return this.driver.getCurrentUrl().endsWith("/leiloes");
}
public NovoLeilaoPage visitaPaginaParaCriarUmNovoLeilao() {
WebDriverWait wait = new WebDriverWait(driver,5);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("novo_leilao_link")));
WebElement href = driver.findElement(By.id("novo_leilao_link"));
wait.until(ExpectedConditions.elementToBeClickable(href));
href.click();
return new NovoLeilaoPage(driver);
}
public DetalhesDoLeilaoPage visitaLeilaoPaginaParaDarLance() {
driver.findElement(By.linkText("dar lance")).click();
return new DetalhesDoLeilaoPage(driver);
}
public AlterarLeilaoPage visitaPaginaParaAltearLeilao() {
driver.findElement(By.linkText("editar")).click();
return new AlterarLeilaoPage(driver);
}
public DetalhesDoLeilaoPage visitaPaginaDoLeilaoDo(String donoDoLeilao) throws Exception {
WebDriverWait wait = new WebDriverWait(driver,5);
String xpath = "//table[@class='table table-hover']/tbody/tr/td[contains(text(),'" +
donoDoLeilao+ "')]/following-sibling::td/a";
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));
WebElement href = driver.findElement(
By.xpath(xpath));
wait.until(ExpectedConditions.elementToBeClickable(href));
href.click();
return new DetalhesDoLeilaoPage(driver);
}
public void esperaCarregar() {
WebDriverWait wait = new WebDriverWait(driver,5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h1[contains(text(),'Todos leilões')]")));
}
public boolean naoPodeDarLanceNoLeilaoCriado(String donoDoLeilao) {
WebElement href = driver.findElement(
By.xpath("//table[@class='table table-hover']/tbody/tr/td[contains(text(),'" +donoDoLeilao+ "')]/following-sibling::td/a"));
return href.getText().contains("editar");
}
}