Code cleanup
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
using AOW4.SeleniumTests.Driver;
|
||||
using NUnit.Framework;
|
||||
using OpenQA.Selenium;
|
||||
using AOW4.SeleniumTests.Driver;
|
||||
|
||||
namespace AOW4.SeleniumTests.Tests;
|
||||
|
||||
[TestFixture]
|
||||
public abstract class BaseTest
|
||||
{
|
||||
protected IWebDriver Driver = null!;
|
||||
protected string BaseUrl => "http://localhost:5212/";
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void GlobalSetup()
|
||||
{
|
||||
@@ -29,8 +26,11 @@ public abstract class BaseTest
|
||||
}
|
||||
}
|
||||
|
||||
protected IWebDriver Driver = null!;
|
||||
protected string BaseUrl => "http://localhost:5212/";
|
||||
|
||||
protected void GoHome()
|
||||
{
|
||||
Driver.Navigate().GoToUrl(BaseUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using NUnit.Framework;
|
||||
using System.Net.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenQA.Selenium;
|
||||
|
||||
namespace AOW4.SeleniumTests.Tests;
|
||||
@@ -25,19 +22,16 @@ public class BrokenLinksTest : BaseTest
|
||||
|
||||
foreach (var raw in anchors)
|
||||
{
|
||||
if (raw.StartsWith("javascript:", System.StringComparison.OrdinalIgnoreCase))
|
||||
if (raw.StartsWith("javascript:", StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
if (raw.StartsWith("mailto:", System.StringComparison.OrdinalIgnoreCase))
|
||||
if (raw.StartsWith("mailto:", StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
|
||||
System.Uri uri;
|
||||
Uri uri;
|
||||
try
|
||||
{
|
||||
uri = new System.Uri(raw, System.UriKind.RelativeOrAbsolute);
|
||||
if (!uri.IsAbsoluteUri)
|
||||
{
|
||||
uri = new System.Uri(new System.Uri(BaseUrl), raw);
|
||||
}
|
||||
uri = new Uri(raw, UriKind.RelativeOrAbsolute);
|
||||
if (!uri.IsAbsoluteUri) uri = new Uri(new Uri(BaseUrl), raw);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -54,21 +48,15 @@ public class BrokenLinksTest : BaseTest
|
||||
// try GET as fallback
|
||||
using var greq = new HttpRequestMessage(HttpMethod.Get, uri);
|
||||
var gresp = client.Send(greq);
|
||||
if (!gresp.IsSuccessStatusCode)
|
||||
{
|
||||
failures.Add($"{(int)gresp.StatusCode} {uri}");
|
||||
}
|
||||
if (!gresp.IsSuccessStatusCode) failures.Add($"{(int)gresp.StatusCode} {uri}");
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
failures.Add($"Error checking {uri}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
if (failures.Any())
|
||||
{
|
||||
Assert.Fail("Broken links found:\n" + string.Join("\n", failures));
|
||||
}
|
||||
if (failures.Any()) Assert.Fail("Broken links found:\n" + string.Join("\n", failures));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using NUnit.Framework;
|
||||
using AOW4.SeleniumTests.Pages;
|
||||
|
||||
namespace AOW4.SeleniumTests.Tests;
|
||||
|
||||
@@ -11,7 +10,9 @@ public class NavigationTests : BaseTest
|
||||
{
|
||||
GoHome();
|
||||
|
||||
Assert.IsTrue(Driver.Url.Contains(expectedPath, System.StringComparison.OrdinalIgnoreCase) || Driver.PageSource.Contains(linkText),
|
||||
Assert.IsTrue(
|
||||
Driver.Url.Contains(expectedPath, StringComparison.OrdinalIgnoreCase) ||
|
||||
Driver.PageSource.Contains(linkText),
|
||||
$"Expected to be on route containing '{expectedPath}' after clicking '{linkText}', but was '{Driver.Url}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user