Estou com este problema em localizar o elemento:
LeilaoPage
package br.com.alura.leilao.leilao;
import br.com.alura.leilao.cadastroLeilaoPage.CadastroLeilaoPage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class LeilaoPage {
public static final String URL_CADASTROLEILAO = "http://localhost:8080/leiloes/new";
private WebDriver browser;
public LeilaoPage(WebDriver browser){
this.browser = browser;
browser.navigate().to(URL_CADASTROLEILAO);
}
public void fechar(){
this.browser.quit();
}
public CadastroLeilaoPage carregarFormulario(){
browser.navigate().to(URL_CADASTROLEILAO);
return new CadastroLeilaoPage(browser);
}
public boolean isLeilaoCadastrado (String nome, String valor, String data){
WebElement linhaDaTabela = this.browser.findElement(By.cssSelector("#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(data) &&
colunaValorInicial.getText().equals(valor);
}
}
LeilaoTest
package br.com.alura.leilao.leilao;
import br.com.alura.leilao.cadastroLeilaoPage.CadastroLeilaoPage;
import br.com.alura.leilao.login.LoginPage;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class LeilaoTest {
private LeilaoPage paginaDeLeiloes;
@AfterEach
public void afterEach(){
paginaDeLeiloes.fechar();
}
@Test
public void cadastrarLeilao(){
LoginPage paginaDeLogin = new LoginPage();
paginaDeLogin.preencheFormulario("fulano","pass");
paginaDeLeiloes = paginaDeLogin.submeterFormulario();
CadastroLeilaoPage paginaDeCadastro = paginaDeLeiloes.carregarFormulario();
String hoje = LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
String nome = "Leilao do dia " + hoje;
String valor = "500";
this.paginaDeLeiloes = paginaDeCadastro.cadastrarLeilao(nome, valor, hoje);
Assertions.assertTrue(paginaDeLeiloes.isLeilaoCadastrado(nome,valor,hoje));
}
}
index
<html>
<head th:replace="~{base :: head}">
<meta charset="UTF-8">
</head>
<body>
<div th:replace="~{base :: logo}"></div>
<div class="container">
<div th:replace="~{base :: titulo('Leilões cadastrados')}"></div>
<div class="alert alert-primary" role="alert" th:if="${message}">
<span th:text="${message}"></span>
</div>
<table id="leiloes" class="table table-hover">
<thead>
<tr>
<th scope="col">Nome</th>
<th scope="col">Data de abertura</th>
<th scope="col">Valor inicial</th>
<th scope="col">Usuario</th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr th:each="leilao : ${leiloes}" >
<td scope="row" th:text="${leilao.nome}">Nome</td>
<td th:text="${#temporals.format(leilao.dataAbertura, 'dd/MM/yyyy')}">10/02/2020</td>
<td th:text="${leilao.valorInicial}">Valor Inicial</td>
<td th:text="${leilao.usuario.nome}">Nome do Usuario</td>
<td sec:authorize="isAuthenticated()" th:if="${leilao.usuario.nome != usuarioLogado.name && leilao.aberto}">
<a class="btn btn-block btn-info" th:href="@{'/leiloes/' + ${leilao.id}}" >dar lance</a>
</td>
<td sec:authorize="isAuthenticated()" th:if="${leilao.usuario.nome == usuarioLogado.name} ">
<a class="btn btn-block btn-primary m-0" th:href="@{'/leiloes/' + ${leilao.id}} + '/form'">editar</a>
</td>
</tr>
</tbody>
</table>
<br />
<a class="btn btn-primary" id="novo_leilao_link" th:href="@{'/leiloes/new'}" role="button" sec:authorize="isAuthenticated()">Novo Leilão</a>
</div>
</body>
</html>