1
resposta

O Assert não retorna True, mesmo o cadastro existindo na listagem!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;

namespace TesteAutomatizado.Pages
{
    public class NovoLeilaoPage
    {
        IWebDriver driver;

        public NovoLeilaoPage(IWebDriver driver)
        {
            this.driver = driver;
        }

        public void Cadastra(string nomeDoItem, double valorDoItem, string usuario, bool usado)
        {
            IWebElement txtNome = driver.FindElement(By.Name("leilao.nome"));
            IWebElement txtValor = driver.FindElement(By.Name("leilao.valorInicial"));

            txtNome.SendKeys(nomeDoItem);
            txtValor.SendKeys(valorDoItem.ToString());

            SelectElement cbUsuario = new SelectElement(driver.FindElement(By.Name("leilao.usuario.id")));
            cbUsuario.SelectByText(usuario);

            if (usado)
            {
                driver.FindElement(By.Name("leilao.usado")).Click();
            }

            txtNome.Submit();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace TesteAutomatizado.Pages
{
    public class LeilaoPage
    {
        IWebDriver driver;

        public LeilaoPage(IWebDriver driver)
        {
            this.driver = driver;
        }

        public void Visita()
        {
            driver.Navigate().GoToUrl("http://localhost:8080/leiloes");
        }

        public NovoLeilaoPage Novo()
        {
            driver.Navigate().GoToUrl("http://localhost:8080/leiloes/new");
            return new NovoLeilaoPage(driver);
        }

        public bool existeNaListagem(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");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using TesteAutomatizado.Pages;

namespace TesteAutomatizado.testes
{
    [TestFixture]
    class LeilaoSystemTest
    {
        private LeilaoPage leilao;


        [SetUp] 
        public void Inicializa()
        {
            IWebDriver driver = new FirefoxDriver();
            this.leilao = new LeilaoPage(driver);
            UsuarioPage usuario  = new UsuarioPage(driver);

            usuario.Visita();
            usuario.Novo().Cadastra("Paulo Henrique","isabela@gmail.com");
        }
        [Test]
        public void DeveCadastrarLeilao()
        {
            leilao.Visita();
            leilao.Novo().Cadastra("Geladeira",123,"Paulo Henrique",true);
            Assert.IsTrue(leilao.existeNaListagem("Geladeira", 123,"Paulo Henrique", true));
        }
    }
}
1 resposta

Oi Isabela, tudo bem?

Por favor, coloque uns breakpoints no código e veja quais parâmetros estão sendo passados para o método existeNaListagem.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software