|
|
@ -11,12 +11,15 @@ using OpenQA.Selenium.Remote;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.UI.Automation
|
|
|
|
namespace NzbDrone.Web.UI.Automation
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
[Explicit]
|
|
|
|
public abstract class AutomationTestBase
|
|
|
|
public abstract class AutomationTestBase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
static readonly EnviromentProvider enviromentProvider = new EnviromentProvider();
|
|
|
|
private static readonly EnviromentProvider enviromentProvider = new EnviromentProvider();
|
|
|
|
private static readonly string testFolder;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string AppUrl
|
|
|
|
private readonly string _clonePackagePath;
|
|
|
|
|
|
|
|
private readonly string _masterPackagePath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected string AppUrl
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get
|
|
|
|
get
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -24,16 +27,18 @@ namespace NzbDrone.Web.UI.Automation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected AutomationTestBase()
|
|
|
|
public RemoteWebDriver Driver { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static AutomationTestBase()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CleanBinFolder();
|
|
|
|
var rawPackagePath = Path.Combine(enviromentProvider.ApplicationPath, "_rawPackage");
|
|
|
|
testFolder = CreatePackage();
|
|
|
|
_clonePackagePath = Path.Combine(rawPackagePath, "NzbDrone_Automation");
|
|
|
|
StartNzbDrone();
|
|
|
|
_masterPackagePath = Path.Combine(rawPackagePath, "NzbDrone");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected RemoteWebDriver Driver { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
[SetUp]
|
|
|
|
public void AutomationSetup()
|
|
|
|
public void AutomationSetup()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -62,18 +67,26 @@ namespace NzbDrone.Web.UI.Automation
|
|
|
|
public void AutomationTestFixtureSetup()
|
|
|
|
public void AutomationTestFixtureSetup()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
StopNzbDrone();
|
|
|
|
StopNzbDrone();
|
|
|
|
ResetUserData();
|
|
|
|
|
|
|
|
StartNzbDrone();
|
|
|
|
|
|
|
|
|
|
|
|
DeleteClone();
|
|
|
|
|
|
|
|
ClonePackage();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//StartNzbDrone();
|
|
|
|
|
|
|
|
InstallNzbDroneService();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new HttpProvider().DownloadString(AppUrl);
|
|
|
|
|
|
|
|
|
|
|
|
Driver = new FirefoxDriver();
|
|
|
|
Driver = new FirefoxDriver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestFixtureTearDown]
|
|
|
|
[TestFixtureTearDown]
|
|
|
|
public void AutomationTestFixtureTearDown()
|
|
|
|
public void AutomationTestFixtureTearDown()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Driver.Close();
|
|
|
|
Driver.Close();
|
|
|
|
StopNzbDrone();
|
|
|
|
StopNzbDrone();
|
|
|
|
|
|
|
|
|
|
|
|
File.Copy(Path.Combine(testFolder, "nzbdrone.log"), Path.Combine(Directory.GetCurrentDirectory(), "nzbdrone.log"), true);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -86,70 +99,90 @@ namespace NzbDrone.Web.UI.Automation
|
|
|
|
((ITakesScreenshot)Driver).GetScreenshot().SaveAsFile(fileName, ImageFormat.Png);
|
|
|
|
((ITakesScreenshot)Driver).GetScreenshot().SaveAsFile(fileName, ImageFormat.Png);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ResetUserData()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var appDataPath = Path.Combine(testFolder, "NzbDrone.Web", "app_data");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Directory.Exists(appDataPath))
|
|
|
|
|
|
|
|
Directory.Delete(appDataPath, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private void StartNzbDrone()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
StartProcess("nzbdrone.exe", false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void CleanBinFolder()
|
|
|
|
private void StopNzbDrone()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var folderName = "Debug";
|
|
|
|
foreach (var process in Process.GetProcessesByName("nzbdrone"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
process.Kill();
|
|
|
|
|
|
|
|
process.WaitForExit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (EnviromentProvider.IsDebug)
|
|
|
|
foreach (var process in Process.GetProcessesByName("iisexpress"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
folderName = "Release";
|
|
|
|
process.Kill();
|
|
|
|
|
|
|
|
process.WaitForExit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var dirs = Directory.GetDirectories(enviromentProvider.ApplicationPath, folderName, SearchOption.AllDirectories);
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
StartProcess("ServiceUninstall.exe", true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var dir in dirs)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Directory.Delete(dir, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void InstallNzbDroneService()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
StartProcess("ServiceInstall.exe", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void StartNzbDrone()
|
|
|
|
private void StartProcess(string fileName, bool waitForExit)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var startInfo = new ProcessStartInfo
|
|
|
|
var startInfo = new ProcessStartInfo
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FileName = Path.Combine(testFolder, "nzbdrone.exe"),
|
|
|
|
FileName = Path.Combine(_clonePackagePath, fileName),
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
UseShellExecute = false
|
|
|
|
RedirectStandardError = true,
|
|
|
|
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var nzbDroneProcess = new Process
|
|
|
|
var nzbDroneProcess = new Process
|
|
|
|
{
|
|
|
|
{
|
|
|
|
StartInfo = startInfo
|
|
|
|
StartInfo = startInfo
|
|
|
|
};
|
|
|
|
};
|
|
|
|
nzbDroneProcess.OutputDataReceived +=
|
|
|
|
|
|
|
|
delegate(object o, DataReceivedEventArgs args)
|
|
|
|
nzbDroneProcess.OutputDataReceived += (o, args) => Console.WriteLine(args.Data);
|
|
|
|
{
|
|
|
|
nzbDroneProcess.ErrorDataReceived += (o, args) => Console.WriteLine(args.Data);
|
|
|
|
Console.WriteLine(args.Data);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nzbDroneProcess.Start();
|
|
|
|
nzbDroneProcess.Start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nzbDroneProcess.BeginErrorReadLine();
|
|
|
|
|
|
|
|
nzbDroneProcess.BeginOutputReadLine();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (waitForExit)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nzbDroneProcess.WaitForExit();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void ClonePackage()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
new DiskProvider().CopyDirectory(_masterPackagePath, _clonePackagePath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void StopNzbDrone()
|
|
|
|
private void DeleteClone()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (var process in Process.GetProcessesByName("nzbdrone"))
|
|
|
|
if (Directory.Exists(_clonePackagePath))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
process.Kill();
|
|
|
|
Directory.Delete(_clonePackagePath, true);
|
|
|
|
process.WaitForExit();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static string CreatePackage()
|
|
|
|
private string CreatePackage()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.WriteLine("Creating NzbDrone Package");
|
|
|
|
Console.WriteLine("Creating NzbDrone Package");
|
|
|
|
|
|
|
|
|
|
|
@ -183,5 +216,32 @@ namespace NzbDrone.Web.UI.Automation
|
|
|
|
|
|
|
|
|
|
|
|
return testFolder;
|
|
|
|
return testFolder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void ResetUserData()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var appDataPath = Path.Combine(_clonePackagePath, "NzbDrone.Web", "app_data");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Directory.Exists(appDataPath))
|
|
|
|
|
|
|
|
Directory.Delete(appDataPath, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void CleanBinFolder()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var folderName = "Debug";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (EnviromentProvider.IsDebug)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
folderName = "Release";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dirs = Directory.GetDirectories(enviromentProvider.ApplicationPath, folderName, SearchOption.AllDirectories);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var dir in dirs)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Directory.Delete(dir, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|