mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-19 22:41:55 +00:00
Added initial Selenium E2E test setup
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@ src/obj/*
|
||||
src/logs/*
|
||||
src/Elmah/*
|
||||
publish/*
|
||||
tests/Berufsschule_HAM.E2ETests/obj/*
|
||||
tests/Berufsschule_HAM.E2ETests/bin/*
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.2.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Berufsschule_HAM", "Berufsschule_HAM.csproj", "{93DF3CFA-1E88-78A3-FA37-F268564DC5FB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Berufsschule_HAM.E2ETests", "..\tests\Berufsschule_HAM.E2ETests\Berufsschule_HAM.E2ETests.csproj", "{26D89942-FBE0-4FCC-9DB5-CFEFC75C5222}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -14,6 +16,10 @@ Global
|
||||
{93DF3CFA-1E88-78A3-FA37-F268564DC5FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{93DF3CFA-1E88-78A3-FA37-F268564DC5FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{93DF3CFA-1E88-78A3-FA37-F268564DC5FB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{26D89942-FBE0-4FCC-9DB5-CFEFC75C5222}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{26D89942-FBE0-4FCC-9DB5-CFEFC75C5222}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{26D89942-FBE0-4FCC-9DB5-CFEFC75C5222}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{26D89942-FBE0-4FCC-9DB5-CFEFC75C5222}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
|
||||
<PackageReference Include="Selenium.Support" Version="4.38.0" />
|
||||
<PackageReference Include="Selenium.WebDriver" Version="4.38.0" />
|
||||
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="142.0.7444.6100" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Berufsschule_HAM.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
45
tests/Berufsschule_HAM.E2ETests/Helper/AppHelper.cs
Normal file
45
tests/Berufsschule_HAM.E2ETests/Helper/AppHelper.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
|
||||
namespace Berufsschule_HAM.E2ETests.Helper;
|
||||
|
||||
public static class AppHelper
|
||||
{
|
||||
public static async Task<Process> StartApp(string appUrl)
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "/snap/bin/dotnet",
|
||||
Arguments = "run --project ../../../../../src/",
|
||||
WorkingDirectory = AppContext.BaseDirectory,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
};
|
||||
startInfo.EnvironmentVariables["ASPNETCORE_ENVIRONMENT"] = "Development";
|
||||
|
||||
|
||||
var process = new Process { StartInfo = startInfo };// Process process = Process.Start("/snap/bin/dotnet", "run -e Development");
|
||||
process.Start();
|
||||
using var client = new HttpClient();
|
||||
for (int i = 0; i < 60; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await client.GetAsync(appUrl);
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return process;
|
||||
}
|
||||
else if (response.StatusCode != HttpStatusCode.RequestTimeout)
|
||||
{
|
||||
throw new Exception($"Server did not start properly? {response.StatusCode}");
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
throw new Exception("Server did not start within 60 seconds");
|
||||
}
|
||||
}
|
||||
37
tests/Berufsschule_HAM.E2ETests/HomePageTests.cs
Normal file
37
tests/Berufsschule_HAM.E2ETests/HomePageTests.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Chrome;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Berufsschule_HAM.E2ETests;
|
||||
|
||||
public class HomePageTests : IDisposable
|
||||
{
|
||||
private readonly ChromeDriver _driver;
|
||||
public string serverUrl;
|
||||
public Process serverProcess;
|
||||
|
||||
public HomePageTests()
|
||||
{
|
||||
serverUrl = "http://localhost:5275";
|
||||
Task<Process> app = Helper.AppHelper.StartApp(serverUrl);
|
||||
|
||||
var options = new ChromeOptions();
|
||||
//options.AddArgument("--headless");
|
||||
_driver = new ChromeDriver(options);
|
||||
serverProcess = app.Result;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HomePage_ShouldShowLoginPage()
|
||||
{
|
||||
_driver.Navigate().GoToUrl(serverUrl);
|
||||
IWebElement loginForm = _driver.FindElement(By.CssSelector("form[action=\"/Home/Login\"]"));
|
||||
Assert.True(loginForm.Displayed);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_driver.Quit();
|
||||
serverProcess.Close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user