Mensagem de erro:
Message: OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"link text","selector":"Novo Leilão"} (Session info: chrome=73.0.3683.103) (Driver info: chromedriver=71.0.3578.33 (269aa0e3f0db08097f0fe231c7e6be200b6939f7),platform=Windows NT 10.0.17134 x86_64)
[TestFixture]
class LanceSystemTest
{
private LeiloesPage leiloes;
private ChromeDriver driver;
[SetUp]
public void inicializa()
{
driver = new ChromeDriver(@"C:\Users\amanda\Desktop\");
leiloes = new LeiloesPage(driver);
UsuarioPage usuario = new UsuarioPage(driver);
usuario.Visita();
usuario.Novo().Cadastra("Renan Saggio", "renan@caelum.com.br");
usuario.Novo().Cadastra("Paulo Henrique", "paulo@caelum.com.br");
leiloes.Novo().Preenche("Geladeira", 250, "Renan Saggio", true);
}
[Test]
public void DeveDarLance()
{
leiloes.Visita();
DetalhesLeilaoPage lances = leiloes.Detalhes(1);
lances.Lance("Paulo Henrique", 150);
Assert.IsTrue(lances.ExisteLance("Paulo Henrique", 150));
}
}
class DetalhesLeilaoPage
{
private IWebDriver driver;
public DetalhesLeilaoPage(IWebDriver driver)
{
this.driver = driver;
}
public void Lance(string usuario, double lance)
{
SelectElement cbUsuario = new SelectElement(driver.FindElement(By.Name("lance.usuario.id")));
IWebElement txtLance = driver.FindElement(By.Name("lance.valor"));
cbUsuario.SelectByText(usuario);
txtLance.SendKeys(Convert.ToString(lance));
driver.FindElement(By.Id("btnDarLance")).Click();
}
public bool ExisteLance(string usuario, double valor)
{
bool existe = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(d => d.FindElement(By.Id("lancesDados")).Text.Contains(usuario));
if (existe)
{
return driver.PageSource.Contains(Convert.ToString(valor));
}
return false;
}
}
class LeiloesPage
{
private IWebDriver driver;
public LeiloesPage(IWebDriver driver)
{
this.driver = driver;
}
public void Visita()
{
driver.Navigate().GoToUrl("http://localhost:8080/leiloes");
}
public NovoLeilaoPage Novo()
{
driver.FindElement(By.LinkText("Novo Leilão")).Click();
return new NovoLeilaoPage(driver);
}
public bool Existe(string produto, double valor, string usuario, bool usado)
{
return driver.PageSource.Contains(produto) &&
driver.PageSource.Contains(Convert.ToString(valor)) &&
driver.PageSource.Contains(usuario) &&
driver.PageSource.Contains(usado ? "Sim" : "Não");
}
public DetalhesLeilaoPage Detalhes (int posicao)
{
driver.FindElements(By.LinkText("exibir"))[posicao - 1].Click();
return new DetalhesLeilaoPage(driver);
}
}