test(SearchTest) Added a test for opening and closing search dialog
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using TestAutomation.Utils;
|
||||
|
||||
namespace TestAutomation;
|
||||
|
||||
public enum DeploymentType
|
||||
{
|
||||
Dev,
|
||||
Local
|
||||
}
|
||||
|
||||
public class BaseTest
|
||||
{
|
||||
protected static readonly DeploymentType DeploymentType =
|
||||
Environment.GetEnvironmentVariable("TEST_HOOK") != null
|
||||
? DeploymentType.Dev
|
||||
: DeploymentType.Local;
|
||||
|
||||
protected static readonly string WebsiteUrl =
|
||||
DeploymentType.Equals(DeploymentType.Dev)
|
||||
? "https://calm-mud-04916b210.1.azurestaticapps.net/"
|
||||
: "https://localhost:7234";
|
||||
|
||||
protected static readonly TestReport TestReport = new();
|
||||
|
||||
|
||||
protected static Website WebsiteInstance = default!;
|
||||
|
||||
protected static Website Website
|
||||
{
|
||||
get
|
||||
{
|
||||
if (WebsiteInstance == null)
|
||||
{
|
||||
var options = new FirefoxOptions();
|
||||
|
||||
options.AcceptInsecureCertificates = true;
|
||||
// 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);
|
||||
}
|
||||
|
||||
return WebsiteInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace TestAutomation.Enums;
|
||||
|
||||
public enum ScreenType
|
||||
{
|
||||
Desktop,
|
||||
Tablet,
|
||||
Mobile
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using TestAutomation.Utils;
|
||||
|
||||
namespace TestAutomation.Pages;
|
||||
|
||||
public class BasePage {
|
||||
public Website website;
|
||||
|
||||
public BasePage(Website website) {
|
||||
this.website = website;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using TestAutomation.Shared;
|
||||
using TestAutomation.Utils;
|
||||
|
||||
namespace TestAutomation.Pages;
|
||||
|
||||
public class DatabaseSinglePage : BaseElement
|
||||
{
|
||||
public DatabaseSinglePage(Website website) : base(website) { }
|
||||
|
||||
|
||||
}
|
||||
@@ -1,71 +1,86 @@
|
||||
using TestAutomation.Utils;
|
||||
using TestAutomation.Shared;
|
||||
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<IWebElement> 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");
|
||||
public class HarassCalculatorPage : BaseElement
|
||||
{
|
||||
public HarassCalculatorPage(Website website) : base(website)
|
||||
{
|
||||
}
|
||||
|
||||
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");
|
||||
private IWebElement NumberOfWorkersLostToHarass => Website.Find("numberOfWorkersLostToHarass");
|
||||
private IWebElement NumberOfTownHallsExisting => Website.Find("numberOfTownHallsExisting");
|
||||
private IList<IWebElement> 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");
|
||||
|
||||
public HarassCalculatorPage SetWorkersLostToHarass(int number) {
|
||||
website.EnterInput(NumberOfWorkersLostToHarass, number);
|
||||
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 HarassCalculatorPage SetWorkersLostToHarass(int number)
|
||||
{
|
||||
Website.EnterInput(NumberOfWorkersLostToHarass, number);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HarassCalculatorPage SetNumberOfTownHallsExisting(int number) {
|
||||
website.EnterInput(NumberOfTownHallsExisting, number);
|
||||
public HarassCalculatorPage SetNumberOfTownHallsExisting(int number)
|
||||
{
|
||||
Website.EnterInput(NumberOfTownHallsExisting, number);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HarassCalculatorPage SetTownHallTravelTime(int forTownHall, int number) {
|
||||
website.EnterInput(OnTownHallTravelTimes[forTownHall], number);
|
||||
public HarassCalculatorPage SetTownHallTravelTime(int forTownHall, int number)
|
||||
{
|
||||
Website.EnterInput(OnTownHallTravelTimes[forTownHall], number);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HarassCalculatorPage GetTotalAlloyHarassment(out int result) {
|
||||
public HarassCalculatorPage GetTotalAlloyHarassment(out int result)
|
||||
{
|
||||
result = TotalAlloyHarassment;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public HarassCalculatorPage GetExampleTotalAlloyLoss(out int result) {
|
||||
public HarassCalculatorPage GetExampleTotalAlloyLoss(out int result)
|
||||
{
|
||||
result = ExampleTotalAlloyLoss;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HarassCalculatorPage GetExampleWorkerCost(out int result) {
|
||||
public HarassCalculatorPage GetExampleWorkerCost(out int result)
|
||||
{
|
||||
result = ExampleWorkerCost;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HarassCalculatorPage GetExampleMiningTimeCost(out int result) {
|
||||
public HarassCalculatorPage GetExampleMiningTimeCost(out int result)
|
||||
{
|
||||
result = ExampleMiningTimeCost;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HarassCalculatorPage GetExampleTotalAlloyLossAccurate(out int result) {
|
||||
public HarassCalculatorPage GetExampleTotalAlloyLossAccurate(out int result)
|
||||
{
|
||||
result = ExampleTotalAlloyLossAccurate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HarassCalculatorPage GetExampleTotalAlloyLossDifference(out int result) {
|
||||
public HarassCalculatorPage GetExampleTotalAlloyLossDifference(out int result)
|
||||
{
|
||||
result = ExampleTotalAlloyLossDifference;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HarassCalculatorPage GetExampleTotalAlloyLossAccurateDifference(out int result) {
|
||||
public HarassCalculatorPage GetExampleTotalAlloyLossAccurateDifference(out int result)
|
||||
{
|
||||
result = ExampleTotalAlloyLossAccurateDifference;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using TestAutomation.Utils;
|
||||
|
||||
namespace TestAutomation.Shared;
|
||||
|
||||
public class BaseElement
|
||||
{
|
||||
protected readonly Website Website;
|
||||
|
||||
protected BaseElement(Website website)
|
||||
{
|
||||
Website = website;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using TestAutomation.Enums;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Discord.Rest;
|
||||
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 void SelectSearchEntity(string throne)
|
||||
{
|
||||
Website.Click(Website.FindButtonWithLabel(throne));
|
||||
//TODO Add DatabaseSinglePage
|
||||
//return Website.DatabaseSinglePage;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Pages\" />
|
||||
<Folder Include="Pages\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,89 +1,45 @@
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using TestAutomation.Utils;
|
||||
|
||||
namespace TestAutomation;
|
||||
|
||||
public class Tests {
|
||||
private readonly IWebDriver _webDriver = default!;
|
||||
private readonly string develop = "https://calm-mud-04916b210.1.azurestaticapps.net/";
|
||||
|
||||
private readonly HttpClient httpClient = new();
|
||||
|
||||
|
||||
private readonly string localhost = "https://localhost:7234";
|
||||
|
||||
private readonly TestReport testReport = new();
|
||||
|
||||
public Tests() {
|
||||
var options = new FirefoxOptions();
|
||||
|
||||
options.AcceptInsecureCertificates = true;
|
||||
options.AddArgument("--headless");
|
||||
options.AddArgument("--ignore-certificate-errors");
|
||||
options.AddArgument("--start-maximized");
|
||||
options.AddArgument("--test-type");
|
||||
options.AddArgument("--allow-running-insecure-content");
|
||||
|
||||
_webDriver = new FirefoxDriver(Environment.CurrentDirectory, options);
|
||||
|
||||
Website = new Website(_webDriver);
|
||||
}
|
||||
|
||||
private Website Website { get; }
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void Setup() {
|
||||
_webDriver.Navigate().GoToUrl(develop);
|
||||
_webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void TearDown() {
|
||||
_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");
|
||||
|
||||
httpClient.PostAsync(Environment.GetEnvironmentVariable("TEST_HOOK"), content).Wait();
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class TestHarassCalculator : BaseTest
|
||||
{
|
||||
[Test]
|
||||
public void HarassCalculator() {
|
||||
testReport.CreateTest();
|
||||
public void CalculatorInput()
|
||||
{
|
||||
TestReport.CreateTest();
|
||||
|
||||
_webDriver.Navigate().GoToUrl(develop + "/harass-calculator");
|
||||
Website.WebDriver.Navigate().GoToUrl(WebsiteUrl + "/harass-calculator");
|
||||
|
||||
var expectedTotalAlloyHarassment = 240;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
Website.HarassCalculatorPage
|
||||
.SetWorkersLostToHarass(3)
|
||||
.SetNumberOfTownHallsExisting(2)
|
||||
.SetTownHallTravelTime(0, 30)
|
||||
.GetTotalAlloyHarassment(out var foundTotalAlloyHarassment);
|
||||
|
||||
testReport.CheckPassed(expectedTotalAlloyHarassment.Equals(foundTotalAlloyHarassment),
|
||||
TestReport.CheckPassed(expectedTotalAlloyHarassment.Equals(foundTotalAlloyHarassment),
|
||||
TestMessage.CreateFailedMessage($"expectTotalAlloyHarassment of {expectedTotalAlloyHarassment} " +
|
||||
"does not equal " +
|
||||
$"foundTotalAlloyHarassment of {foundTotalAlloyHarassment} "));
|
||||
}
|
||||
catch (Exception e) {
|
||||
testReport.CheckPassed(false,
|
||||
catch (Exception e)
|
||||
{
|
||||
TestReport.CheckPassed(false,
|
||||
TestMessage.CreateFailedMessage(e.StackTrace!));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HarassCalculatorInformation() {
|
||||
testReport.CreateTest();
|
||||
public void CalculatedExampleInformation()
|
||||
{
|
||||
TestReport.CreateTest();
|
||||
|
||||
_webDriver.Navigate().GoToUrl(develop + "/harass-calculator");
|
||||
Website.WebDriver.Navigate().GoToUrl(WebsiteUrl + "/harass-calculator");
|
||||
|
||||
var expectedExampleTotalAlloyLoss = 720;
|
||||
var expectedExampleWorkerCost = 300;
|
||||
@@ -100,38 +56,38 @@ public class Tests {
|
||||
.GetExampleTotalAlloyLossDifference(out var foundGetExampleTotalAlloyLossDifference)
|
||||
.GetExampleTotalAlloyLossAccurateDifference(out var foundExampleTotalAlloyLossAccurateDifference);
|
||||
|
||||
testReport.CheckPassed(expectedExampleTotalAlloyLoss.Equals(foundTotalAlloyLoss),
|
||||
TestReport.CheckPassed(expectedExampleTotalAlloyLoss.Equals(foundTotalAlloyLoss),
|
||||
TestMessage.CreateFailedMessage($"expectedExampleTotalAlloyLoss of {expectedExampleTotalAlloyLoss} " +
|
||||
"does not equal " +
|
||||
$"foundTotalAlloyLoss of {foundTotalAlloyLoss} "));
|
||||
|
||||
testReport.CheckPassed(expectedExampleWorkerCost.Equals(foundExampleWorkerCost),
|
||||
TestReport.CheckPassed(expectedExampleWorkerCost.Equals(foundExampleWorkerCost),
|
||||
TestMessage.CreateFailedMessage($"expectedExampleWorkerCost of {expectedExampleWorkerCost} " +
|
||||
"does not equal " +
|
||||
$"foundExampleWorkerCost of {foundExampleWorkerCost} "));
|
||||
|
||||
|
||||
testReport.CheckPassed(expectedExampleMiningTimeCost.Equals(foundExampleMiningTimeCost),
|
||||
TestReport.CheckPassed(expectedExampleMiningTimeCost.Equals(foundExampleMiningTimeCost),
|
||||
TestMessage.CreateFailedMessage($"expectedExampleMiningTimeCost of {expectedExampleMiningTimeCost} " +
|
||||
"does not equal " +
|
||||
$"foundExampleMiningTimeCost of {foundExampleMiningTimeCost} "));
|
||||
|
||||
|
||||
testReport.CheckPassed(expectedExampleTotalAlloyLossAccurate.Equals(foundExampleTotalAlloyLossAccurate),
|
||||
TestReport.CheckPassed(expectedExampleTotalAlloyLossAccurate.Equals(foundExampleTotalAlloyLossAccurate),
|
||||
TestMessage.CreateFailedMessage(
|
||||
$"expectedExampleTotalAlloyLossAccurate of {expectedExampleTotalAlloyLossAccurate} " +
|
||||
"does not equal " +
|
||||
$"foundExampleTotalAlloyLossAccurate of {foundExampleTotalAlloyLossAccurate} "));
|
||||
|
||||
|
||||
testReport.CheckPassed(expectedExampleTotalAlloyLossDifference.Equals(foundGetExampleTotalAlloyLossDifference),
|
||||
TestReport.CheckPassed(expectedExampleTotalAlloyLossDifference.Equals(foundGetExampleTotalAlloyLossDifference),
|
||||
TestMessage.CreateFailedMessage(
|
||||
$"expectedExampleTotalAlloyLossDifference of {expectedExampleTotalAlloyLossDifference} " +
|
||||
"does not equal " +
|
||||
$"foundGetExampleTotalAlloyLossDifference of {foundGetExampleTotalAlloyLossDifference} "));
|
||||
|
||||
|
||||
testReport.CheckPassed(
|
||||
TestReport.CheckPassed(
|
||||
expectedExampleTotalAlloyLossAccurateDifference.Equals(foundExampleTotalAlloyLossAccurateDifference),
|
||||
TestMessage.CreateFailedMessage(
|
||||
$"expectedExampleTotalAlloyLossAccurateDifference of {expectedExampleTotalAlloyLossAccurateDifference} " +
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace TestAutomation;
|
||||
|
||||
[TestFixture]
|
||||
public class TestSearchFeatures : BaseTest
|
||||
{
|
||||
[Test]
|
||||
public void DesktopOpenCloseSearchDialog()
|
||||
{
|
||||
TestReport.CreateTest();
|
||||
|
||||
Website.WebDriver.Navigate().GoToUrl(WebsiteUrl + "/");
|
||||
|
||||
Website.NavigationBar
|
||||
.ClickSearchButton()
|
||||
.CloseDialog()
|
||||
.ClickHomeLink();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Not completed")]
|
||||
public void DesktopSearchForThrone()
|
||||
{
|
||||
TestReport.CreateTest();
|
||||
|
||||
Website.WebDriver.Navigate().GoToUrl(WebsiteUrl + "/");
|
||||
|
||||
Website.NavigationBar
|
||||
.ClickSearchButton()
|
||||
.Search("Throne")
|
||||
.SelectSearchEntity("Throne");
|
||||
// .GetName(out var name);
|
||||
|
||||
// TestReport.CheckPassed(name.Equals("Throne"), "Couldn't find Throne via search.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace TestAutomation;
|
||||
|
||||
[SetUpFixture]
|
||||
public class Tests : BaseTest
|
||||
{
|
||||
[OneTimeSetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Website.WebDriver.Navigate().GoToUrl(WebsiteUrl);
|
||||
Website.WebDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
HttpClient HttpClient = new();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace TestAutomation.Utils;
|
||||
|
||||
public class Test {
|
||||
public class Test
|
||||
{
|
||||
public string Name { get; set; } = "Name...";
|
||||
public bool Result { get; set; } = true;
|
||||
public IList<TestMessage> Messages { get; set; } = new List<TestMessage>();
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
namespace TestAutomation.Utils;
|
||||
|
||||
public class TestMessage {
|
||||
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) {
|
||||
public static TestMessage CreateFailedMessage(string description)
|
||||
{
|
||||
return new TestMessage { Title = "Check Failed", Description = description, Color = "FF0000" };
|
||||
}
|
||||
}
|
||||
@@ -4,24 +4,31 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace TestAutomation.Utils;
|
||||
|
||||
public class TestReport {
|
||||
public class TestReport
|
||||
{
|
||||
private List<Test> Tests { get; } = new();
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public Test CreateTest() {
|
||||
public Test CreateTest()
|
||||
{
|
||||
var testName = new StackTrace().GetFrame(1)!.GetMethod()!.Name!;
|
||||
Tests.Add(new Test { Name = testName });
|
||||
return Tests.Last();
|
||||
}
|
||||
|
||||
public void CheckPassed(bool passed, TestMessage message) {
|
||||
public void CheckPassed(bool passed, TestMessage message)
|
||||
{
|
||||
if (passed) return;
|
||||
Tests.Last().Result = false;
|
||||
Tests.Last().Messages.Add(message);
|
||||
|
||||
throw new Exception(message.Description);
|
||||
}
|
||||
|
||||
public bool DidTestsPass() {
|
||||
foreach (var test in Tests) {
|
||||
public bool DidTestsPass()
|
||||
{
|
||||
foreach (var test in Tests)
|
||||
{
|
||||
if (test.Result) continue;
|
||||
|
||||
return false;
|
||||
@@ -31,10 +38,13 @@ public class TestReport {
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<object> GetMessages() {
|
||||
public List<object> GetMessages()
|
||||
{
|
||||
if (DidTestsPass())
|
||||
return new List<object> {
|
||||
new {
|
||||
return new List<object>
|
||||
{
|
||||
new
|
||||
{
|
||||
title = "Passed",
|
||||
color = int.Parse("00FF00", NumberStyles.HexNumber),
|
||||
description = $"All {Tests.Count} tests passed."
|
||||
@@ -45,7 +55,8 @@ public class TestReport {
|
||||
foreach (var test in Tests)
|
||||
foreach (var message in test.Messages)
|
||||
messageList.Add(
|
||||
new {
|
||||
new
|
||||
{
|
||||
title = message.Title,
|
||||
color = int.Parse(message.Color, NumberStyles.HexNumber),
|
||||
description = message.Description
|
||||
|
||||
@@ -1,35 +1,113 @@
|
||||
namespace TestAutomation.Utils;
|
||||
using OpenQA.Selenium.Interactions;
|
||||
using TestAutomation.Enums;
|
||||
using TestAutomation.Shared;
|
||||
|
||||
public class Website {
|
||||
public Website(IWebDriver webDriver) {
|
||||
namespace TestAutomation.Utils;
|
||||
|
||||
public class Website
|
||||
{
|
||||
public readonly ScreenType ScreenType = ScreenType.Desktop;
|
||||
|
||||
public Website(IWebDriver webDriver)
|
||||
{
|
||||
WebDriver = webDriver;
|
||||
|
||||
HarassCalculatorPage = new HarassCalculatorPage(this);
|
||||
NavigationBar = new NavigationBar(this);
|
||||
WebsiteSearchDialog = new WebsiteSearchDialog(this);
|
||||
}
|
||||
|
||||
public IWebDriver WebDriver { get; }
|
||||
|
||||
public HarassCalculatorPage HarassCalculatorPage { get; }
|
||||
public NavigationBar NavigationBar { get; }
|
||||
public WebsiteSearchDialog WebsiteSearchDialog { get; }
|
||||
|
||||
public IWebElement Find(string byId) {
|
||||
return WebDriver.FindElement(By.Id(byId));
|
||||
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 IList<IWebElement> FindChildren(string ofId, string tagname) {
|
||||
|
||||
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 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<IWebElement> FindChildren(string ofId, string tagname)
|
||||
{
|
||||
return WebDriver.FindElements(By.CssSelector($"#{ofId} {tagname}"));
|
||||
}
|
||||
|
||||
public string FindText(string byId) {
|
||||
public string FindText(string byId)
|
||||
{
|
||||
return WebDriver.FindElement(By.Id(byId)).Text;
|
||||
}
|
||||
|
||||
|
||||
public int FindInt(string byId) {
|
||||
public int FindInt(string byId)
|
||||
{
|
||||
return int.Parse(WebDriver.FindElement(By.Id(byId)).Text);
|
||||
}
|
||||
|
||||
|
||||
public IWebElement EnterInput<T>(IWebElement element, T input) {
|
||||
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<T>(IWebElement element, T input)
|
||||
{
|
||||
element.Clear();
|
||||
element.SendKeys(input!.ToString());
|
||||
element.SendKeys(Keys.Enter);
|
||||
@@ -37,7 +115,8 @@ public class Website {
|
||||
}
|
||||
|
||||
|
||||
public IWebElement EnterInput<T>(string byId, T input) {
|
||||
public IWebElement EnterInput<T>(string byId, T input)
|
||||
{
|
||||
var element = Find(byId);
|
||||
element.Clear();
|
||||
element.SendKeys(input!.ToString());
|
||||
@@ -45,7 +124,8 @@ public class Website {
|
||||
return element;
|
||||
}
|
||||
|
||||
public string GetLabel(string byId) {
|
||||
public string GetLabel(string byId)
|
||||
{
|
||||
return Find(byId).Text;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user