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 GetTotalAlloyHarassmentAsync() => await ReadIntAsync("totalAlloyHarassment"); public async Task GetWorkerReplacementCostAsync() => await ReadIntAsync("workerReplacementCost"); public async Task GetDelayedMiningCostAsync() => await ReadIntAsync("delayedMiningCost"); public async Task GetAverageTravelTimeAsync() => await ReadIntAsync("getAverageTravelTime"); public async Task GetExampleTotalAlloyLossAsync() => await ReadIntAsync("exampleTotalAlloyLoss"); public async Task GetExampleWorkerCostAsync() => await ReadIntAsync("exampleWorkerCost"); public async Task GetExampleMiningTimeCostAsync() => await ReadIntAsync("exampleMiningTimeCost"); public async Task GetExampleTotalAlloyLossAccurateAsync() => await ReadIntAsync("exampleTotalAlloyLossAccurate"); public async Task GetExampleTotalAlloyLossDifferenceAsync() => await ReadIntAsync("exampleTotalAlloyLossDifference"); public async Task 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 ReadIntAsync(string id) { var text = await Website.FindById(id).TextContentAsync() ?? ""; return int.Parse(text.Trim()); } }