O código está dando o erro abaixo quando tento executa-lo:
java.lang.AssertionError
at org.junit.Assert.fail(Assert.java:87)
at org.junit.Assert.assertTrue(Assert.java:42)
at org.junit.Assert.assertTrue(Assert.java:53)
at br.com.alura.leilao.leiloes.LeiloesTest.deveCadastrarLeilao(LeiloesTest.java:41)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:686)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
Segue abaixo meu código LeiloesTest.java
package br.com.alura.leilao.leiloes;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import br.com.alura.leilao.login.LoginPage;
public class LeiloesTest {
private LeiloesPage paginaDeLeiloes;
@AfterEach
public void afterEach() {
this.paginaDeLeiloes.fechar();
}
@Test
public void deveCadastrarLeilao() throws InterruptedException {
LoginPage paginaDeLogin = new LoginPage();
paginaDeLogin.preencheFomularioDeLogin("fulano", "pass");
this.paginaDeLeiloes = paginaDeLogin.efetuarLogin();
CadastroLeilaoPage paginaDeCadastro = paginaDeLeiloes.carregarFormulario();
String hoje = LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
String nome = "Leilão do dia " + hoje;
String valor = "500.00";
this.paginaDeLeiloes = paginaDeCadastro.cadastrarLeilao(nome, valor, hoje);
Assert.assertTrue(paginaDeLeiloes.isLeilaoCadastrado(nome, valor, hoje));
}
}
E também meu código do LeiloesPage.java
package br.com.alura.leilao.leiloes;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LeiloesPage {
private static final String URL_LEILOES = "http://localhost:8080/leiloes";
private static final String URL_CADASTRO_LEILAO = "http://localhost:8080/leiloes/new";
private WebDriver browser;
public LeiloesPage(WebDriver browser) {
this.browser = browser;
}
public void fechar() {
this.browser.quit();
}
public CadastroLeilaoPage carregarFormulario() {
this.browser.navigate().to(URL_CADASTRO_LEILAO);
return new CadastroLeilaoPage(browser);
}
public boolean isLeilaoCadastrado(String nome, String valor, String hoje) {
WebElement linhaDaTabela = this.browser.findElement(By.cssSelector("#tabela-leiloes tbody tr:last-child"));
WebElement colunaNome = linhaDaTabela.findElement(By.cssSelector("td:nth-child(1)"));
WebElement colunaDataAbertura = linhaDaTabela.findElement(By.cssSelector("td:nth-child(2)"));
WebElement colunaValorInicial = linhaDaTabela.findElement(By.cssSelector("td:nth-child(3)"));
return colunaNome.getText().equals(nome) && colunaDataAbertura.getText().equals(valor)
&& colunaValorInicial.getText().equals(hoje);
}
}