Replaced unreliable sleeps with WebDriverWait

This commit is contained in:
2025-11-10 00:29:36 +01:00
parent 53645a4b7e
commit fb15d825d0
6 changed files with 35 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
using Berufsschule_HAM.E2ETests.Helper;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using SeleniumExtras.WaitHelpers;
using System.Diagnostics;
namespace Berufsschule_HAM.E2ETests;
@@ -41,11 +42,10 @@ public class InventoryPageTests : IDisposable
assetIdInputField.SendKeys("1");
IWebElement scanBarcode = _driver.FindElement(By.Id("enterAssetIdManuallyButton"));
scanBarcode.Click();
Thread.Sleep(500);
AppHelper.AwaitVisible(_driver, By.Id("viewAssetModal"));
IWebElement viewModal = _driver.FindElement(By.Id("viewAssetModal"));
Assert.True(viewModal.Displayed);
Assert.True(_driver.FindElement(By.CssSelector("svg[class=\"form-control\"]")).Displayed);
Thread.Sleep(500);
Assert.NotEmpty(_driver.FindElement(By.Id("detailName")).GetAttribute("value") ?? "");
Assert.NotEmpty(_driver.FindElement(By.Id("detailLocation")).GetAttribute("value") ?? "");
@@ -71,12 +71,11 @@ public class InventoryPageTests : IDisposable
assetIdInputField.SendKeys("1");
IWebElement scanBarcode = _driver.FindElement(By.Id("enterAssetIdManuallyButton"));
scanBarcode.Click();
Thread.Sleep(500);
AppHelper.AwaitVisible(_driver, By.Id("viewAssetModal"));
IWebElement viewModal = _driver.FindElement(By.Id("viewAssetModal"));
Assert.True(viewModal.Displayed);
IWebElement okButton = _driver.FindElement(By.CssSelector("#viewAssetModal button.btn.btn-primary[data-bs-dismiss=\"modal\"]"));
okButton.Click();
Thread.Sleep(500);
Assert.True(AppHelper.TryRetryFindSuccessToast(_driver));
}
@@ -89,15 +88,14 @@ public class InventoryPageTests : IDisposable
assetIdInputField.SendKeys("1");
IWebElement scanBarcode = _driver.FindElement(By.Id("enterAssetIdManuallyButton"));
scanBarcode.Click();
Thread.Sleep(500);
AppHelper.AwaitVisible(_driver, By.Id("viewAssetModal"));
IWebElement viewModal = _driver.FindElement(By.Id("viewAssetModal"));
Assert.True(viewModal.Displayed);
IWebElement updateButton = _driver.FindElement(By.CssSelector("#viewAssetModal button.btn.btn-warning[data-bs-dismiss=\"modal\"]"));
updateButton.Click();
Thread.Sleep(1000);
AppHelper.AwaitVisible(_driver, By.CssSelector("#updateAssetModal button.btn.btn-warning[type=\"submit\"]"));
IWebElement okButton = _driver.FindElement(By.CssSelector("#updateAssetModal button.btn.btn-warning[type=\"submit\"]"));
okButton.Click();
Thread.Sleep(500);
Assert.True(AppHelper.TryRetryFindSuccessToast(_driver));
}
@@ -108,7 +106,7 @@ public class InventoryPageTests : IDisposable
_driver.Navigate().GoToUrl(new Uri(serverUri, "/Home/Inventory"));
IWebElement link = _driver.FindElement(By.CssSelector("a[href=\"/Home/Assets?CreateModal=true\"]"));
link.Click();
Thread.Sleep(500);
AppHelper.Timeout(_driver).Until(ExpectedConditions.UrlContains("/Home/Assets"));
Assert.Contains("/Home/Assets", _driver.Url);
}
@@ -119,7 +117,7 @@ public class InventoryPageTests : IDisposable
_driver.Navigate().GoToUrl(new Uri(serverUri, "/Home/Inventory"));
IWebElement openPrintModalButton = _driver.FindElement(By.Id("openPrintModal"));
openPrintModalButton.Click();
Thread.Sleep(500);
AppHelper.AwaitVisible(_driver, By.Id("printModal"));
IWebElement printModal = _driver.FindElement(By.Id("printModal"));
Assert.True(printModal.Displayed);
}