Radarr/src/NzbDrone.Automation.Test/AutomationTest.cs

78 lines
2.3 KiB
C#
Raw Normal View History

2013-11-20 00:42:17 +00:00
using System.Collections.Generic;
2013-11-12 03:25:54 +00:00
using System.Linq;
using FluentAssertions;
using NLog;
using NLog.Config;
using NLog.Targets;
using NUnit.Framework;
using NzbDrone.Automation.Test.PageModel;
2013-11-12 03:25:54 +00:00
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Test.Common;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
2013-11-12 06:18:57 +00:00
using OpenQA.Selenium.Remote;
2013-11-12 03:25:54 +00:00
namespace NzbDrone.Automation.Test
{
[TestFixture]
[AutomationTest]
public abstract class AutomationTest
{
private NzbDroneRunner _runner;
2013-11-12 06:18:57 +00:00
protected RemoteWebDriver driver;
2013-11-12 03:25:54 +00:00
public AutomationTest()
{
2013-11-26 06:53:36 +00:00
new StartupContext();
2013-11-12 03:25:54 +00:00
LogManager.Configuration = new LoggingConfiguration();
var consoleTarget = new ConsoleTarget { Layout = "${level}: ${message} ${exception}" };
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
2016-12-09 02:06:56 +00:00
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", NLog.LogLevel.Trace, consoleTarget));
2013-11-12 03:25:54 +00:00
}
[OneTimeSetUp]
2013-11-12 03:25:54 +00:00
public void SmokeTestSetup()
{
var options = new FirefoxOptions();
options.AddArguments("--headless");
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
2019-12-22 22:08:53 +00:00
// service.Host = "::1"; // Workaround netcore/selenium bug https://github.com/SeleniumHQ/selenium/issues/7840
2019-12-22 22:08:53 +00:00
driver = new FirefoxDriver(service, options, new System.TimeSpan(0, 3, 0));
2013-11-12 03:25:54 +00:00
2014-12-17 07:12:26 +00:00
_runner = new NzbDroneRunner(LogManager.GetCurrentClassLogger());
2013-11-12 03:25:54 +00:00
_runner.KillAll();
_runner.Start();
driver.Url = "http://localhost:7878";
2013-11-12 03:25:54 +00:00
var page = new PageBase(driver);
page.WaitForNoSpinner();
2013-11-12 03:25:54 +00:00
driver.ExecuteScript("window.Radarr.NameViews = true;");
2015-02-04 19:09:34 +00:00
2013-11-12 03:25:54 +00:00
GetPageErrors().Should().BeEmpty();
}
protected IEnumerable<string> GetPageErrors()
{
return driver.FindElements(By.CssSelector("#errors div"))
.Select(e => e.Text);
}
[OneTimeTearDown]
2013-11-12 03:25:54 +00:00
public void SmokeTestTearDown()
{
_runner.KillAll();
2013-11-12 06:18:57 +00:00
driver.Quit();
2013-11-12 03:25:54 +00:00
}
2013-11-12 06:18:57 +00:00
[TearDown]
public void AutomationTearDown()
2013-11-12 03:25:54 +00:00
{
2013-11-12 06:18:57 +00:00
GetPageErrors().Should().BeEmpty();
2013-11-12 03:25:54 +00:00
}
}
}