mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Refactored HomePageTests
This commit is contained in:
@@ -7,6 +7,8 @@ namespace Berufsschule_HAM.E2ETests.Helper;
|
|||||||
|
|
||||||
public static class AppHelper
|
public static class AppHelper
|
||||||
{
|
{
|
||||||
|
public const string ServerUrl = "http://localhost:5275";
|
||||||
|
public static Uri ServerUri = new(ServerUrl);
|
||||||
public static async Task<Process> StartApp(string appUrl)
|
public static async Task<Process> StartApp(string appUrl)
|
||||||
{
|
{
|
||||||
var startInfo = new ProcessStartInfo
|
var startInfo = new ProcessStartInfo
|
||||||
@@ -44,9 +46,17 @@ public static class AppHelper
|
|||||||
throw new Exception("Server did not start within 60 seconds");
|
throw new Exception("Server did not start within 60 seconds");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Login(ChromeDriver driver, string serverUrl)
|
public static ChromeDriver GetChromeDriver()
|
||||||
{
|
{
|
||||||
driver.Navigate().GoToUrl(serverUrl);
|
var options = new ChromeOptions();
|
||||||
|
//options.AddArgument("--headless");
|
||||||
|
return new ChromeDriver(options);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Login(ChromeDriver driver)
|
||||||
|
{
|
||||||
|
driver.Navigate().GoToUrl(ServerUrl);
|
||||||
IWebElement username = driver.FindElement(By.Id("username"));
|
IWebElement username = driver.FindElement(By.Id("username"));
|
||||||
username.SendKeys("admin");
|
username.SendKeys("admin");
|
||||||
IWebElement password = driver.FindElement(By.Id("password"));
|
IWebElement password = driver.FindElement(By.Id("password"));
|
||||||
|
|||||||
@@ -14,13 +14,10 @@ public class HomePageTests : IDisposable
|
|||||||
|
|
||||||
public HomePageTests()
|
public HomePageTests()
|
||||||
{
|
{
|
||||||
serverUrl = "http://localhost:5275";
|
serverUrl = AppHelper.ServerUrl;
|
||||||
serverUri = new(serverUrl);
|
serverUri = AppHelper.ServerUri;
|
||||||
Task<Process> app = Helper.AppHelper.StartApp(serverUrl);
|
Task<Process> app = AppHelper.StartApp(serverUrl);
|
||||||
|
_driver = AppHelper.GetChromeDriver();
|
||||||
var options = new ChromeOptions();
|
|
||||||
//options.AddArgument("--headless");
|
|
||||||
_driver = new ChromeDriver(options);
|
|
||||||
serverProcess = app.Result;
|
serverProcess = app.Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,22 +32,35 @@ public class HomePageTests : IDisposable
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void HomePage_ShouldSucceedLogin()
|
public void HomePage_ShouldSucceedLogin()
|
||||||
{
|
{
|
||||||
AppHelper.Login(_driver, serverUrl);
|
AppHelper.Login(_driver);
|
||||||
Assert.Contains("/Home/Index", _driver.Url);
|
Assert.Contains("/Home/Index", _driver.Url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void HomePage_ShouldSucceedLoginAndLogout()
|
||||||
|
{
|
||||||
|
AppHelper.Login(_driver);
|
||||||
|
Assert.Contains("/Home/Index", _driver.Url);
|
||||||
|
IWebElement userDropdown = _driver.FindElement(By.Id("userDropdown"));
|
||||||
|
userDropdown.Click();
|
||||||
|
IWebElement logout = _driver.FindElement(By.CssSelector("a[href=\"/Home/Logout\"]"));
|
||||||
|
Assert.True(logout.Displayed);
|
||||||
|
logout.Click();
|
||||||
|
Thread.Sleep(250);
|
||||||
|
Assert.Contains("/Home/Login", _driver.Url);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void HomePage_ShouldContainButtons()
|
public void HomePage_ShouldContainButtons()
|
||||||
{
|
{
|
||||||
_driver.Navigate().GoToUrl(new Uri(serverUri, "/Home/Index"));
|
_driver.Navigate().GoToUrl(new Uri(serverUri, "/Home/Index"));
|
||||||
AppHelper.Login(_driver, serverUrl);
|
AppHelper.Login(_driver);
|
||||||
List<IWebElement> buttons = [
|
|
||||||
_driver.FindElement(By.CssSelector("a[href=\"/Home/Inventory\"]")),
|
_driver.FindElement(By.CssSelector("a[href=\"/Home/Inventory\"]"));
|
||||||
_driver.FindElement(By.CssSelector("a[href=\"/Home/Assets\"]")),
|
_driver.FindElement(By.CssSelector("a[href=\"/Home/Assets\"]"));
|
||||||
_driver.FindElement(By.CssSelector("a[href=\"/Home/Locations\"]")),
|
_driver.FindElement(By.CssSelector("a[href=\"/Home/Locations\"]"));
|
||||||
_driver.FindElement(By.CssSelector("a[href=\"/Home/Users\"]")),
|
_driver.FindElement(By.CssSelector("a[href=\"/Home/Users\"]"));
|
||||||
_driver.FindElement(By.CssSelector("a[href=\"/Home/Groups\"]")),
|
_driver.FindElement(By.CssSelector("a[href=\"/Home/Groups\"]"));
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
Reference in New Issue
Block a user