feat(TestAutomation) Harass Calculator tests and Search box style fix
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using OpenQA.Selenium;
|
||||
|
||||
namespace TestAutomation.Pages;
|
||||
|
||||
public class BasePage {
|
||||
|
||||
public Website website;
|
||||
|
||||
public BasePage(Website website) {
|
||||
this.website = website;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
namespace TestAutomation.Pages;
|
||||
|
||||
public class HarassCalculatorPage : BasePage {
|
||||
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");
|
||||
|
||||
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(Website website) : base(website) { }
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotNetSeleniumExtras.PageObjects" Version="3.11.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.2.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Pages\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,120 @@
|
||||
|
||||
namespace TestAutomation;
|
||||
|
||||
public class Tests
|
||||
{
|
||||
private IWebDriver _webDriver = default!;
|
||||
|
||||
|
||||
private readonly string localhost = "https://localhost:7234";
|
||||
private readonly string develop = "https://calm-mud-04916b210.1.azurestaticapps.net/";
|
||||
|
||||
|
||||
private Website Website { get; }
|
||||
|
||||
public Tests() {
|
||||
//var options = new FirefoxOptions();
|
||||
var options = new ChromeOptions();
|
||||
|
||||
options.AcceptInsecureCertificates = true;
|
||||
|
||||
#if !DEBUG
|
||||
options.AddArgument("--headless");
|
||||
#endif
|
||||
|
||||
options.AddArgument("--start-maximized");
|
||||
|
||||
//_webDriver = new FirefoxDriver(options);
|
||||
_webDriver = new ChromeDriver(options);
|
||||
|
||||
Website = new Website(_webDriver);
|
||||
}
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_webDriver.Navigate().GoToUrl(localhost);
|
||||
_webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
_webDriver.Quit();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HarassCalculator()
|
||||
{
|
||||
_webDriver.Navigate().GoToUrl(localhost + "/harass-calculator");
|
||||
|
||||
int expectedTotalAlloyHarassment = 240;
|
||||
|
||||
Website.HarassCalculatorPage
|
||||
.SetWorkersLostToHarass(3)
|
||||
.SetNumberOfTownHallsExisting(2)
|
||||
.SetTownHallTravelTime(0, 30)
|
||||
.GetTotalAlloyHarassment(out var foundTotalAlloyHarassment);
|
||||
|
||||
Assert.True(expectedTotalAlloyHarassment.Equals(foundTotalAlloyHarassment),
|
||||
$"expectTotalAlloyHarassment of {expectedTotalAlloyHarassment} " +
|
||||
"does not equal " +
|
||||
$"foundTotalAlloyHarassment of {foundTotalAlloyHarassment} ");
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HarassCalculatorInformation()
|
||||
{
|
||||
_webDriver.Navigate().GoToUrl(localhost + "/harass-calculator");
|
||||
|
||||
int expectedExampleTotalAlloyLoss = 720;
|
||||
int expectedExampleWorkerCost = 300;
|
||||
int expectedExampleMiningTimeCost = 420;
|
||||
int expectedExampleTotalAlloyLossDifference = 300;
|
||||
int expectedExampleTotalAlloyLossAccurate = 450;
|
||||
int expectedExampleTotalAlloyLossAccurateDifference = 270;
|
||||
|
||||
Website.HarassCalculatorPage
|
||||
.GetExampleTotalAlloyLoss(out var foundTotalAlloyLoss)
|
||||
.GetExampleWorkerCost(out var foundExampleWorkerCost)
|
||||
.GetExampleMiningTimeCost(out var foundExampleMiningTimeCost)
|
||||
.GetExampleTotalAlloyLossAccurate(out var foundExampleTotalAlloyLossAccurate)
|
||||
.GetExampleTotalAlloyLossDifference(out var foundGetExampleTotalAlloyLossDifference)
|
||||
.GetExampleTotalAlloyLossAccurateDifference(out var foundExampleTotalAlloyLossAccurateDifference);
|
||||
|
||||
Assert.True(expectedExampleTotalAlloyLoss.Equals(foundTotalAlloyLoss),
|
||||
$"expectedExampleTotalAlloyLoss of {expectedExampleTotalAlloyLoss} " +
|
||||
"does not equal " +
|
||||
$"foundTotalAlloyLoss of {foundTotalAlloyLoss} ");
|
||||
|
||||
Assert.True(expectedExampleWorkerCost.Equals(foundExampleWorkerCost),
|
||||
$"expectedExampleWorkerCost of {expectedExampleWorkerCost} " +
|
||||
"does not equal " +
|
||||
$"foundExampleWorkerCost of {foundExampleWorkerCost} ");
|
||||
|
||||
|
||||
Assert.True(expectedExampleMiningTimeCost.Equals(foundExampleMiningTimeCost),
|
||||
$"expectedExampleMiningTimeCost of {expectedExampleMiningTimeCost} " +
|
||||
"does not equal " +
|
||||
$"foundExampleMiningTimeCost of {foundExampleMiningTimeCost} ");
|
||||
|
||||
|
||||
Assert.True(expectedExampleTotalAlloyLossAccurate.Equals(foundExampleTotalAlloyLossAccurate),
|
||||
$"expectedExampleTotalAlloyLossAccurate of {expectedExampleTotalAlloyLossAccurate} " +
|
||||
"does not equal " +
|
||||
$"foundExampleTotalAlloyLossAccurate of {foundExampleTotalAlloyLossAccurate} ");
|
||||
|
||||
|
||||
Assert.True(expectedExampleTotalAlloyLossDifference.Equals(foundGetExampleTotalAlloyLossDifference),
|
||||
$"expectedExampleTotalAlloyLossDifference of {expectedExampleTotalAlloyLossDifference} " +
|
||||
"does not equal " +
|
||||
$"foundGetExampleTotalAlloyLossDifference of {foundGetExampleTotalAlloyLossDifference} ");
|
||||
|
||||
|
||||
Assert.True(expectedExampleTotalAlloyLossAccurateDifference.Equals(foundExampleTotalAlloyLossAccurateDifference),
|
||||
$"expectedExampleTotalAlloyLossAccurateDifference of {expectedExampleTotalAlloyLossAccurateDifference} " +
|
||||
"does not equal " +
|
||||
$"foundExampleTotalAlloyLossAccurateDifference of {foundExampleTotalAlloyLossAccurateDifference} ");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
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;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
namespace TestAutomation;
|
||||
|
||||
public class Website {
|
||||
public IWebDriver WebDriver { get; }
|
||||
|
||||
public HarassCalculatorPage HarassCalculatorPage { get; }
|
||||
|
||||
public Website(IWebDriver webDriver) {
|
||||
WebDriver = webDriver;
|
||||
|
||||
HarassCalculatorPage = new HarassCalculatorPage(this);
|
||||
}
|
||||
|
||||
public IWebElement Find(string byId) {
|
||||
return WebDriver.FindElement(By.Id(byId));
|
||||
}
|
||||
|
||||
public IList<IWebElement> 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 IWebElement EnterInput<T>(IWebElement element, T input) {
|
||||
element.Clear();
|
||||
element.SendKeys(input!.ToString());
|
||||
element.SendKeys(Keys.Enter);
|
||||
return element;
|
||||
}
|
||||
|
||||
|
||||
public IWebElement EnterInput<T>(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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user