Files
IGP-Fan-Reference/Tests/Pages/HarassCalculatorPage.cs
T

49 lines
2.4 KiB
C#

namespace Tests.Pages;
public class HarassCalculatorPage : BasePage
{
public HarassCalculatorPage(Website website) : base(website) { }
public override string Url => "harass-calculator";
public async Task SetWorkersLostToHarassAsync(int number) =>
await EnterAndPressAsync("numberOfWorkersLostToHarass", number);
public async Task SetNumberOfTownHallsExistingAsync(int number) =>
await EnterAndPressAsync("numberOfTownHallsExisting", number);
public async Task SetTownHallTravelTimeAsync(int index, int seconds) =>
await EnterInputAtIndexAsync("numberOfTownHallTravelTimes", index, seconds);
public async Task<int> GetTotalAlloyHarassmentAsync() => await ReadIntAsync("totalAlloyHarassment");
public async Task<int> GetWorkerReplacementCostAsync() => await ReadIntAsync("workerReplacementCost");
public async Task<int> GetDelayedMiningCostAsync() => await ReadIntAsync("delayedMiningCost");
public async Task<int> GetAverageTravelTimeAsync() => await ReadIntAsync("getAverageTravelTime");
public async Task<int> GetExampleTotalAlloyLossAsync() => await ReadIntAsync("exampleTotalAlloyLoss");
public async Task<int> GetExampleWorkerCostAsync() => await ReadIntAsync("exampleWorkerCost");
public async Task<int> GetExampleMiningTimeCostAsync() => await ReadIntAsync("exampleMiningTimeCost");
public async Task<int> GetExampleTotalAlloyLossAccurateAsync() => await ReadIntAsync("exampleTotalAlloyLossAccurate");
public async Task<int> GetExampleTotalAlloyLossDifferenceAsync() => await ReadIntAsync("exampleTotalAlloyLossDifference");
public async Task<int> GetExampleTotalAlloyLossAccurateDifferenceAsync() => await ReadIntAsync("exampleTotalAlloyLossAccurateDifference");
private async Task EnterAndPressAsync(string id, int value)
{
var locator = Website.FindById(id);
await Website.EnterInputAsync(locator, value.ToString());
}
private async Task EnterInputAtIndexAsync(string parentId, int index, int value)
{
var inputs = Website.FindById(parentId).Locator("input");
var input = inputs.Nth(index);
await input.FillAsync(value.ToString());
await input.PressAsync("Enter");
}
private async Task<int> ReadIntAsync(string id)
{
var text = await Website.FindById(id).TextContentAsync() ?? "";
return int.Parse(text.Trim());
}
}