//Fixture
using Alura.LeilaoOnline.Tests.Helpers;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
namespace Alura.LeilaoOnline.Tests.Fixtures
{
public class TestFixture : IDisposable
{
public IWebDriver Driver { get; private set; }
//Setup
public TestFixture()
{
Driver = new ChromeDriver(TestHelpers.PastaDoExecutavel);
}
//TearDown
public void Dispose()
{
Driver.Quit();
}
}
}
//CollectionFixture
using System;
using System.Collections.Generic;
using System.Text;
using Alura.LeilaoOnline.Tests.Fixtures;
using Xunit;
namespace Alura.LeilaoOnline.Tests.Fixtures
{
[CollectionDefinition("Chrome Driver")]
public class CollectionFixtures : ICollectionFixture
{
// This class has no code, and is never created. Its purpose is simply
// to be the place to apply [CollectionDefinition] and all the
// ICollectionFixture<> interfaces.
}
}
//UnitTest
using Xunit;
using OpenQA.Selenium;
using Alura.LeilaoOnline.Tests.Fixtures;
namespace XUnitTestProject1
{
[Collection("Chrome Driver")]
public class AoNavegarParaHome
{
private IWebDriver driver;
//gerar Construtor ctor
//Setup Através das Fixtures
public AoNavegarParaHome(TestFixture fixture)
{
driver = fixture.Driver;
}
[Fact]
public void DadoChromeAbertoDeveMostrarLeiloesNoTitulo()
{
//Arrange
//Act
driver.Navigate().GoToUrl("http://localhost:5000");
//Assert
Assert.Contains("Leilões", driver.Title);
}
[Fact]
public void DadoChromeAbertoDeveMostrarProximosLeiloes()
{
//Arrange
//Act
driver.Navigate().GoToUrl("http://localhost:5000");
//Assert
Assert.Contains("Próximos Leilões", driver.PageSource);
}
}
}