From 3974fcfb919c95a9ce76192aad1147f691b4ed36 Mon Sep 17 00:00:00 2001 From: 6d486f49 Date: Mon, 1 Jun 2026 09:58:44 -0400 Subject: [PATCH] Removing legacy test automation --- IGP/IGP.sln | 6 - TestAutomation/BaseTest.cs | 43 ---- TestAutomation/Enums/WindowType.cs | 8 - TestAutomation/Pages/BasePage.cs | 29 --- TestAutomation/Pages/DatabasePage.cs | 53 ----- TestAutomation/Pages/DatabaseSinglePage.cs | 49 ----- TestAutomation/Pages/HarassCalculatorPage.cs | 99 --------- TestAutomation/Shared/BaseElement.cs | 13 -- TestAutomation/Shared/NavigationBar.cs | 25 --- TestAutomation/Shared/WebsiteSearchDialog.cs | 32 --- TestAutomation/TestAutomation.csproj | 28 --- TestAutomation/TestHarassCalculator.cs | 95 -------- TestAutomation/TestLinks.cs | 30 --- TestAutomation/TestSearchFeatures.cs | 84 -------- TestAutomation/Utils/Test.cs | 8 - TestAutomation/Utils/TestMessage.cs | 13 -- TestAutomation/Utils/TestReport.cs | 111 ---------- TestAutomation/Utils/Usings.cs | 7 - TestAutomation/Utils/Website.cs | 216 ------------------- TestAutomation/_Tests.cs | 33 --- 20 files changed, 982 deletions(-) delete mode 100644 TestAutomation/BaseTest.cs delete mode 100644 TestAutomation/Enums/WindowType.cs delete mode 100644 TestAutomation/Pages/BasePage.cs delete mode 100644 TestAutomation/Pages/DatabasePage.cs delete mode 100644 TestAutomation/Pages/DatabaseSinglePage.cs delete mode 100644 TestAutomation/Pages/HarassCalculatorPage.cs delete mode 100644 TestAutomation/Shared/BaseElement.cs delete mode 100644 TestAutomation/Shared/NavigationBar.cs delete mode 100644 TestAutomation/Shared/WebsiteSearchDialog.cs delete mode 100644 TestAutomation/TestAutomation.csproj delete mode 100644 TestAutomation/TestHarassCalculator.cs delete mode 100644 TestAutomation/TestLinks.cs delete mode 100644 TestAutomation/TestSearchFeatures.cs delete mode 100644 TestAutomation/Utils/Test.cs delete mode 100644 TestAutomation/Utils/TestMessage.cs delete mode 100644 TestAutomation/Utils/TestReport.cs delete mode 100644 TestAutomation/Utils/Usings.cs delete mode 100644 TestAutomation/Utils/Website.cs delete mode 100644 TestAutomation/_Tests.cs diff --git a/IGP/IGP.sln b/IGP/IGP.sln index 5a1bc57..b2b93e6 100644 --- a/IGP/IGP.sln +++ b/IGP/IGP.sln @@ -11,8 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "..\Components EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "..\Services\Services.csproj", "{621178C8-4E8B-478E-80E5-7478F0E7B67E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAutomation", "..\TestAutomation\TestAutomation.csproj", "{8B49D038-D013-460D-9C4F-817CAFFEB06F}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -35,10 +33,6 @@ Global {621178C8-4E8B-478E-80E5-7478F0E7B67E}.Debug|Any CPU.Build.0 = Debug|Any CPU {621178C8-4E8B-478E-80E5-7478F0E7B67E}.Release|Any CPU.ActiveCfg = Release|Any CPU {621178C8-4E8B-478E-80E5-7478F0E7B67E}.Release|Any CPU.Build.0 = Release|Any CPU - {8B49D038-D013-460D-9C4F-817CAFFEB06F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8B49D038-D013-460D-9C4F-817CAFFEB06F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8B49D038-D013-460D-9C4F-817CAFFEB06F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8B49D038-D013-460D-9C4F-817CAFFEB06F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TestAutomation/BaseTest.cs b/TestAutomation/BaseTest.cs deleted file mode 100644 index 087fdb8..0000000 --- a/TestAutomation/BaseTest.cs +++ /dev/null @@ -1,43 +0,0 @@ -using TestAutomation.Utils; - -namespace TestAutomation; - -public enum DeploymentType -{ - Dev, - Local -} - -public class BaseTest -{ - protected static readonly TestReport TestReport = new(); - - - protected static Website WebsiteInstance = default!; - protected readonly HttpClient HttpClient = new(); - - protected static Website Website - { - get - { - if (WebsiteInstance == null) - { - var options = new FirefoxOptions(); - - options.AcceptInsecureCertificates = true; - - if (Website.DeploymentType.Equals(DeploymentType.Dev)) options.AddArgument("--headless"); - options.AddArgument("--ignore-certificate-errors"); - options.AddArgument("--start-maximized"); - options.AddArgument("--test-type"); - options.AddArgument("--allow-running-insecure-content"); - - IWebDriver webDriver = new FirefoxDriver(Environment.CurrentDirectory, options); - - WebsiteInstance = new Website(webDriver, TestReport); - } - - return WebsiteInstance; - } - } -} \ No newline at end of file diff --git a/TestAutomation/Enums/WindowType.cs b/TestAutomation/Enums/WindowType.cs deleted file mode 100644 index 2616a93..0000000 --- a/TestAutomation/Enums/WindowType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace TestAutomation.Enums; - -public enum ScreenType -{ - Desktop, - Tablet, - Mobile -} \ No newline at end of file diff --git a/TestAutomation/Pages/BasePage.cs b/TestAutomation/Pages/BasePage.cs deleted file mode 100644 index 4aee351..0000000 --- a/TestAutomation/Pages/BasePage.cs +++ /dev/null @@ -1,29 +0,0 @@ -using TestAutomation.Shared; -using TestAutomation.Utils; - -namespace TestAutomation.Pages; - -public abstract class BasePage : BaseElement -{ - protected BasePage(Website website) : base(website) - { - } - - private IEnumerable Links => - Website.FindAllWithTag(Website.Find("content"), "a") - .Select(x => x.GetAttribute("href")); - - public abstract string Url { get; set; } - - public IEnumerable GetLinks() - { - try - { - return Links; - } - catch (Exception e) - { - throw new Exception($"Couldn't get links on page {Url}"); - } - } -} \ No newline at end of file diff --git a/TestAutomation/Pages/DatabasePage.cs b/TestAutomation/Pages/DatabasePage.cs deleted file mode 100644 index 8e4b1d3..0000000 --- a/TestAutomation/Pages/DatabasePage.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Collections.ObjectModel; -using TestAutomation.Utils; - -namespace TestAutomation.Pages; - -public class DatabasePage : BasePage -{ - public DatabasePage(Website website) : base(website) - { - } - - private IWebElement FilterNameInput => Website.Find("filterName"); - - public override string Url { get; set; } = "database"; - - - private ReadOnlyCollection EntityNames() - { - return Website.FindAll("entityName"); - } - - - private IWebElement EntityName(string entityType, string entityName) - { - return Website.Find("entityName", - $"{entityType.ToLower()}-{entityName.ToLower()}"); - } - - public DatabasePage FilterName(string name) - { - Website.EnterInput(FilterNameInput, name); - - return this; - } - - public DatabasePage GetEntityName(string entityType, string entityName, out string result) - { - result = EntityName(entityType, entityName).Text; - return this; - } - - public DatabasePage GetEntityName(int index, out string result) - { - result = EntityNames()[index].Text; - return this; - } - - public DatabasePage Goto() - { - Website.Goto(Url); - return this; - } -} \ No newline at end of file diff --git a/TestAutomation/Pages/DatabaseSinglePage.cs b/TestAutomation/Pages/DatabaseSinglePage.cs deleted file mode 100644 index e748d84..0000000 --- a/TestAutomation/Pages/DatabaseSinglePage.cs +++ /dev/null @@ -1,49 +0,0 @@ -using TestAutomation.Utils; - -namespace TestAutomation.Pages; - -public class DatabaseSinglePage : BasePage -{ - public DatabaseSinglePage(Website website) : base(website) - { - } - - private IWebElement EntityName => Website.Find("entityName"); - private IWebElement EntityHealth => Website.Find("entityHealth"); - - private IWebElement InvalidSearch => Website.Find("invalidSearch"); - private IWebElement ValidSearch => Website.Find("validSearch"); - - public override string Url { get; set; } = "database"; - - - public DatabaseSinglePage GetEntityName(out string result) - { - result = EntityName.Text; - return this; - } - - public DatabaseSinglePage GetEntityHealth(out string result) - { - result = EntityHealth.Text; - return this; - } - - public DatabaseSinglePage GetInvalidSearch(out string result) - { - result = InvalidSearch.Text; - return this; - } - - public DatabaseSinglePage GetValidSearch(out string result) - { - result = ValidSearch.Text; - return this; - } - - public DatabaseSinglePage Goto(string searchText) - { - Website.Goto($"{Url}/{searchText}"); - return this; - } -} \ No newline at end of file diff --git a/TestAutomation/Pages/HarassCalculatorPage.cs b/TestAutomation/Pages/HarassCalculatorPage.cs deleted file mode 100644 index d45ceae..0000000 --- a/TestAutomation/Pages/HarassCalculatorPage.cs +++ /dev/null @@ -1,99 +0,0 @@ -using TestAutomation.Utils; - -namespace TestAutomation.Pages; - -public class HarassCalculatorPage : BasePage -{ - public HarassCalculatorPage(Website website) : base(website) - { - } - - private IWebElement NumberOfWorkersLostToHarass => Website.Find("numberOfWorkersLostToHarass"); - private IWebElement NumberOfTownHallsExisting => Website.Find("numberOfTownHallsExisting"); - private IList OnTownHallTravelTimes => Website.FindChildren("numberOfTownHallTravelTimes", "input"); - private int TotalAlloyHarassment => Website.FindInt("totalAlloyHarassment"); - private int WorkerReplacementCost => Website.FindInt("workerReplacementCost"); - private int DelayedMiningCost => Website.FindInt("delayedMiningCost"); - private int AverageTravelTime => Website.FindInt("getAverageTravelTime"); - - private int ExampleTotalAlloyLoss => Website.FindInt("exampleTotalAlloyLoss"); - private int ExampleWorkerCost => Website.FindInt("exampleWorkerCost"); - private int ExampleMiningTimeCost => Website.FindInt("exampleMiningTimeCost"); - private int ExampleTotalAlloyLossDifference => Website.FindInt("exampleTotalAlloyLossDifference"); - private int ExampleTotalAlloyLossAccurate => Website.FindInt("exampleTotalAlloyLossAccurate"); - private int ExampleTotalAlloyLossAccurateDifference => Website.FindInt("exampleTotalAlloyLossAccurateDifference"); - - public override string Url { get; set; } = "harass-calculator"; - - public HarassCalculatorPage SetWorkersLostToHarass(int number) - { - Website.EnterInput(NumberOfWorkersLostToHarass, number); - return this; - } - - public HarassCalculatorPage SetNumberOfTownHallsExisting(int number) - { - Website.EnterInput(NumberOfTownHallsExisting, number); - return this; - } - - public HarassCalculatorPage SetTownHallTravelTime(int forTownHall, int number) - { - Website.EnterInput(OnTownHallTravelTimes[forTownHall], number); - return this; - } - - public HarassCalculatorPage GetTotalAlloyHarassment(out int result) - { - result = TotalAlloyHarassment; - return this; - } - - - public HarassCalculatorPage GetExampleTotalAlloyLoss(out int result) - { - result = ExampleTotalAlloyLoss; - return this; - } - - public HarassCalculatorPage GetExampleWorkerCost(out int result) - { - result = ExampleWorkerCost; - return this; - } - - public HarassCalculatorPage GetExampleMiningTimeCost(out int result) - { - result = ExampleMiningTimeCost; - return this; - } - - public HarassCalculatorPage GetExampleTotalAlloyLossAccurate(out int result) - { - result = ExampleTotalAlloyLossAccurate; - return this; - } - - public HarassCalculatorPage GetExampleTotalAlloyLossDifference(out int result) - { - result = ExampleTotalAlloyLossDifference; - return this; - } - - public HarassCalculatorPage GetExampleTotalAlloyLossAccurateDifference(out int result) - { - result = ExampleTotalAlloyLossAccurateDifference; - return this; - } - - protected HarassCalculatorPage NavigateTo() - { - return this; - } - - public HarassCalculatorPage Goto() - { - Website.Goto(Url); - return this; - } -} \ No newline at end of file diff --git a/TestAutomation/Shared/BaseElement.cs b/TestAutomation/Shared/BaseElement.cs deleted file mode 100644 index 68f36f6..0000000 --- a/TestAutomation/Shared/BaseElement.cs +++ /dev/null @@ -1,13 +0,0 @@ -using TestAutomation.Utils; - -namespace TestAutomation.Shared; - -public abstract class BaseElement -{ - protected readonly Website Website; - - protected BaseElement(Website website) - { - Website = website; - } -} \ No newline at end of file diff --git a/TestAutomation/Shared/NavigationBar.cs b/TestAutomation/Shared/NavigationBar.cs deleted file mode 100644 index e9b7553..0000000 --- a/TestAutomation/Shared/NavigationBar.cs +++ /dev/null @@ -1,25 +0,0 @@ -using TestAutomation.Utils; - -namespace TestAutomation.Shared; - -public class NavigationBar : BaseElement -{ - public NavigationBar(Website website) : base(website) - { - } - - private IWebElement HomeLink => Website.FindScreenSpecific("homeLink"); - private IWebElement SearchButton => Website.FindScreenSpecific("searchButton"); - - public NavigationBar ClickHomeLink() - { - Website.Click(HomeLink); - return this; - } - - public WebsiteSearchDialog ClickSearchButton() - { - Website.Click(SearchButton); - return Website.WebsiteSearchDialog; - } -} \ No newline at end of file diff --git a/TestAutomation/Shared/WebsiteSearchDialog.cs b/TestAutomation/Shared/WebsiteSearchDialog.cs deleted file mode 100644 index 5ecf15a..0000000 --- a/TestAutomation/Shared/WebsiteSearchDialog.cs +++ /dev/null @@ -1,32 +0,0 @@ -using TestAutomation.Utils; - -namespace TestAutomation.Shared; - -public class WebsiteSearchDialog : BaseElement -{ - public WebsiteSearchDialog(Website website) : base(website) - { - } - - public IWebElement SearchBackground => Website.Find("searchBackground"); - - public IWebElement SearchInput => Website.Find("searchInput"); - - public NavigationBar CloseDialog() - { - Website.ClickTopLeft(); - return Website.NavigationBar; - } - - public WebsiteSearchDialog Search(string throne) - { - Website.EnterInput(SearchInput, throne); - return this; - } - - public DatabaseSinglePage SelectSearchEntity(string throne) - { - Website.Click(Website.FindButtonWithLabel(throne)); - return Website.DatabaseSinglePage; - } -} \ No newline at end of file diff --git a/TestAutomation/TestAutomation.csproj b/TestAutomation/TestAutomation.csproj deleted file mode 100644 index 0a1163b..0000000 --- a/TestAutomation/TestAutomation.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - net8.0 - enable - enable - - false - - - - - - - - - - - - - - - - - - - - diff --git a/TestAutomation/TestHarassCalculator.cs b/TestAutomation/TestHarassCalculator.cs deleted file mode 100644 index 0cfdf98..0000000 --- a/TestAutomation/TestHarassCalculator.cs +++ /dev/null @@ -1,95 +0,0 @@ -using TestAutomation.Utils; - -namespace TestAutomation; - -[TestFixture] -public class TestHarassCalculator : BaseTest -{ - [SetUp] - public void SetUp() - { - TestReport.CreateTest(); - } - - [TearDown] - public void TearDown() - { - TestReport.ThrowErrors(); - } - - [Test] - public void CalculatorInput() - { - var expectedTotalAlloyHarassment = 240; - - Website.HarassCalculatorPage - .Goto() - .SetWorkersLostToHarass(3) - .SetNumberOfTownHallsExisting(2) - .SetTownHallTravelTime(0, 30) - .GetTotalAlloyHarassment(out var foundTotalAlloyHarassment); - - TestReport.CheckPassed(expectedTotalAlloyHarassment.Equals(foundTotalAlloyHarassment), - TestMessage.CreateFailedMessage($"expectTotalAlloyHarassment of {expectedTotalAlloyHarassment} " + - "does not equal " + - $"foundTotalAlloyHarassment of {foundTotalAlloyHarassment} ")); - } - - [Test] - public void CalculatedExampleInformation() - { - var expectedExampleTotalAlloyLoss = 720; - var expectedExampleWorkerCost = 300; - var expectedExampleMiningTimeCost = 420; - var expectedExampleTotalAlloyLossDifference = 300; - var expectedExampleTotalAlloyLossAccurate = 450; - var expectedExampleTotalAlloyLossAccurateDifference = 270; - - Website.HarassCalculatorPage - .Goto() - .GetExampleTotalAlloyLoss(out var foundTotalAlloyLoss) - .GetExampleWorkerCost(out var foundExampleWorkerCost) - .GetExampleMiningTimeCost(out var foundExampleMiningTimeCost) - .GetExampleTotalAlloyLossAccurate(out var foundExampleTotalAlloyLossAccurate) - .GetExampleTotalAlloyLossDifference(out var foundGetExampleTotalAlloyLossDifference) - .GetExampleTotalAlloyLossAccurateDifference(out var foundExampleTotalAlloyLossAccurateDifference); - - TestReport.CheckPassed(expectedExampleTotalAlloyLoss.Equals(foundTotalAlloyLoss), - TestMessage.CreateFailedMessage($"expectedExampleTotalAlloyLoss of {expectedExampleTotalAlloyLoss} " + - "does not equal " + - $"foundTotalAlloyLoss of {foundTotalAlloyLoss} ")); - - TestReport.CheckPassed(expectedExampleWorkerCost.Equals(foundExampleWorkerCost), - TestMessage.CreateFailedMessage($"expectedExampleWorkerCost of {expectedExampleWorkerCost} " + - "does not equal " + - $"foundExampleWorkerCost of {foundExampleWorkerCost} ")); - - - TestReport.CheckPassed(expectedExampleMiningTimeCost.Equals(foundExampleMiningTimeCost), - TestMessage.CreateFailedMessage($"expectedExampleMiningTimeCost of {expectedExampleMiningTimeCost} " + - "does not equal " + - $"foundExampleMiningTimeCost of {foundExampleMiningTimeCost} ")); - - - TestReport.CheckPassed(expectedExampleTotalAlloyLossAccurate.Equals(foundExampleTotalAlloyLossAccurate), - TestMessage.CreateFailedMessage( - $"expectedExampleTotalAlloyLossAccurate of {expectedExampleTotalAlloyLossAccurate} " + - "does not equal " + - $"foundExampleTotalAlloyLossAccurate of {foundExampleTotalAlloyLossAccurate} ")); - - - TestReport.CheckPassed(expectedExampleTotalAlloyLossDifference.Equals(foundGetExampleTotalAlloyLossDifference), - TestMessage.CreateFailedMessage( - $"expectedExampleTotalAlloyLossDifference of {expectedExampleTotalAlloyLossDifference} " + - "does not equal " + - $"foundGetExampleTotalAlloyLossDifference of {foundGetExampleTotalAlloyLossDifference} ")); - - - TestReport.CheckPassed( - expectedExampleTotalAlloyLossAccurateDifference.Equals(foundExampleTotalAlloyLossAccurateDifference), - TestMessage.CreateFailedMessage( - $"expectedExampleTotalAlloyLossAccurateDifference of {expectedExampleTotalAlloyLossAccurateDifference} " + - "does not equal " + - $"foundExampleTotalAlloyLossAccurateDifference of {foundExampleTotalAlloyLossAccurateDifference} ")); - } -} \ No newline at end of file diff --git a/TestAutomation/TestLinks.cs b/TestAutomation/TestLinks.cs deleted file mode 100644 index 903b984..0000000 --- a/TestAutomation/TestLinks.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace TestAutomation; - -[TestFixture] -public class TestLinks : BaseTest -{ - [SetUp] - public void SetUp() - { - TestReport.CreateTest(); - } - - [TearDown] - public void TearDown() - { - TestReport.ThrowErrors(); - } - - [Test] - public void VerifyPageLinks() - { - Website.HarassCalculatorPage.Goto(); - TestReport.VerifyLinks(Website.HarassCalculatorPage).Wait(); - - Website.DatabasePage.Goto(); - TestReport.VerifyLinks(Website.DatabasePage).Wait(); - - Website.DatabaseSinglePage.Goto("throne"); - TestReport.VerifyLinks(Website.DatabaseSinglePage).Wait(); - } -} \ No newline at end of file diff --git a/TestAutomation/TestSearchFeatures.cs b/TestAutomation/TestSearchFeatures.cs deleted file mode 100644 index ba7d901..0000000 --- a/TestAutomation/TestSearchFeatures.cs +++ /dev/null @@ -1,84 +0,0 @@ -using TestAutomation.Utils; - -namespace TestAutomation; - -[TestFixture] -public class TestSearchFeatures : BaseTest -{ - [SetUp] - public void SetUp() - { - TestReport.CreateTest(); - } - - [TearDown] - public void TearDown() - { - TestReport.ThrowErrors(); - } - - [Test] - public void DesktopOpenCloseSearchDialog() - { - Website - .Goto() - .NavigationBar - .ClickSearchButton() - .CloseDialog() - .ClickHomeLink(); - } - - [Test] - public void DesktopSearchForThrone() - { - Website - .Goto() - .NavigationBar.ClickSearchButton() - .Search("Throne") - .SelectSearchEntity("Throne") - .GetEntityName(out var name) - .GetEntityHealth(out var health); - - TestReport.CheckPassed(name.Equals("Throne"), - new TestMessage { Description = "Couldn't find Throne via search." }); - TestReport.CheckPassed(!health.Trim().Equals(""), - new TestMessage { Description = "Throne has no visible health!" }); - } - - [Test] - public void DesktopFilterForThrone() - { - Website.DatabasePage - .Goto() - .FilterName("Throne") - .GetEntityName(0, out var name); - - TestReport.CheckPassed(name.Equals("Throne"), - new TestMessage { Description = "Couldn't find Throne via filter." }); - } - - [Test] - public void SeeThroneByDefault() - { - Website.DatabasePage - .Goto() - .GetEntityName("army", "throne", out var name); - - TestReport.CheckPassed(name.Equals("Throne"), - new TestMessage { Description = "Couldn't find Throne on the page by default." }); - } - - [Test] - public void DirectLinkNotThroneFailure() - { - Website.DatabaseSinglePage - .Goto("not throne") - .GetInvalidSearch(out var invalidSearch) - .GetValidSearch(out var validSearch); - - TestReport.CheckPassed(invalidSearch.Equals("not throne"), - new TestMessage { Description = "Couldn't find invalid search text on the page." }); - TestReport.CheckPassed(validSearch.Equals("Throne"), - new TestMessage { Description = "Couldn't find valid search text on the page." }); - } -} \ No newline at end of file diff --git a/TestAutomation/Utils/Test.cs b/TestAutomation/Utils/Test.cs deleted file mode 100644 index edfa672..0000000 --- a/TestAutomation/Utils/Test.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace TestAutomation.Utils; - -public class Test -{ - public string Name { get; set; } = "Name..."; - public bool Result { get; set; } = true; - public IList Messages { get; set; } = new List(); -} \ No newline at end of file diff --git a/TestAutomation/Utils/TestMessage.cs b/TestAutomation/Utils/TestMessage.cs deleted file mode 100644 index 4e89fef..0000000 --- a/TestAutomation/Utils/TestMessage.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace TestAutomation.Utils; - -public class TestMessage -{ - public string Title { get; set; } = "Name..."; - public string Description { get; set; } = ""; - public string Color { get; set; } = "FFFFFF"; - - public static TestMessage CreateFailedMessage(string description) - { - return new TestMessage { Title = "Check Failed", Description = description, Color = "FF0000" }; - } -} \ No newline at end of file diff --git a/TestAutomation/Utils/TestReport.cs b/TestAutomation/Utils/TestReport.cs deleted file mode 100644 index d9f9f58..0000000 --- a/TestAutomation/Utils/TestReport.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System.Globalization; -using System.Runtime.CompilerServices; - -namespace TestAutomation.Utils; - -public class TestReport -{ - private List Tests { get; } = new(); - - [MethodImpl(MethodImplOptions.NoInlining)] - public Test CreateTest() - { - Tests.Add(new Test - { - Name = TestContext.CurrentContext.Test.Name - }); - return Tests.Last(); - } - - public void ThrowErrors() - { - if (!Tests.Last().Result) - { - var messages = string.Join("\n", Tests.Last().Messages.Select(x => x.Description).ToList()); - - throw new Exception( - $"{Tests.Last().Name} test failed with {Tests.Last().Messages.Count} messages.\n\n{messages}"); - } - } - - public async Task VerifyLinks(BasePage page) - { - foreach (var link in page.GetLinks()) - try - { - if (link.StartsWith("mailto")) continue; - - using var client = new HttpClient(); - var response = await client.GetAsync(link); - - if (!response.IsSuccessStatusCode) - { - CheckPassed(false, - new TestMessage - { - Color = "red", Title = "Bad Link", - Description = $"{link} failed on page {page.Url} with status code {response.StatusCode}" - }); - Console.WriteLine(response.StatusCode.ToString()); - } - } - catch (Exception e) - { - CheckPassed(false, - new TestMessage - { - Color = "red", Title = "Bad Link", - Description = $"{link} failed on page {page.Url} with stacktrace {e.StackTrace}" - }); - } - } - - - public void CheckPassed(bool passed, TestMessage message) - { - if (passed) return; - Tests.Last().Result = false; - Tests.Last().Messages.Add(message); - } - - public bool DidTestsPass() - { - foreach (var test in Tests) - { - if (test.Result) continue; - - return false; - } - - - return true; - } - - public List GetMessages() - { - if (DidTestsPass()) - return new List - { - new - { - title = "Passed", - color = int.Parse("00FF00", NumberStyles.HexNumber), - description = $"All {Tests.Count} tests passed." - } - }; - - var messageList = new List(); - foreach (var test in Tests) - foreach (var message in test.Messages) - messageList.Add( - new - { - title = message.Title, - color = int.Parse(message.Color, NumberStyles.HexNumber), - description = message.Description - }); - - - return messageList; - } -} \ No newline at end of file diff --git a/TestAutomation/Utils/Usings.cs b/TestAutomation/Utils/Usings.cs deleted file mode 100644 index e71a5ca..0000000 --- a/TestAutomation/Utils/Usings.cs +++ /dev/null @@ -1,7 +0,0 @@ -global using NUnit.Framework; -global using OpenQA.Selenium; -global using OpenQA.Selenium.Firefox; -global using OpenQA.Selenium.Chrome; -global using TestAutomation.Pages; -global using OpenQA.Selenium.Support.UI; -global using OpenQA.Selenium.Support; \ No newline at end of file diff --git a/TestAutomation/Utils/Website.cs b/TestAutomation/Utils/Website.cs deleted file mode 100644 index 5972397..0000000 --- a/TestAutomation/Utils/Website.cs +++ /dev/null @@ -1,216 +0,0 @@ -using System.Collections.ObjectModel; -using OpenQA.Selenium.Interactions; -using TestAutomation.Enums; -using TestAutomation.Shared; - -namespace TestAutomation.Utils; - -public class Website -{ - public static readonly DeploymentType DeploymentType = - Environment.GetEnvironmentVariable("TEST_HOOK")!.Contains("localhost") - ? DeploymentType.Local - : DeploymentType.Dev; - - public static readonly string Url = - DeploymentType.Equals(DeploymentType.Dev) - ? "https://calm-mud-04916b210.1.azurestaticapps.net" - : "https://localhost:7234"; - - public readonly ScreenType ScreenType = ScreenType.Desktop; - - public Website(IWebDriver webDriver, TestReport testReport) - { - WebDriver = webDriver; - TestReport = testReport; - - // Pages - HarassCalculatorPage = new HarassCalculatorPage(this); - DatabasePage = new DatabasePage(this); - DatabaseSinglePage = new DatabaseSinglePage(this); - - // Navigation - NavigationBar = new NavigationBar(this); - - // Dialogs - WebsiteSearchDialog = new WebsiteSearchDialog(this); - } - - public TestReport TestReport { get; set; } - - public IWebDriver WebDriver { get; } - - public HarassCalculatorPage HarassCalculatorPage { get; } - public DatabaseSinglePage DatabaseSinglePage { get; } - public DatabasePage DatabasePage { get; } - public NavigationBar NavigationBar { get; } - public WebsiteSearchDialog WebsiteSearchDialog { get; } - - public IWebElement FindScreenSpecific(string byId) - { - var screenSpecificId = $"{ScreenType.ToString().ToLower()}-{byId}"; - - try - { - return WebDriver.FindElement(By.Id(screenSpecificId)); - } - catch (Exception e) - { - throw new Exception($"Couldn't find {screenSpecificId}. Element does not exist on current page. " + - "\n\nPerhaps an Id is missing."); - } - } - - - public IWebElement Find(string byId, string withParentId) - { - IWebElement parent; - - try - { - parent = WebDriver.FindElement(By.Id(withParentId)); - } - catch (Exception e) - { - throw new Exception($"Couldn't find parent {withParentId}. Element does not exist on current page. " + - "\n\nPerhaps an Id is missing."); - } - - try - { - return parent.FindElement(By.Id(byId)); - } - catch (Exception e) - { - throw new Exception($"Couldn't find {byId}. Element does not exist on current page. " + - "\n\nPerhaps an Id is missing."); - } - } - - public IWebElement Find(string byId) - { - try - { - return WebDriver.FindElement(By.Id(byId)); - } - catch (Exception e) - { - throw new Exception($"Couldn't find {byId}. Element does not exist on current page. " + - "\n\nPerhaps an Id is missing."); - } - } - - public ReadOnlyCollection FindAll(string byId) - { - try - { - return WebDriver.FindElements(By.Id(byId)); - } - catch (Exception e) - { - throw new Exception($"Couldn't find {byId}. Element does not exist on current page. " + - "\n\nPerhaps an Id is missing."); - } - } - - public ReadOnlyCollection FindAllWithTag(string tag) - { - return WebDriver.FindElements(By.TagName(tag)); - } - - public ReadOnlyCollection FindAllWithTag(IWebElement parent, string tag) - { - return parent.FindElements(By.TagName(tag)); - } - - - public IWebElement FindButtonWithLabel(string label) - { - try - { - return WebDriver.FindElement(By.XPath($"//button[@label='{label}']")); - } - catch (Exception e) - { - throw new Exception($"Couldn't find with label: {label}. Element does not exist on current page. "); - } - } - - //@FindBy(xpath = "//div[@label='First Name']") - - public IList FindChildren(string ofId, string tagname) - { - return WebDriver.FindElements(By.CssSelector($"#{ofId} {tagname}")); - } - - public string FindText(string byId) - { - return WebDriver.FindElement(By.Id(byId)).Text; - } - - - public int FindInt(string byId) - { - return int.Parse(WebDriver.FindElement(By.Id(byId)).Text); - } - - - public void ClickTopLeft() - { - new Actions(WebDriver) - .MoveByOffset(32, 32) - .Click() - .Perform(); - } - - public IWebElement Click(IWebElement element) - { - try - { - element.Click(); - } - catch - { - throw new Exception($"Couldn't click on {element.GetDomProperty("id")}. "); - } - - return element; - } - - - public IWebElement EnterInput(IWebElement element, T input) - { - element.Clear(); - element.SendKeys(input!.ToString()); - element.SendKeys(Keys.Enter); - return element; - } - - - public IWebElement EnterInput(string byId, T input) - { - var element = Find(byId); - element.Clear(); - element.SendKeys(input!.ToString()); - element.SendKeys(Keys.Enter); - return element; - } - - public string GetLabel(string byId) - { - return Find(byId).Text; - } - - public Website Goto() - { - WebDriver.Navigate().GoToUrl($"{Url}"); - return this; - } - - public void Goto(string path) - { - var url = $"{Url}/{path}"; - - WebDriver.Navigate().GoToUrl($"{url}"); - } -} \ No newline at end of file diff --git a/TestAutomation/_Tests.cs b/TestAutomation/_Tests.cs deleted file mode 100644 index d0e460a..0000000 --- a/TestAutomation/_Tests.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text; -using Newtonsoft.Json; - -namespace TestAutomation; - -[SetUpFixture] -public class Tests : BaseTest -{ - [OneTimeSetUp] - public void Setup() - { - Website.Goto(); - Website.WebDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15); - } - - [OneTimeTearDown] - public void TearDown() - { - Website.WebDriver.Quit(); - - var message = new - { - content = "Test Report " + DateTime.Now.ToString("dd/MM/yyyy"), - embeds = TestReport.GetMessages() - }; - - var content = new StringContent(JsonConvert.SerializeObject(message), Encoding.UTF8, "application/json"); - - if (Environment.GetEnvironmentVariable("TEST_HOOK") == null) return; - - HttpClient.PostAsync(Environment.GetEnvironmentVariable("TEST_HOOK"), content).Wait(); - } -} \ No newline at end of file