Запуск нового браузера для каждого теста из набора
Есть набор автотестов. Когда запускаю в ручную по одному каждый проходит отлично, а когда запускаю что бы все тесты выполнялись по порядку, то проходит только один тест(первый). Как сделать что бы на каждый тест по новому открывался браузер, тест выполнялся и браузер закрывался?
Здесь инициализация браузера
public class TestBase
{
protected IWebDriver Driver { get; set; }
public TestBase()
{
//var browser = TestContext.Parameters.Get("browser");
var browser = "Chrome";
if (!Enum.TryParse(browser, out BrowserType browserType))
{
throw new Exception("Browser parameter is not valid");
}
var driverFactory = new BrowserFactory();
Driver = driverFactory.GetDriver(browserType);
}
[TearDown]
public void TearDown()
{
Driver.Quit();
}
}
Тут сами тесты
[TestFixture]
public class EmailTest : TestBase
{
private MainPage _mainPage;
private EmailPage _emailPage;
private LoginPage _loginPage;
private InfoFromJsonFile _jsonFile;
private TestData _testData;
public EmailTest()
{
_mainPage = new MainPage(Driver);
_emailPage = new EmailPage(Driver);
_loginPage = new LoginPage(Driver);
_jsonFile = new InfoFromJsonFile();
_testData = _jsonFile.GetTestData();
}
[SetUp]
public void Setup()
{
Driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(20);
Driver.Manage().Window.Maximize();
Driver.Navigate().GoToUrl(_testData.YandexUrl);
}
[Test]
public void OpenEmail_CheckUserName()
{
_mainPage.ClickEmailLoginButton();
_loginPage.LoginInput(_testData.ValidLogin);
_loginPage.ClickLoginButton();
_loginPage.PasswordInput(_testData.ValidPassword);
_loginPage.ClickLoginButton();
var userName = _emailPage.GetUserName();
Assert.AreEqual(_testData.ValidLogin, userName);
}
[Test]
public void QuitFromEmailAccount()
{
_mainPage.ClickEmailLoginButton();
_loginPage.LoginInput(_testData.ValidLogin);
_loginPage.ClickLoginButton();
_loginPage.PasswordInput(_testData.ValidPassword);
_loginPage.ClickLoginButton();
var emailPageUrl = Driver.Url;
_emailPage.LogOut();
var currentUrl = Driver.Url;
Assert.AreNotEqual(emailPageUrl, currentUrl);
}
Вот так такой результат запуска набора тестов.
Текст ошибки
Message:
OpenQA.Selenium.WebDriverException : A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:54653/session//timeouts. The status of the exception was UnknownError, and the message was: No connection could be made because the target machine actively refused it. No connection could be made because the target machine actively refused it.
----> System.Net.WebException : No connection could be made because the target machine actively refused it. No connection could be made because the target machine actively refused it.
----> System.Net.Http.HttpRequestException : No connection could be made because the target machine actively refused it.
----> System.Net.Sockets.SocketException : No connection could be made because the target machine actively refused it.
TearDown : OpenQA.Selenium.WebDriverException : A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:54653/session//window/handles. The status of the exception was UnknownError, and the message was: No connection could be made because the target machine actively refused it. No connection could be made because the target machine actively refused it.
----> System.Net.WebException : No connection could be made because the target machine actively refused it. No connection could be made because the target machine actively refused it.
----> System.Net.Http.HttpRequestException : No connection could be made because the target machine actively refused it.
----> System.Net.Sockets.SocketException : No connection could be made because the target machine actively refused it.
Ответы (1 шт):
Автор решения: Павел Панасюк
→ Ссылка
Проблему решил но не открытием нового браузера. Перед стартом каждого теста, делаю очистку Cookes и открываю новую вкладку. Таким образом при каждом новом логине получаю пустой браузер.
