mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Added HomePage_ShouldContainButtons E2E test, added login helper
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using OpenQA.Selenium;
|
||||||
|
using OpenQA.Selenium.Chrome;
|
||||||
|
|
||||||
namespace Berufsschule_HAM.E2ETests.Helper;
|
namespace Berufsschule_HAM.E2ETests.Helper;
|
||||||
|
|
||||||
@@ -42,4 +43,16 @@ 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)
|
||||||
|
{
|
||||||
|
driver.Navigate().GoToUrl(serverUrl);
|
||||||
|
IWebElement username = driver.FindElement(By.Id("username"));
|
||||||
|
username.SendKeys("admin");
|
||||||
|
IWebElement password = driver.FindElement(By.Id("password"));
|
||||||
|
password.SendKeys("Test1234.");
|
||||||
|
IWebElement submit = driver.FindElement(By.CssSelector("button[type=\"submit\"]"));
|
||||||
|
submit.Click();
|
||||||
|
Thread.Sleep(250);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using OpenQA.Selenium;
|
using Berufsschule_HAM.E2ETests.Helper;
|
||||||
|
using OpenQA.Selenium;
|
||||||
using OpenQA.Selenium.Chrome;
|
using OpenQA.Selenium.Chrome;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
@@ -7,12 +8,14 @@ namespace Berufsschule_HAM.E2ETests;
|
|||||||
public class HomePageTests : IDisposable
|
public class HomePageTests : IDisposable
|
||||||
{
|
{
|
||||||
private readonly ChromeDriver _driver;
|
private readonly ChromeDriver _driver;
|
||||||
|
public Uri serverUri;
|
||||||
public string serverUrl;
|
public string serverUrl;
|
||||||
public Process serverProcess;
|
public Process serverProcess;
|
||||||
|
|
||||||
public HomePageTests()
|
public HomePageTests()
|
||||||
{
|
{
|
||||||
serverUrl = "http://localhost:5275";
|
serverUrl = "http://localhost:5275";
|
||||||
|
serverUri = new(serverUrl);
|
||||||
Task<Process> app = Helper.AppHelper.StartApp(serverUrl);
|
Task<Process> app = Helper.AppHelper.StartApp(serverUrl);
|
||||||
|
|
||||||
var options = new ChromeOptions();
|
var options = new ChromeOptions();
|
||||||
@@ -32,17 +35,24 @@ public class HomePageTests : IDisposable
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void HomePage_ShouldSucceedLogin()
|
public void HomePage_ShouldSucceedLogin()
|
||||||
{
|
{
|
||||||
_driver.Navigate().GoToUrl(serverUrl);
|
AppHelper.Login(_driver, serverUrl);
|
||||||
IWebElement username = _driver.FindElement(By.Id("username"));
|
|
||||||
username.SendKeys("admin");
|
|
||||||
IWebElement password = _driver.FindElement(By.Id("password"));
|
|
||||||
password.SendKeys("Test1234.");
|
|
||||||
IWebElement submit = _driver.FindElement(By.CssSelector("button[type=\"submit\"]"));
|
|
||||||
submit.Click();
|
|
||||||
Thread.Sleep(250);
|
|
||||||
Assert.Contains("/Home/Index", _driver.Url);
|
Assert.Contains("/Home/Index", _driver.Url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void HomePage_ShouldContainButtons()
|
||||||
|
{
|
||||||
|
_driver.Navigate().GoToUrl(new Uri(serverUri, "/Home/Index"));
|
||||||
|
AppHelper.Login(_driver, serverUrl);
|
||||||
|
List<IWebElement> buttons = [
|
||||||
|
_driver.FindElement(By.CssSelector("a[href=\"/Home/Inventory\"]")),
|
||||||
|
_driver.FindElement(By.CssSelector("a[href=\"/Home/Assets\"]")),
|
||||||
|
_driver.FindElement(By.CssSelector("a[href=\"/Home/Locations\"]")),
|
||||||
|
_driver.FindElement(By.CssSelector("a[href=\"/Home/Users\"]")),
|
||||||
|
_driver.FindElement(By.CssSelector("a[href=\"/Home/Groups\"]")),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_driver.Quit();
|
_driver.Quit();
|
||||||
|
|||||||
Reference in New Issue
Block a user