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

94 lines
2.8 KiB
C#
Raw Normal View History

using System;
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.Chrome;
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
}
2019-08-08 02:08:03 +00:00
[OneTimeSetUp]
2013-11-12 03:25:54 +00:00
public void SmokeTestSetup()
{
var options = new ChromeOptions();
options.AddArguments("--headless");
var service = ChromeDriverService.CreateDefaultService();
// Timeout as windows automation tests seem to take alot longer to get going
driver = new ChromeDriver(service, options, new TimeSpan(0, 3, 0));
driver.Manage().Window.Size = new System.Drawing.Size(1920, 1080);
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:8989";
var page = new PageBase(driver);
page.WaitForNoSpinner();
2013-11-12 03:25:54 +00:00
driver.ExecuteScript("window.Sonarr.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);
}
protected void TakeScreenshot(string name)
{
try
{
Screenshot image = ((ITakesScreenshot)driver).GetScreenshot();
image.SaveAsFile($"./{name}_test_screenshot.png", ScreenshotImageFormat.Png);
}
catch (Exception ex)
{
Console.WriteLine($"Failed to save screenshot {name}, {ex.Message}");
}
}
2019-08-08 02:08:03 +00:00
[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
}
}
}