mirror of
https://github.com/Jackett/Jackett.git
synced 2025-10-02 08:34:32 +02:00
core: Add Integration Tests (#7023)
Add some basic integration tests for Jackett
This commit is contained in:
110
src/Jackett.IntegrationTests/DashboardTests.cs
Normal file
110
src/Jackett.IntegrationTests/DashboardTests.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Support.UI;
|
||||
|
||||
namespace Jackett.IntegrationTests
|
||||
{
|
||||
[TestClass]
|
||||
public class DashboardTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void CheckTitle()
|
||||
{
|
||||
string pageTitle = _webDriver.Title;
|
||||
Assert.AreEqual("Jackett", pageTitle);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DefaultPortShown()
|
||||
{
|
||||
string port = _webDriver.FindElement(By.CssSelector("#jackett-port")).GetAttribute("value");
|
||||
Assert.AreEqual("9117", port);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IndexerTableIsPresent()
|
||||
{
|
||||
IWebElement table = _webDriver.FindElement(By.CssSelector("#configured-indexer-datatable"));
|
||||
Assert.IsNotNull(table);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AddIndexerOpens()
|
||||
{
|
||||
_webDriver.FindElement(By.CssSelector("#jackett-add-indexer")).Click();
|
||||
WaitUntilModalIsDisplayed("#select-indexer-modal h4");
|
||||
string modalHeading = _webDriver.FindElement(By.CssSelector("#select-indexer-modal h4")).Text;
|
||||
Assert.AreEqual("Select an indexer to setup", modalHeading);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CheckIndexersAreAvailableToAdd()
|
||||
{
|
||||
_webDriver.FindElement(By.CssSelector("#jackett-add-indexer")).Click();
|
||||
WaitUntilModalIsDisplayed("#select-indexer-modal h4");
|
||||
int indexerCount = _webDriver.FindElements(By.CssSelector("#unconfigured-indexer-datatable tbody tr")).Count;
|
||||
Assert.IsTrue(indexerCount > 400);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ManualSearchOpens()
|
||||
{
|
||||
_webDriver.FindElement(By.CssSelector("#jackett-show-search")).Click();
|
||||
WaitUntilModalIsDisplayed("#select-indexer-modal div.modal-body p");
|
||||
string modalDescription = _webDriver.FindElement(By.CssSelector("#select-indexer-modal div.modal-body p")).Text;
|
||||
Assert.AreEqual("You can search all configured indexers from this screen.", modalDescription);
|
||||
}
|
||||
|
||||
|
||||
[ClassInitialize]
|
||||
public static void StartBrowser(TestContext testContext)
|
||||
{
|
||||
_webDriver = WebDriverFactory.CreateFromEnvironmentVariableSettings();
|
||||
_webDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(20);
|
||||
_webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
|
||||
_webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(20);
|
||||
}
|
||||
|
||||
[ClassCleanup]
|
||||
public static void StopBrowser()
|
||||
{
|
||||
_webDriver?.Quit();
|
||||
}
|
||||
|
||||
[TestInitialize]
|
||||
public void LoadDashboard()
|
||||
{
|
||||
string url = "http://localhost:9117/UI/Dashboard";
|
||||
Console.WriteLine($"Url for test: {url}");
|
||||
_webDriver.Navigate().GoToUrl(url);
|
||||
|
||||
WebDriverWait wait = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(20));
|
||||
IWebElement element = wait.Until(x => x.FindElement(By.CssSelector("#configured-indexer-datatable")));
|
||||
}
|
||||
|
||||
private bool WaitUntilModalIsDisplayed(string cssSelector)
|
||||
{
|
||||
WebDriverWait wait = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(5));
|
||||
var element = wait.Until(condition =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var elementToBeDisplayed = _webDriver.FindElement(By.CssSelector(cssSelector));
|
||||
return elementToBeDisplayed.Displayed;
|
||||
}
|
||||
catch (StaleElementReferenceException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (NoSuchElementException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
private static IWebDriver _webDriver;
|
||||
}
|
||||
}
|
17
src/Jackett.IntegrationTests/Jackett.IntegrationTests.csproj
Normal file
17
src/Jackett.IntegrationTests/Jackett.IntegrationTests.csproj
Normal file
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="1.0.1" />
|
||||
<PackageReference Include="Selenium.Chrome.WebDriver" Version="79.0.0" />
|
||||
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
60
src/Jackett.IntegrationTests/WebDriverFactory.cs
Normal file
60
src/Jackett.IntegrationTests/WebDriverFactory.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Chrome;
|
||||
using System;
|
||||
|
||||
namespace Jackett.IntegrationTests
|
||||
{
|
||||
// This factory class is just one example of how you might initialize Selenium. If your project already has its own means
|
||||
// of initializing Selenium, you can keep using that as-is and ignore this sample file; skip ahead to SamplePageTests.cs.
|
||||
public static class WebDriverFactory
|
||||
{
|
||||
public static IWebDriver CreateFromEnvironmentVariableSettings() {
|
||||
// This environment variable gets set by our Azure Pipelines build definition in ./azure-pipelines.yml.
|
||||
// That file uses a matrix strategy to run multiple different build jobs for different combinations of OS/browser.
|
||||
// Each job sets this environment variable accordingly, and we use it to decide which browser the tests will use.
|
||||
const string BROWSER_ENVIRONMENT_VARIABLE = "SELENIUM_BROWSER";
|
||||
var browserEnvVar = Environment.GetEnvironmentVariable(BROWSER_ENVIRONMENT_VARIABLE);
|
||||
|
||||
// It's convenient to have a default to make it easier for a developer to run a plain "dotnet test" command.
|
||||
// In our CI builds in Azure Pipelines, we'll always specify the browser explicitly instead of using this.
|
||||
const string DEFAULT_BROWSER = "chrome";
|
||||
|
||||
// Headless browsers generally use small window sizes by default. Some of the axe checks require
|
||||
// elements to be present in the viewport to be assessable, so using a viewport size based on your
|
||||
// most common usage is a good idea to prevent axe from having to do extra work to scroll items into
|
||||
// view and avoid issues with elements not fitting into the viewport.
|
||||
const int windowWidth = 1920;
|
||||
const int windowHeight = 1080;
|
||||
|
||||
switch (browserEnvVar ?? DEFAULT_BROWSER)
|
||||
{
|
||||
case "chrome":
|
||||
// The ChromeWebDriver environment variable comes pre-set in the Azure Pipelines VM Image we
|
||||
// specify in azure-pipelines.yml. ChromeDriver requires that you use *matching* versions of Chrome and
|
||||
// the Chrome WebDriver; in the build agent VMs, using this environment variable will make sure that we use
|
||||
// the pre-installed version of ChromeDriver that matches the pre-installed version of Chrome.
|
||||
//
|
||||
// See https://docs.microsoft.com/en-us/azure/devops/pipelines/test/continuous-test-selenium
|
||||
//
|
||||
// Environment.CurrentDirectory is where the Selenium.Webdriver.ChromeDriver NuGet package will place the
|
||||
// version of the Chrome WebDriver that it comes with. We fall back to this so that if a developer working on
|
||||
// the project hasn't separately installed ChromeDriver, the test will still be able to run on their machine.
|
||||
var chromeDriverDirectory = Environment.GetEnvironmentVariable("CHROMEWEBDRIVER") ?? Environment.CurrentDirectory;
|
||||
|
||||
// The tests will work fine in non-headless mode; we recommend using --headless for performance and
|
||||
// because it makes it easier to run the tests in non-graphical environments (eg, most Docker containers)
|
||||
var chromeOptions = new ChromeOptions();
|
||||
chromeOptions.AddArgument("--headless");
|
||||
chromeOptions.AddArgument($"--window-size={windowWidth},{windowHeight}");
|
||||
|
||||
return new ChromeDriver(chromeDriverDirectory, chromeOptions);
|
||||
|
||||
default:
|
||||
throw new ArgumentException($"Unknown browser type '{browserEnvVar}' specified in '{BROWSER_ENVIRONMENT_VARIABLE}' environment variable");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user