Browse Source

feat(TestAutomation) Harass Calculator tests and Search box style fix

main
Jonathan McCaffrey 4 years ago
parent
commit
7c10149ff3
  1. 4
      Components/Form/FormNumberComponent.razor
  2. BIN
      IGP/Database.db
  3. 7
      IGP/Dialog/SearchDialogComponent.razor
  4. 6
      IGP/IGP.sln
  5. 214
      IGP/Pages/HarassCalculatorPage.razor
  6. 23
      IGP/Portals/SearchPortal.razor
  7. 2
      IGP/wwwroot/generated/AgileTaskModels.json
  8. 4
      Model/TravelTime.cs
  9. 13
      TestAutomation/Pages/BasePage.cs
  10. 70
      TestAutomation/Pages/HarassCalculatorPage.cs
  11. 24
      TestAutomation/TestAutomation.csproj
  12. 120
      TestAutomation/UnitTest1.cs
  13. 9
      TestAutomation/Usings.cs
  14. 51
      TestAutomation/Website.cs

4
Components/Form/FormNumberComponent.razor

@ -5,6 +5,7 @@
}
<div>
<input readonly="@ReadOnly"
id="@Id"
class="numberInput"
type="number"
min="@Min"
@ -40,6 +41,9 @@
[Parameter]
public RenderFragment? FormLabelComponent { get; set; }
[Parameter]
public string Id { get; set; } = default!;
[Parameter]
public RenderFragment? FormInfoComponent { get; set; }

BIN
IGP/Database.db

Binary file not shown.

7
IGP/Dialog/SearchDialogComponent.razor

@ -50,7 +50,7 @@
filter: blur(2px);
}
.confirmDialogBackground {
.searchBackground {
position: fixed;
top: 0;
left: 0;
@ -84,7 +84,7 @@
}
.confirmDialogContainer {
.searchContainer {
margin-left: auto;
margin-right: auto;
margin-top: 64px;
@ -120,7 +120,6 @@
protected override void OnInitialized()
{
base.OnInitialized();
searchService.Subscribe(OnSearchChanged);
timer = new Timer(200);
@ -145,7 +144,7 @@
StateHasChanged();
}
void IDisposable.Dispose()
public void Dispose()
{
searchService.Unsubscribe(OnSearchChanged);
timer.Elapsed -= FocusTimer;

6
IGP/IGP.sln

@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "..\Services\Ser
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IGP_Convert", "..\IGP_Convert\IGP_Convert.csproj", "{82F1848E-4BF6-4B16-A9DD-574AF566712B}"
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
@ -45,6 +47,10 @@ Global
{82F1848E-4BF6-4B16-A9DD-574AF566712B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{82F1848E-4BF6-4B16-A9DD-574AF566712B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82F1848E-4BF6-4B16-A9DD-574AF566712B}.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

214
IGP/Pages/HarassCalculatorPage.razor

@ -1,10 +1,10 @@
@layout PageLayout
@inject IDataCollectionService DataCollectionService
@using Model
@inherits BasePage
@page "/harass-calculator"
@using Model
<LayoutMediumContentComponent>
<WebsiteTitleComponent>Harass Calculator</WebsiteTitleComponent>
@ -12,21 +12,21 @@
<PaperComponent>
Credit to Zard for deriving the formula.
</PaperComponent>
<PaperComponent>
<LayoutRowComponent>
<LayoutColumnComponent>
<FormLayoutComponent>
<FormDisplayComponent Label="Cost of worker">
<Display>@costOfWorker</Display>
<Display>@CostOfWorker</Display>
</FormDisplayComponent>
<FormDisplayComponent Label="Alloy mined per second by worker">
<Display>@alloyMinedPerSecondByWorker</Display>
<Display>@AlloyMinedPerSecondByWorker</Display>
</FormDisplayComponent>
<FormDisplayComponent Label="Time to produce worker">
<Display>@timeToProduceWorker</Display>
<Display>@TimeToProduceWorker</Display>
</FormDisplayComponent>
</FormLayoutComponent>
</LayoutColumnComponent>
@ -34,40 +34,45 @@
<LayoutColumnComponent>
<FormLayoutComponent>
<FormNumberComponent Min="1"
Value="@((int)numberOfWorkersLostToHarass)"
OnChange="@(e => { numberOfWorkersLostToHarass = int.Parse(e.Value!.ToString()!); Calculate();})">
Id="numberOfWorkersLostToHarass"
Value="@((int)NumberOfWorkersLostToHarass)"
OnChange="@(e => { NumberOfWorkersLostToHarass = int.Parse(e.Value!.ToString()!); Calculate();})">
<FormLabelComponent>Number of workers lost to harass</FormLabelComponent>
</FormNumberComponent>
<FormNumberComponent Min="1"
Value="@((int)numberOfTownHallsExisting)"
Id="numberOfTownHallsExisting"
Value="@((int)NumberOfTownHallsExisting)"
OnChange="OnTownHallsChanged">
<FormLabelComponent>Number of townhalls you have</FormLabelComponent>
</FormNumberComponent>
<div id="numberOfTownHallTravelTimes">
@{
var index = 0;
}
@foreach (var travelTime in TravelTimes)
{
@foreach (var travelTime in TravelTimes) {
index++;
if (index == 1)
{
if (index == 1) {
continue;
}
var id = $"numberOfTownHallsExisting_{index}";
<FormNumberComponent Min="0"
Value="@(travelTime.Value)"
Id="@id"
Value="@((int)travelTime.Value)"
OnChange="e => { OnTownHallTravelTimeChanged(e, travelTime); }">
<FormLabelComponent>Worker travel time from other base @(travelTime.Index + 1)</FormLabelComponent>
</FormNumberComponent>
}
</div>
<FormDisplayComponent Label="Total alloy lost">
<Display>
<div style="font-size: 1.5rem; font-weight: 800;">
@totalAlloyHarassment
<span id="totalAlloyHarassment">
@TotalAlloyHarassment
</span>
</div>
</Display>
</FormDisplayComponent>
@ -77,19 +82,16 @@
<br/>
<div>
(<b>Worker replacement costs:</b> @WorkerReplacementCost())
(<b>Worker replacement costs:</b> <span id="workerReplacementCost">@WorkerReplacementCost()</span>)
</div>
<div>
(<b>Delayed mining time:</b> @DelayedMiningCost())
(<b>Delayed mining time:</b> <span id="delayedMiningCost">@DelayedMiningCost()</span>)
</div>
<div>
(<b>Average travel time:</b> @GetAverageTravelTime())
(<b>Average travel time:</b> <span id="getAverageTravelTime">@GetAverageTravelTime()</span>)
</div>
</LayoutColumnComponent>
</LayoutRowComponent>
</PaperComponent>
@ -101,7 +103,10 @@
What is this tool?
</InfoQuestionComponent>
<InfoAnswerComponent>
The Harass Calculator allows you to calculate damage done to an enemy alloy line. For example, if you were to attack with Ichors, and kill 6 enemy workers, you can set the <b>Number of workers lost to harass</b> to 6. This would determine a loss of 741 alloy. Quite the large number.
The Harass Calculator allows you to calculate damage done to an enemy alloy line. For example, if you
were to attack with Ichors, and kill 6 enemy workers, you can set the <b>Number of workers lost to
harass</b> to 6. This would determine a loss of <span id="exampleTotalAlloyLoss">@ExampleTotalAlloyLoss</span> alloy. Quite
the large number.
</InfoAnswerComponent>
</InfoBodyComponent>
@ -110,12 +115,21 @@
What can I learn from this?
</InfoQuestionComponent>
<InfoAnswerComponent>
Well, let's assume you lost a full alloy line of workers, and have to take that 741 alloy cost (300 to rebuy the workers, and 441 in lost mining time.)
Well, let's assume you lost a full alloy line of workers, and have to take that
@ExampleTotalAlloyLoss alloy cost (<span id="exampleWorkerCost">@ExampleWorkerCost</span>
to rebuy the workers, and <span id="exampleMiningTimeCost">@ExampleMiningTimeCost</span> in lost mining
time.)
<br/><br/>
If you were to set the <b>Number of townhalls you have</b> to 2, the calculator will consider worker transfer micro. Allowing you to cut the total cost by roughly 315 alloy. However, that number isn't entirely accurate, you are also going to have to bump up the <b>Worker travel time to alloy</b> to account for the time it takes the transferred workers to arrive at the decimated alloy line.
If you were to set the <b>Number of townhalls you have</b> to 2, the calculator will consider worker
transfer micro. Allowing you to cut the total cost by roughly
<span id="exampleTotalAlloyLossDifference">@ExampleTotalAlloyLossDifference</span> alloy. However, that number isn't
entirely accurate, you are also going to have to bump up the <b>Worker travel time to alloy</b> to account for the time it takes the transferred workers to arrive at the decimated alloy line.
<br/><br/>
Let's say it takes 10 seconds for workers to transfer from your second base. We can divide that number by 2, to represent our bases, and add those 5 additional seconds to <b>Worker travel time to alloy</b>, for the more accurate loss of 456 alloy (saving you 285 alloy.) <i>Which is much better than not transferring workers!</i>
Let's say it takes 10 seconds for workers to transfer from your second base. Let's enter that for the
second base travel time for the more accurate loss of <span
id="exampleTotalAlloyLossAccurate">@ExampleTotalAlloyLossAccurate</span> alloy
(saving you <span id="exampleTotalAlloyLossAccurateDifference">@ExampleTotalAlloyLossAccurateDifference</span> alloy.) <i>Which is
much better than not transferring workers!</i>
</InfoAnswerComponent>
</InfoBodyComponent>
@ -194,101 +208,137 @@
</style>
@code {
float totalAlloyHarassment = 0;
readonly float costOfWorker = 50;
readonly float alloyMinedPerSecondByWorker = 1;
readonly float timeToProduceWorker = 20;
float numberOfWorkersLostToHarass = 1;
float numberOfTownHallsExisting = 1;
float GetAverageTravelTime()
{
if (TravelTimes.Count == 0)
{
// Example calcs
float ExampleTotalAlloyLoss => Calculate(
WorkerReplacementCost(6),
SimultaneousProductionFloor(1,6),
6,
new List<float> { 0 });
float ExampleWorkerCost => WorkerReplacementCost(6);
float ExampleMiningTimeCost => ExampleTotalAlloyLoss - ExampleWorkerCost;
float ExampleTotalAlloyLossDifference => ExampleTotalAlloyLoss - Calculate(
WorkerReplacementCost(6),
SimultaneousProductionFloor(2,6),
6,
new List<float> { 0, 0 });
float ExampleTotalAlloyLossAccurate => Calculate(
WorkerReplacementCost(6),
SimultaneousProductionFloor(2,6),
6,
new List<float> { 0, 10 });
float ExampleTotalAlloyLossAccurateDifference => ExampleTotalAlloyLoss - ExampleTotalAlloyLossAccurate;
float TotalAlloyHarassment = 0;
readonly float CostOfWorker = 50;
readonly float AlloyMinedPerSecondByWorker = 1;
readonly float TimeToProduceWorker = 20;
float NumberOfWorkersLostToHarass = 1;
float NumberOfTownHallsExisting = 1;
float GetAverageTravelTime() {
if (TravelTimes.Count == 0) {
return 0;
}
var sum = 0;
float sum = 0;
foreach (var travelTime in TravelTimes)
{
foreach (var travelTime in TravelTimes) {
sum += travelTime.Value;
}
return sum / numberOfTownHallsExisting;
return sum / NumberOfTownHallsExisting;
}
float SimultaneousProductionFloor()
{
if (numberOfTownHallsExisting <= 0 || numberOfWorkersLostToHarass <= 0)
{
float SimultaneousProductionFloor() {
if (NumberOfTownHallsExisting <= 0 || NumberOfWorkersLostToHarass <= 0) {
return 0;
}
return numberOfWorkersLostToHarass / Math.Min(numberOfTownHallsExisting, numberOfWorkersLostToHarass);
return NumberOfWorkersLostToHarass / Math.Min(NumberOfTownHallsExisting, NumberOfWorkersLostToHarass);
}
float SimultaneousProductionFloor(float existingTownHalls, float numberOfWorkersLost) {
if (existingTownHalls <= 0 || numberOfWorkersLost <= 0) {
return 0;
}
float WorkerReplacementCost()
{
return costOfWorker * numberOfWorkersLostToHarass;
return numberOfWorkersLost / Math.Min(existingTownHalls, numberOfWorkersLost);
}
float DelayedMiningCost()
{
return totalAlloyHarassment - WorkerReplacementCost();
float WorkerReplacementCost() {
return CostOfWorker * NumberOfWorkersLostToHarass;
}
float WorkerReplacementCost(int numberOfWorkersLostToHarass) {
return CostOfWorker * numberOfWorkersLostToHarass;
}
void Calculate()
{
totalAlloyHarassment = WorkerReplacementCost();
float DelayedMiningCost() {
return TotalAlloyHarassment - WorkerReplacementCost();
}
for (var workerProductionIndex = 0; workerProductionIndex < SimultaneousProductionFloor(); workerProductionIndex++)
{
void Calculate() {
TotalAlloyHarassment = Calculate(WorkerReplacementCost(),
SimultaneousProductionFloor(),
NumberOfWorkersLostToHarass,
TravelTimes.Select(x => x.Value).ToList(),
TimeToProduceWorker,
AlloyMinedPerSecondByWorker);
}
float Calculate(float workerReplacementCost,
float simultaneousProductionFloor,
float numberOfWorkersLostToHarass,
IList<float> travelTimes,
float timeToProduceWorker = 20,
float alloyMinedPerSecondByWorker = 1) {
float totalAlloyHarassment = workerReplacementCost;
for (var workerProductionIndex = 0; workerProductionIndex < simultaneousProductionFloor; workerProductionIndex++) {
totalAlloyHarassment += alloyMinedPerSecondByWorker * timeToProduceWorker * (workerProductionIndex + 1);
}
var remainder = (int)(numberOfWorkersLostToHarass % SimultaneousProductionFloor());
for (var remainderIndex = 0; remainderIndex < remainder; remainderIndex++)
{
totalAlloyHarassment += alloyMinedPerSecondByWorker * timeToProduceWorker * (SimultaneousProductionFloor() + 1);
var remainder = (int)(numberOfWorkersLostToHarass % simultaneousProductionFloor);
for (var remainderIndex = 0; remainderIndex < remainder; remainderIndex++) {
totalAlloyHarassment += alloyMinedPerSecondByWorker * timeToProduceWorker * (simultaneousProductionFloor + 1);
}
for (var travelTimeIndex = 0; travelTimeIndex < numberOfWorkersLostToHarass; travelTimeIndex++)
{
var townHallIndex = travelTimeIndex % TravelTimes.Count;
totalAlloyHarassment += alloyMinedPerSecondByWorker * TravelTimes[townHallIndex].Value;
for (var travelTimeIndex = 0; travelTimeIndex < numberOfWorkersLostToHarass; travelTimeIndex++) {
var townHallIndex = travelTimeIndex % travelTimes.Count;
totalAlloyHarassment += alloyMinedPerSecondByWorker * travelTimes[townHallIndex];
}
return totalAlloyHarassment;
}
protected override void OnInitialized()
{
protected override void OnInitialized() {
base.OnInitialized();
Calculate();
}
void ValueChanged(float test)
{
Calculate();
}
public List<TravelTime> TravelTimes { get; set; } = new() { new TravelTime(0, 0) };
private void OnTownHallsChanged(ChangeEventArgs obj)
{
numberOfTownHallsExisting = int.Parse(obj.Value!.ToString()!);
private void OnTownHallsChanged(ChangeEventArgs obj) {
NumberOfTownHallsExisting = int.Parse(obj.Value!.ToString()!);
while (TravelTimes.Count > numberOfTownHallsExisting)
while (TravelTimes.Count > NumberOfTownHallsExisting)
TravelTimes.Remove(TravelTimes.Last());
while (TravelTimes.Count < numberOfTownHallsExisting)
TravelTimes.Add(new TravelTime(TravelTimes.Count, 0));
while (TravelTimes.Count < NumberOfTownHallsExisting)
TravelTimes.Add(new TravelTime(TravelTimes.Count, 10 * (TravelTimes.Count)));
Calculate();
}
private void OnTownHallTravelTimeChanged(ChangeEventArgs obj, TravelTime travelTime)
{
private void OnTownHallTravelTimeChanged(ChangeEventArgs obj, TravelTime travelTime) {
travelTime.Value = (int)obj.Value!;
Calculate();

23
IGP/Portals/SearchPortal.razor

@ -1,28 +1,29 @@
@implements IDisposable;
@inject ISearchService SearchService
@inject IJSRuntime JsRuntime
@inject ISearchService searchService
@inject IJSRuntime jsRuntime
<SearchDialogComponent></SearchDialogComponent>
@code {
private string test = "Q";
protected override void OnInitialized()
{
base.OnInitialized();
SearchService.Subscribe(OnUpdate);
searchService.Subscribe(OnUpdate);
}
protected override async Task OnInitializedAsync()
{
await SearchService.Load();
await JsRuntime.InvokeVoidAsync("SetDotnetReference", DotNetObjectReference.Create(this));
await searchService.Load();
await jsRuntime.InvokeVoidAsync("SetDotnetReference", DotNetObjectReference.Create(this));
}
void IDisposable.Dispose()
public void Dispose()
{
SearchService.Unsubscribe(OnUpdate);
searchService.Unsubscribe(OnUpdate);
}
void OnUpdate()
@ -35,13 +36,13 @@
{
if (code.ToLower().Equals("k") && (ctrlKey || shiftKey || altKey || metaKey))
{
if (SearchService.IsVisible)
if (searchService.IsVisible)
{
SearchService.Hide();
searchService.Hide();
}
else
{
SearchService.Show();
searchService.Show();
}
}
}

2
IGP/wwwroot/generated/AgileTaskModels.json

File diff suppressed because one or more lines are too long

4
Model/TravelTime.cs

@ -2,12 +2,12 @@
public class TravelTime
{
public TravelTime(int index, int value)
public TravelTime(int index, float value)
{
Index = index;
Value = value;
}
public int Index { get; set; }
public int Value { get; set; }
public float Value { get; set; }
}

13
TestAutomation/Pages/BasePage.cs

@ -0,0 +1,13 @@
using OpenQA.Selenium;
namespace TestAutomation.Pages;
public class BasePage {
public Website website;
public BasePage(Website website) {
this.website = website;
}
}

70
TestAutomation/Pages/HarassCalculatorPage.cs

@ -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;
}
}

24
TestAutomation/TestAutomation.csproj

@ -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>

120
TestAutomation/UnitTest1.cs

@ -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} ");
}
}

9
TestAutomation/Usings.cs

@ -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;

51
TestAutomation/Website.cs

@ -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;
}
}
Loading…
Cancel
Save