mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Merge pull request #293 from LD-Reborn/290-e2e-tests---location
290 e2e tests location
This commit is contained in:
2
tests/Berufsschule_HAM.E2ETests/AssemblyInfo.cs
Normal file
2
tests/Berufsschule_HAM.E2ETests/AssemblyInfo.cs
Normal file
@@ -0,0 +1,2 @@
|
||||
using Xunit;
|
||||
[assembly: CollectionBehavior(DisableTestParallelization = true)]
|
||||
@@ -101,4 +101,24 @@ public static class AppHelper
|
||||
{
|
||||
return webElement.GetAttribute("checked") == "true";
|
||||
}
|
||||
|
||||
public static void ScrollIntoViewAndClick(ChromeDriver driver, IWebElement webElement)
|
||||
{
|
||||
driver.ExecuteScript("arguments[0].scrollIntoView();", webElement);
|
||||
int retryCounter = 0;
|
||||
retry:
|
||||
try
|
||||
{
|
||||
Thread.Sleep(250);
|
||||
webElement.Click();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (retryCounter++ < 20)
|
||||
{
|
||||
goto retry;
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public static class GroupsHelper
|
||||
{
|
||||
NavigateToGroupsPage(driver);
|
||||
IWebElement updateGroupButton = driver.FindElement(By.CssSelector($"button[data-group-id=\"{cn}\"].btn-update"));
|
||||
updateGroupButton.Click();
|
||||
AppHelper.ScrollIntoViewAndClick(driver, updateGroupButton);
|
||||
Thread.Sleep(500);
|
||||
var cnInput = driver.FindElement(By.CssSelector("input#groupId"));
|
||||
cnInput.Click();
|
||||
@@ -68,7 +68,7 @@ public static class GroupsHelper
|
||||
{
|
||||
NavigateToGroupsPage(driver);
|
||||
IWebElement deleteButton = driver.FindElement(By.CssSelector($"button[data-group-id=\"{cn}\"].btn-delete"));
|
||||
deleteButton.Click();
|
||||
AppHelper.ScrollIntoViewAndClick(driver, deleteButton);
|
||||
Thread.Sleep(1000);
|
||||
driver.FindElement(By.Id("deleteModal"));
|
||||
IWebElement deleteConfirmButton = driver.FindElement(By.CssSelector("#deleteModal .btn-danger"));
|
||||
|
||||
62
tests/Berufsschule_HAM.E2ETests/Helper/LocationsHelper.cs
Normal file
62
tests/Berufsschule_HAM.E2ETests/Helper/LocationsHelper.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Chrome;
|
||||
using OpenQA.Selenium.Support.UI;
|
||||
|
||||
namespace Berufsschule_HAM.E2ETests.Helper;
|
||||
|
||||
public static class LocationsHelper
|
||||
{
|
||||
public static void CreateLocation(ChromeDriver driver, string name, string room, string seat)
|
||||
{
|
||||
NavigateToLocationsPage(driver);
|
||||
IWebElement createLocationButton = driver.FindElement(By.CssSelector("button[data-bs-target=\"#createModal\"]"));
|
||||
createLocationButton.Click();
|
||||
Thread.Sleep(500);
|
||||
driver.FindElement(By.Id("createLocationName")).SendKeys(name);
|
||||
driver.FindElement(By.Id("createRoomNumber")).SendKeys(room);
|
||||
driver.FindElement(By.Id("createSeat")).SendKeys(seat);
|
||||
IWebElement createButton = driver.FindElement(By.CssSelector("#createModal .btn-primary"));
|
||||
createButton.Click();
|
||||
Assert.True(AppHelper.TryRetryFindSuccessToast(driver));
|
||||
}
|
||||
|
||||
public static void UpdateLocation(ChromeDriver driver, string name, string room, string seat, string newName, string newRoom, string newSeat)
|
||||
{
|
||||
NavigateToLocationsPage(driver);
|
||||
string selector = $"button.btn-warning[data-location-name=\"{name}\"][data-room-number=\"{room}\"][data-seat=\"{seat}\"]";
|
||||
IWebElement updateLocationButton = driver.FindElement(By.CssSelector(selector));
|
||||
AppHelper.ScrollIntoViewAndClick(driver, updateLocationButton);
|
||||
Thread.Sleep(500);
|
||||
List<string[]> ids = [["editLocationName", newName], ["editRoomNumber", newRoom], ["editSeat", newSeat]];
|
||||
ids.ForEach(id =>
|
||||
{
|
||||
var cnInput = driver.FindElement(By.Id(id[0]));
|
||||
cnInput.Click();
|
||||
cnInput.Clear();
|
||||
cnInput.SendKeys(id[1]);
|
||||
});
|
||||
IWebElement updateButton = driver.FindElement(By.CssSelector("#editModal .btn-warning"));
|
||||
updateButton.Click();
|
||||
Assert.True(AppHelper.TryRetryFindSuccessToast(driver));
|
||||
}
|
||||
|
||||
|
||||
public static void DeleteLocation(ChromeDriver driver, string cn)
|
||||
{
|
||||
NavigateToLocationsPage(driver);
|
||||
IWebElement deleteButton = driver.FindElement(By.CssSelector($"button.btn-danger[data-location-id=\"{cn}\"]"));
|
||||
AppHelper.ScrollIntoViewAndClick(driver, deleteButton);
|
||||
Thread.Sleep(1000);
|
||||
driver.FindElement(By.Id("deleteModal"));
|
||||
IWebElement deleteConfirmButton = driver.FindElement(By.Id("deleteForm"));
|
||||
deleteConfirmButton.Click();
|
||||
Assert.True(AppHelper.TryRetryFindSuccessToast(driver));
|
||||
}
|
||||
|
||||
public static void NavigateToLocationsPage(ChromeDriver driver)
|
||||
{
|
||||
driver.Navigate().GoToUrl(new Uri(AppHelper.ServerUri, "/Home/Locations"));
|
||||
}
|
||||
}
|
||||
58
tests/Berufsschule_HAM.E2ETests/LocationsPageTests.cs
Normal file
58
tests/Berufsschule_HAM.E2ETests/LocationsPageTests.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Berufsschule_HAM.E2ETests.Helper;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Chrome;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Berufsschule_HAM.E2ETests;
|
||||
|
||||
public class LocationsPageTests : IDisposable
|
||||
{
|
||||
private readonly ChromeDriver _driver;
|
||||
public Uri serverUri;
|
||||
public string serverUrl;
|
||||
public Process serverProcess;
|
||||
|
||||
public LocationsPageTests()
|
||||
{
|
||||
serverUrl = AppHelper.ServerUrl;
|
||||
serverUri = AppHelper.ServerUri;
|
||||
Task<Process> app = AppHelper.StartApp(serverUrl);
|
||||
_driver = AppHelper.GetChromeDriver();
|
||||
serverProcess = app.Result;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocationsPage_ShouldShowButton()
|
||||
{
|
||||
AppHelper.Login(_driver);
|
||||
LocationsHelper.NavigateToLocationsPage(_driver);
|
||||
_driver.FindElement(By.CssSelector("button[data-bs-target=\"#createModal\"]"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocationsPage_ShouldShowCreateViewModal()
|
||||
{
|
||||
AppHelper.Login(_driver);
|
||||
LocationsHelper.NavigateToLocationsPage(_driver);
|
||||
List<string> ids = ["createLocationName", "createRoomNumber", "createSeat"];
|
||||
List<string> css = ["#createModal .btn-primary", "#createModal .btn-secondary"];
|
||||
ids.ForEach(id => _driver.FindElement(By.Id(id)));
|
||||
css.ForEach(selector => _driver.FindElement(By.CssSelector(selector)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocationsPage_ShouldCreateAndUpdateAndDeleteGroup()
|
||||
{
|
||||
AppHelper.Login(_driver);
|
||||
LocationsHelper.NavigateToLocationsPage(_driver);
|
||||
LocationsHelper.CreateLocation(_driver, "RESERVED_LOCATION", "RESERVED_ROOM", "RESERVED_ROOMNUMBER");
|
||||
LocationsHelper.UpdateLocation(_driver, "RESERVED_LOCATION", "RESERVED_ROOM", "RESERVED_ROOMNUMBER", "RESERVED_LOCATION2", "RESERVED_ROOM2", "RESERVED_ROOMNUMBER2");
|
||||
LocationsHelper.UpdateLocation(_driver, "RESERVED_LOCATION2", "RESERVED_ROOM2", "RESERVED_ROOMNUMBER2", "RESERVED_LOCATION", "RESERVED_ROOM", "RESERVED_ROOMNUMBER");
|
||||
LocationsHelper.DeleteLocation(_driver, "reservedlocation-reservedroom-reservedroomnumber");
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_driver.Quit();
|
||||
serverProcess.Kill();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user