Я только что создал новый проект с Nunit, я пытаюсь заставить работать драйвер FireFox, но получаю следующую ошибку:
OneTimeSetUp: System.TypeInitializationException : The type initializer for 'SetupEnvironment.BaseTest' threw an exception.
----> System.InvalidOperationException : Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line (SessionNotCreated)
Я попытался добавить пути к файлам для geckoDriver и FireFox драйвер.
Было бы здорово, если бы кто-то мог помочь.
Код:
using NUnit.Framework;
using OpenQA.Selenium;
using System;
using AventStack.ExtentReports;
using OpenQA.Selenium.Firefox;
using AventStack.ExtentReports.Reporter;
namespace SetupEnvironment
{
[SetUpFixture]
public class BaseTest
{
public static IWebDriver driver = new FirefoxDriver();
public static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
public static new ExtentTest ReporterTest;
public static new ExtentHtmlReporter htmlReporter;
public static new ExtentReports extent;
public static new Exception LastException { get; private set; }
[OneTimeSetUp]
public void Initialize()
{
//Give the path of the geckodriver.exe
var service = FirefoxDriverService.CreateDefaultService(@"filepath", "geckodriver.exe");
service.FirefoxBinaryPath = @"filepath";
driver = new FirefoxDriver(service);
}
[OneTimeTearDown]
public void CleanUp()
{
htmlReporter = new ExtentHtmlReporter("C:\\Reports\\report.html");
extent = new ExtentReports();
extent.AttachReporter(htmlReporter);
extent.Flush();
driver.Quit();
}
}
}
Тестовая страница:
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using System;
using System.Net;
namespace SetupEnvironment
{
[Parallelizable]
public class EntryPoint
{
[SetUp]
public void TestSetup()
{
BaseTest.ReporterTest = BaseTest.ReporterTest.Extent.CreateTest(TestContext.CurrentContext.Test.Name);
BaseTest.Logger.Info($"|**|Nunit Test [{TestContext.CurrentContext.Test.Name}] STARTED |**|");
}
[Test]
[Category("Parallel Search Engine Tests")]
public void GoogleTest1()
{
var url = "www.google.co.uk";
BaseTest.driver.Navigate().GoToUrl(url);
}
[TearDown]
public void WebFixtureCleanup()
{
if (TestContext.CurrentContext.Result.Outcome.Equals(ResultState.Failure))
{
try
{
BaseTest.ReporterTest.Fail(WebUtility.HtmlEncode(BaseTest.LastException.Message));
}
catch (Exception exception)
{
BaseTest.ReporterTest.Fail(WebUtility.HtmlEncode(exception.ToString()));
}
}
else
{
BaseTest.ReporterTest.Pass(TestContext.CurrentContext.Test.Name);
}
BaseTest.Logger.Info($"|**| Nunit Test [{TestContext.CurrentContext.Test.Name}] COMPLETED |**|");
}
}
}