From 76409a19c8118b30e72780b26c5b4b33b3a55c85 Mon Sep 17 00:00:00 2001 From: binon Date: Tue, 20 Feb 2024 17:05:22 +0000 Subject: [PATCH 1/8] TD-2899 - New project accessibilty unit test --- .gitignore | 1 + .../AccessibilityTestsBase.cs | 67 +++++++++ .../BasicAccessibilityTests.cs | 39 +++++ ...rningHub.Nhs.WebUI.AutomatedUiTests.csproj | 55 +++++++ .../SeleniumServerFactory.cs | 138 ++++++++++++++++++ .../TestFixtures/AccessibilityTestsFixture.cs | 55 +++++++ .../AuthenticatedAccessibilityTestsFixture.cs | 37 +++++ .../MyAccountAccessibiltyTests.cs | 63 ++++++++ .../TestHelpers/ConfigurationHelper.cs | 26 ++++ .../TestHelpers/DriverHelper.cs | 111 ++++++++++++++ .../TestHelpers/LoginHelper.cs | 54 +++++++ .../appsettings.json | 7 + LearningHub.Nhs.WebUI.sln | 10 ++ 13 files changed, 663 insertions(+) create mode 100644 LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs create mode 100644 LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs create mode 100644 LearningHub.Nhs.WebUI.AutomatedUiTests/LearningHub.Nhs.WebUI.AutomatedUiTests.csproj create mode 100644 LearningHub.Nhs.WebUI.AutomatedUiTests/SeleniumServerFactory.cs create mode 100644 LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs create mode 100644 LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AuthenticatedAccessibilityTestsFixture.cs create mode 100644 LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/MyAccountAccessibiltyTests.cs create mode 100644 LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/ConfigurationHelper.cs create mode 100644 LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/DriverHelper.cs create mode 100644 LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs create mode 100644 LearningHub.Nhs.WebUI.AutomatedUiTests/appsettings.json diff --git a/.gitignore b/.gitignore index 0afa44753..4119589ad 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,4 @@ obj /WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.jfm /WebAPI/MigrationTool/LearningHub.Nhs.Migration.Staging.Database/LearningHub.Nhs.Migration.Staging.Database.dbmdl /WebAPI/MigrationTool/LearningHub.Nhs.Migration.Staging.Database/LearningHub.Nhs.Migration.Staging.Database.jfm +/LearningHub.Nhs.WebUI.AutomatedUiTests/appsettings.Development.json diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs new file mode 100644 index 000000000..2560b4326 --- /dev/null +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs @@ -0,0 +1,67 @@ +// +// Copyright (c) HEE.nhs.uk. +// + +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests +{ + using FluentAssertions; + using LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures; + using LearningHub.Nhs.WebUI.Startup; + using OpenQA.Selenium; + using Selenium.Axe; + using Xunit; + + /// + /// Accessibility Tests Base. + /// + [Collection("Selenium test collection")] + public class AccessibilityTestsBase + { + /// + /// Gets the base URL for the tests. + /// +#pragma warning disable SA1401 // Fields should be private + internal readonly string BaseUrl; +#pragma warning restore SA1401 // Fields should be private + + /// + /// Gets the WebDriver used for the tests. + /// +#pragma warning disable SA1401 // Fields should be private + internal readonly IWebDriver Driver; +#pragma warning restore SA1401 // Fields should be private + + /// + /// Initializes a new instance of the class. + /// + /// fixture. + public AccessibilityTestsBase(AccessibilityTestsFixture fixture) + { + this.BaseUrl = fixture.BaseUrl; + this.Driver = fixture.Driver; + } + + /// + /// Analyze Page Heading And Accessibility. + /// + /// Page Title. + public void AnalyzePageHeadingAndAccessibility(string pageTitle) + { + this.ValidatePageHeading(pageTitle); + + // then + var axeResult = new AxeBuilder(this.Driver).Analyze(); + axeResult.Violations.Should().BeEmpty(); + } + + /// + /// ValidatePageHeading. + /// + /// Page Title. + public void ValidatePageHeading(string pageTitle) + { + var h1Element = this.Driver.FindElement(By.TagName("h1")); + h1Element.Text.Should().BeEquivalentTo(pageTitle); + } + } +} diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs new file mode 100644 index 000000000..37c3da9a6 --- /dev/null +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs @@ -0,0 +1,39 @@ +// +// Copyright (c) HEE.nhs.uk. +// + +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests +{ + using LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures; + using Xunit; + + /// + /// BasicAccessibilityTests. + /// + public class BasicAccessibilityTests : AccessibilityTestsBase, IClassFixture> + { + /// + /// Initializes a new instance of the class. + /// BasicAccessibilityTests. + /// + /// fixture. + public BasicAccessibilityTests(AccessibilityTestsFixture fixture) + : base(fixture) + { + } + + [Theory] + [InlineData("/Home/Index", "A platform for learning and sharing resources")] + +#pragma warning disable SA1600 // Elements should be documented + public void PageHasNoAccessibilityErrors(string url, string pageTitle) +#pragma warning restore SA1600 // Elements should be documented + { + // when + this.Driver.Navigate().GoToUrl(this.BaseUrl + url); + + // then + this.AnalyzePageHeadingAndAccessibility(pageTitle); + } + } +} diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/LearningHub.Nhs.WebUI.AutomatedUiTests.csproj b/LearningHub.Nhs.WebUI.AutomatedUiTests/LearningHub.Nhs.WebUI.AutomatedUiTests.csproj new file mode 100644 index 000000000..719ae88fb --- /dev/null +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/LearningHub.Nhs.WebUI.AutomatedUiTests.csproj @@ -0,0 +1,55 @@ + + + + net6.0 + enable + enable + + false + + True + + + + + + + + + + PreserveNewest + true + PreserveNewest + + + PreserveNewest + true + PreserveNewest + + + + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/SeleniumServerFactory.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/SeleniumServerFactory.cs new file mode 100644 index 000000000..e01df94f3 --- /dev/null +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/SeleniumServerFactory.cs @@ -0,0 +1,138 @@ +// +// Copyright (c) HEE.nhs.uk. +// + +namespace LearningHub.Nhs.WebUI.AutomatedUiTests +{ + using System; + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + using LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers; + using LearningHub.Nhs.WebUI.Startup; + using Microsoft.AspNetCore; + using Microsoft.AspNetCore.Hosting; + using Microsoft.AspNetCore.Hosting.Server.Features; + using Microsoft.AspNetCore.Mvc.Testing; + using Microsoft.AspNetCore.TestHost; + using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.Configuration.Json; + using Serilog; + + /// + /// SeleniumServerFactory. + /// + /// TStartup. + public class SeleniumServerFactory : WebApplicationFactory + where TStartup : class + { + /// + /// Root Uri. + /// +#pragma warning disable SA1401 // Fields should be private + public string RootUri; +#pragma warning restore SA1401 // Fields should be private + private IWebHost host; + + /// + /// Initializes a new instance of the class. + /// + public SeleniumServerFactory() + { + IConfiguration configuration = ConfigurationHelper.GetConfiguration(); + this.RootUri = configuration["LearningHubWebUiUrl"]; + + // We are consuming from IIS express + // this.CreateServer(this.CreateWebHostBuilder()); + // this.CreateClient(); + } + + /// + /// Create Server. + /// + /// builder. + /// TestServer. + protected sealed override TestServer CreateServer(IWebHostBuilder builder) + { + // base.ConfigureWebHost(builder); + + // Real TCP port + var host = builder + .UseStartup() + .UseSerilog() + .ConfigureAppConfiguration(configBuilder => + { + configBuilder.AddConfiguration(GetConfigForUiTests()); + }) + .Build(); + + host.Start(); + var rootUri = host.ServerFeatures.Get().Addresses.First(); + + // Fake Server to satisfy the return type + return new TestServer( + new WebHostBuilder() + .UseStartup() + .UseSerilog() + .ConfigureAppConfiguration( + configBuilder => { configBuilder.AddConfiguration(GetConfigForUiTests()); })); + } + + /// + /// Create Web Host Builder. + /// + /// CreateDefaultBuilder. + protected sealed override IWebHostBuilder CreateWebHostBuilder() + { + return WebHost.CreateDefaultBuilder(Array.Empty()) + .UseStartup() + .UseSerilog() + .UseUrls("http://127.0.0.1:0") + .ConfigureAppConfiguration( + configBuilder => + { + var jsonConfigSources = configBuilder.Sources + .Where(source => source.GetType() == typeof(JsonConfigurationSource)) + .ToList(); + + foreach (var jsonConfigSource in jsonConfigSources) + { + configBuilder.Sources.Remove(jsonConfigSource); + } + + configBuilder.AddConfiguration(GetConfigForUiTests()); + }); + } + + /// + /// Dispose implementation. + /// + /// disposing. + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (disposing) + { + this.host?.Dispose(); + } + } + + /// + /// Get Config ForUi Tests. + /// + /// ConfigurationBuilder. + private static IConfigurationRoot GetConfigForUiTests() + { + return new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.Development.json") + .AddEnvironmentVariables("DlsRefactor_") + .AddUserSecrets(typeof(Program).Assembly) + .Build(); + } + } +} diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs new file mode 100644 index 000000000..8238b893d --- /dev/null +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs @@ -0,0 +1,55 @@ +// +// Copyright (c) HEE.nhs.uk. +// + +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures +{ + using System; + using System.Data.SqlClient; + using LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers; + using OpenQA.Selenium; + + /// + /// Represents a fixture for accessibility tests. + /// + /// The type of the startup class. + public class AccessibilityTestsFixture : IDisposable + where TStartup : class + { + /// + /// Gets the base URL for the tests. + /// +#pragma warning disable SA1401 // Fields should be private + internal readonly string BaseUrl; +#pragma warning restore SA1401 // Fields should be private + + /// + /// Gets the WebDriver used for the tests. + /// +#pragma warning disable SA1401 // Fields should be private + internal readonly IWebDriver Driver; +#pragma warning restore SA1401 // Fields should be private + + private readonly SeleniumServerFactory factory; + + /// + /// Initializes a new instance of the class. + /// + public AccessibilityTestsFixture() + { + this.factory = new SeleniumServerFactory(); + this.BaseUrl = this.factory.RootUri; + this.Driver = DriverHelper.CreateHeadlessChromeDriver(); + } + + /// + /// Dispose. + /// + public void Dispose() + { + this.Driver.Quit(); + this.Driver.Dispose(); + this.factory.Dispose(); + } + } +} diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AuthenticatedAccessibilityTestsFixture.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AuthenticatedAccessibilityTestsFixture.cs new file mode 100644 index 000000000..8fc395da5 --- /dev/null +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AuthenticatedAccessibilityTestsFixture.cs @@ -0,0 +1,37 @@ +// +// Copyright (c) HEE.nhs.uk. +// + +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures +{ + using LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers; + using Microsoft.Extensions.Configuration; + + /// + /// AuthenticatedAccessibilityTestsFixture. + /// + /// TStartup. + public class AuthenticatedAccessibilityTestsFixture : AccessibilityTestsFixture + where TStartup : class + { + /// + /// Initializes a new instance of the class. + /// + public AuthenticatedAccessibilityTestsFixture() + { + IConfiguration configuration = ConfigurationHelper.GetConfiguration(); + string adminUsername = configuration["AdminUser:Username"]; + string adminPassword = configuration["AdminUser:Password"]; + this.Driver.LogUserInAsAdmin(this.BaseUrl, adminUsername, adminPassword); + } + + /// + /// Dispose. + /// + public new void Dispose() + { + this.Driver.LogOutUser(this.BaseUrl); + base.Dispose(); + } + } +} diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/MyAccountAccessibiltyTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/MyAccountAccessibiltyTests.cs new file mode 100644 index 000000000..3d80d035a --- /dev/null +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/MyAccountAccessibiltyTests.cs @@ -0,0 +1,63 @@ +// +// Copyright (c) HEE.nhs.uk. +// + +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures +{ + using FluentAssertions; + using LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests; + using LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers; + using Selenium.Axe; + using Xunit; + + /// + /// MyAccountAccessibiltyTests. + /// + public class MyAccountAccessibiltyTests : AccessibilityTestsBase, + IClassFixture> + { + /// + /// Initializes a new instance of the class. + /// MyAccountAccessibiltyTests. + /// + /// fixture. + public MyAccountAccessibiltyTests(AuthenticatedAccessibilityTestsFixture fixture) + : base(fixture) + { + } + + /// + /// MyAccountPageHasNoAccessibilityErrors. + /// + [Fact] + public void MyAccountPageHasNoAccessibilityErrors() + { + // given + // this.Driver.LogUserInAsAdmin(this.BaseUrl); + const string myaccountsUrl = "/myaccount"; + + // when + this.Driver.Navigate().GoToUrl(this.BaseUrl + myaccountsUrl); + var result = new AxeBuilder(this.Driver).Analyze(); + + // then + CheckAccessibilityResult(result); + } + + private static void CheckAccessibilityResult(AxeResult result) + { + // Expect axe violations caused by having an aria-expanded attribute on two + // radio inputs and one checkbox input. + // The targets #course-filter-type-1, #course-filter-type-2 and #EndDate are + // nhs-tested components so ignore this violation. + result.Violations.Should().HaveCount(5); + + var violation = result.Violations[0]; + + violation.Id.Should().Be("landmark-contentinfo-is-top-level"); + violation.Nodes.Should().HaveCount(1); + violation.Nodes[0].Target.Should().HaveCount(1); + violation.Nodes[0].Target[0].Selector.Should().Be("footer > footer"); + } + } +} diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/ConfigurationHelper.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/ConfigurationHelper.cs new file mode 100644 index 000000000..675564e76 --- /dev/null +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/ConfigurationHelper.cs @@ -0,0 +1,26 @@ +// +// Copyright (c) HEE.nhs.uk. +// + +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers +{ + using Microsoft.Extensions.Configuration; + + /// + /// ConfigurationHelper. + /// + public static class ConfigurationHelper + { + /// + /// GetConfiguration. + /// + /// IConfiguration. + public static IConfiguration GetConfiguration() + { + return new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.Development.json") + .Build(); + } + } +} diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/DriverHelper.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/DriverHelper.cs new file mode 100644 index 000000000..b1a23d3fb --- /dev/null +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/DriverHelper.cs @@ -0,0 +1,111 @@ +// +// Copyright (c) HEE.nhs.uk. +// + +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers +{ + using OpenQA.Selenium; + using OpenQA.Selenium.Chrome; + using OpenQA.Selenium.Support.UI; + + /// + /// Driver Helper. + /// + public static class DriverHelper + { + /// + /// Create Headless ChromeDriver. + /// + /// Chrome Driver. + public static ChromeDriver CreateHeadlessChromeDriver() + { + var chromeOptions = new ChromeOptions(); + + // chromeOptions.AddArgument("--headless"); + return new ChromeDriver(chromeOptions); + } + + /// + /// Fill Text Input. + /// + /// WebDriver. + /// inputId. + /// inputText. + public static void FillTextInput(this IWebDriver driver, string inputId, string inputText) + { + var answer = driver.FindElement(By.Id(inputId)); + answer.Clear(); + answer.SendKeys(inputText); + } + + /// + /// ClickButtonByText. + /// + /// WebDriver. + /// text. + public static void ClickButtonByText(this IWebDriver driver, string text) + { + var addButton = driver.FindElement(By.XPath($"//button[.='{text}']")); + addButton.Click(); + } + + /// + /// ClickLinkContainingText. + /// + /// WebDriver. + /// text. + public static void ClickLinkContainingText(this IWebDriver driver, string text) + { + var foundLink = driver.FindElement(By.XPath($"//a[contains(., '{text}')]")); + foundLink.Click(); + } + + /// + /// SelectDropdownItemValue. + /// + /// WebDriver. + /// dropdownId. + /// selectedValue. + public static void SelectDropdownItemValue(this IWebDriver driver, string dropdownId, string selectedValue) + { + var dropdown = new SelectElement(driver.FindElement(By.Id(dropdownId))); + dropdown.SelectByValue(selectedValue); + } + + /// + /// SetCheckboxState. + /// + /// WebDriver. + /// inputId. + /// checkState. + public static void SetCheckboxState(this IWebDriver driver, string inputId, bool checkState) + { + var answer = driver.FindElement(By.Id(inputId)); + if (answer.Selected != checkState) + { + answer.Click(); + } + } + + /// + /// Submit Form. + /// + /// WebDriver. + public static void SubmitForm(this IWebDriver driver) + { + var selectPromptForm = driver.FindElement(By.TagName("form")); + selectPromptForm.Submit(); + } + + /// + /// Select Radio Option By Id. + /// + /// WebDriver. + /// radio Id. + public static void SelectRadioOptionById(this IWebDriver driver, string radioId) + { + var radioInput = driver.FindElement(By.Id(radioId)); + radioInput.Click(); + } + } +} diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs new file mode 100644 index 000000000..31aa5087f --- /dev/null +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs @@ -0,0 +1,54 @@ +// +// Copyright (c) HEE.nhs.uk. +// +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers +{ + using OpenQA.Selenium; + using OpenQA.Selenium.Support.UI; + + /// + /// LoginHelper. + /// + public static class LoginHelper + { + /// + /// Get LogUserInAsAdmin. + /// + /// WebDriver. + /// baseUrl. + /// adminName. + /// adminPassword. + public static void LogUserInAsAdmin(this IWebDriver driver, string baseUrl, string adminName, string adminPassword) + { + driver.Navigate().GoToUrl(baseUrl + "/Login"); + var username = driver.FindElement(By.Id("Username")); + username.SendKeys(adminName); + + var password = driver.FindElement(By.Id("Password")); + password.SendKeys(adminPassword); + + var submitButton = driver.FindElement(By.TagName("form")); + submitButton.Submit(); + } + + /// + /// LogOutUser. + /// + /// WebDriver. + /// baseUrl. + public static void LogOutUser(this IWebDriver driver, string baseUrl) + { + driver.Navigate().GoToUrl(baseUrl); + + // Wait for the element to be present on the page + WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); + IWebElement logoutLink = driver.FindElement(By.XPath("//a[@class='nhsuk-account__login--link' and @href='/Home/Logout']")); + + // Perform an action on the element (e.g., click) + logoutLink.Click(); + + // var submitButton = driver.FindElement(By.TagName("form")); + // submitButton.Submit(); + } + } +} diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/appsettings.json b/LearningHub.Nhs.WebUI.AutomatedUiTests/appsettings.json new file mode 100644 index 000000000..223c0c93f --- /dev/null +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/appsettings.json @@ -0,0 +1,7 @@ +{ + "LearningHubWebUiUrl": "", + "AdminUser": { + "Username": "", + "Password": "" + } +} \ No newline at end of file diff --git a/LearningHub.Nhs.WebUI.sln b/LearningHub.Nhs.WebUI.sln index 9cce69d55..5aea6885f 100644 --- a/LearningHub.Nhs.WebUI.sln +++ b/LearningHub.Nhs.WebUI.sln @@ -79,6 +79,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LearningHub.Nhs.ReportApi.S EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LearningHub.Nhs.ReportApi.Shared", "ReportAPI\LearningHub.Nhs.ReportApi.Shared\LearningHub.Nhs.ReportApi.Shared.csproj", "{6167F037-166C-4C5A-81BE-55618E77D4E8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LearningHub.Nhs.WebUI.AutomatedUiTests", "LearningHub.Nhs.WebUI.AutomatedUiTests\LearningHub.Nhs.WebUI.AutomatedUiTests.csproj", "{A84EC50B-2B01-4819-A2B1-BD867B7595CA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -335,6 +337,14 @@ Global {6167F037-166C-4C5A-81BE-55618E77D4E8}.Release|Any CPU.Build.0 = Release|Any CPU {6167F037-166C-4C5A-81BE-55618E77D4E8}.Release|x64.ActiveCfg = Release|Any CPU {6167F037-166C-4C5A-81BE-55618E77D4E8}.Release|x64.Build.0 = Release|Any CPU + {A84EC50B-2B01-4819-A2B1-BD867B7595CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A84EC50B-2B01-4819-A2B1-BD867B7595CA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A84EC50B-2B01-4819-A2B1-BD867B7595CA}.Debug|x64.ActiveCfg = Debug|Any CPU + {A84EC50B-2B01-4819-A2B1-BD867B7595CA}.Debug|x64.Build.0 = Debug|Any CPU + {A84EC50B-2B01-4819-A2B1-BD867B7595CA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A84EC50B-2B01-4819-A2B1-BD867B7595CA}.Release|Any CPU.Build.0 = Release|Any CPU + {A84EC50B-2B01-4819-A2B1-BD867B7595CA}.Release|x64.ActiveCfg = Release|Any CPU + {A84EC50B-2B01-4819-A2B1-BD867B7595CA}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 21d1a689c8d1a36f98a583d1c85a3ca7b8123a87 Mon Sep 17 00:00:00 2001 From: binon Date: Tue, 27 Feb 2024 12:37:28 +0000 Subject: [PATCH 2/8] Refactored some of the code --- .../AccessibilityTestsBase.cs | 2 +- .../BasicAccessibilityTests.cs | 6 +- .../MyAccountAccessibiltyTests.cs | 21 ++-- .../SeleniumServerFactory.cs | 96 +------------------ .../TestFixtures/AccessibilityTestsFixture.cs | 13 +-- .../AuthenticatedAccessibilityTestsFixture.cs | 5 +- .../TestHelpers/LoginHelper.cs | 42 ++++++-- 7 files changed, 58 insertions(+), 127 deletions(-) rename LearningHub.Nhs.WebUI.AutomatedUiTests/{TestFixtures => AccessibilityTests}/MyAccountAccessibiltyTests.cs (69%) diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs index 2560b4326..28a445e13 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs @@ -35,7 +35,7 @@ public class AccessibilityTestsBase /// Initializes a new instance of the class. /// /// fixture. - public AccessibilityTestsBase(AccessibilityTestsFixture fixture) + public AccessibilityTestsBase(AccessibilityTestsFixture fixture) { this.BaseUrl = fixture.BaseUrl; this.Driver = fixture.Driver; diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs index 37c3da9a6..7a4352353 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs @@ -10,14 +10,14 @@ namespace LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests /// /// BasicAccessibilityTests. /// - public class BasicAccessibilityTests : AccessibilityTestsBase, IClassFixture> + public class BasicAccessibilityTests : AccessibilityTestsBase, IClassFixture { /// /// Initializes a new instance of the class. /// BasicAccessibilityTests. /// /// fixture. - public BasicAccessibilityTests(AccessibilityTestsFixture fixture) + public BasicAccessibilityTests(AccessibilityTestsFixture fixture) : base(fixture) { } @@ -34,6 +34,8 @@ public void PageHasNoAccessibilityErrors(string url, string pageTitle) // then this.AnalyzePageHeadingAndAccessibility(pageTitle); + + this.Driver.Dispose(); } } } diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/MyAccountAccessibiltyTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs similarity index 69% rename from LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/MyAccountAccessibiltyTests.cs rename to LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs index 3d80d035a..530ec67d1 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/MyAccountAccessibiltyTests.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs @@ -2,10 +2,10 @@ // Copyright (c) HEE.nhs.uk. // -namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests { using FluentAssertions; - using LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests; + using LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures; using LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers; using Selenium.Axe; using Xunit; @@ -14,26 +14,26 @@ namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures /// MyAccountAccessibiltyTests. /// public class MyAccountAccessibiltyTests : AccessibilityTestsBase, - IClassFixture> + IClassFixture { /// /// Initializes a new instance of the class. /// MyAccountAccessibiltyTests. /// /// fixture. - public MyAccountAccessibiltyTests(AuthenticatedAccessibilityTestsFixture fixture) + public MyAccountAccessibiltyTests(AuthenticatedAccessibilityTestsFixture fixture) : base(fixture) { } /// - /// MyAccountPageHasNoAccessibilityErrors. + /// MyAccount Page Has Accessibility Errors. /// [Fact] - public void MyAccountPageHasNoAccessibilityErrors() + public void MyAccountPageHasAccessibilityErrors() { // given - // this.Driver.LogUserInAsAdmin(this.BaseUrl); + // this.Driver.LogUserInAsAdmin(this.BaseUrl); const string myaccountsUrl = "/myaccount"; // when @@ -42,14 +42,13 @@ public void MyAccountPageHasNoAccessibilityErrors() // then CheckAccessibilityResult(result); + + this.Driver.LogOutUser(this.BaseUrl); } private static void CheckAccessibilityResult(AxeResult result) { - // Expect axe violations caused by having an aria-expanded attribute on two - // radio inputs and one checkbox input. - // The targets #course-filter-type-1, #course-filter-type-2 and #EndDate are - // nhs-tested components so ignore this violation. + // Expect axe violation result.Violations.Should().HaveCount(5); var violation = result.Violations[0]; diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/SeleniumServerFactory.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/SeleniumServerFactory.cs index e01df94f3..bf1274c84 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/SeleniumServerFactory.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/SeleniumServerFactory.cs @@ -26,113 +26,21 @@ namespace LearningHub.Nhs.WebUI.AutomatedUiTests /// /// SeleniumServerFactory. /// - /// TStartup. - public class SeleniumServerFactory : WebApplicationFactory - where TStartup : class + public class SeleniumServerFactory { /// /// Root Uri. /// #pragma warning disable SA1401 // Fields should be private public string RootUri; -#pragma warning restore SA1401 // Fields should be private - private IWebHost host; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public SeleniumServerFactory() { IConfiguration configuration = ConfigurationHelper.GetConfiguration(); this.RootUri = configuration["LearningHubWebUiUrl"]; - - // We are consuming from IIS express - // this.CreateServer(this.CreateWebHostBuilder()); - // this.CreateClient(); - } - - /// - /// Create Server. - /// - /// builder. - /// TestServer. - protected sealed override TestServer CreateServer(IWebHostBuilder builder) - { - // base.ConfigureWebHost(builder); - - // Real TCP port - var host = builder - .UseStartup() - .UseSerilog() - .ConfigureAppConfiguration(configBuilder => - { - configBuilder.AddConfiguration(GetConfigForUiTests()); - }) - .Build(); - - host.Start(); - var rootUri = host.ServerFeatures.Get().Addresses.First(); - - // Fake Server to satisfy the return type - return new TestServer( - new WebHostBuilder() - .UseStartup() - .UseSerilog() - .ConfigureAppConfiguration( - configBuilder => { configBuilder.AddConfiguration(GetConfigForUiTests()); })); - } - - /// - /// Create Web Host Builder. - /// - /// CreateDefaultBuilder. - protected sealed override IWebHostBuilder CreateWebHostBuilder() - { - return WebHost.CreateDefaultBuilder(Array.Empty()) - .UseStartup() - .UseSerilog() - .UseUrls("http://127.0.0.1:0") - .ConfigureAppConfiguration( - configBuilder => - { - var jsonConfigSources = configBuilder.Sources - .Where(source => source.GetType() == typeof(JsonConfigurationSource)) - .ToList(); - - foreach (var jsonConfigSource in jsonConfigSources) - { - configBuilder.Sources.Remove(jsonConfigSource); - } - - configBuilder.AddConfiguration(GetConfigForUiTests()); - }); - } - - /// - /// Dispose implementation. - /// - /// disposing. - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - if (disposing) - { - this.host?.Dispose(); - } - } - - /// - /// Get Config ForUi Tests. - /// - /// ConfigurationBuilder. - private static IConfigurationRoot GetConfigForUiTests() - { - return new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.Development.json") - .AddEnvironmentVariables("DlsRefactor_") - .AddUserSecrets(typeof(Program).Assembly) - .Build(); } } } diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs index 8238b893d..eac8a6d68 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs @@ -4,17 +4,13 @@ namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures { - using System; - using System.Data.SqlClient; using LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers; using OpenQA.Selenium; /// /// Represents a fixture for accessibility tests. /// - /// The type of the startup class. - public class AccessibilityTestsFixture : IDisposable - where TStartup : class + public class AccessibilityTestsFixture { /// /// Gets the base URL for the tests. @@ -30,14 +26,14 @@ public class AccessibilityTestsFixture : IDisposable internal readonly IWebDriver Driver; #pragma warning restore SA1401 // Fields should be private - private readonly SeleniumServerFactory factory; + private readonly SeleniumServerFactory factory; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public AccessibilityTestsFixture() { - this.factory = new SeleniumServerFactory(); + this.factory = new SeleniumServerFactory(); this.BaseUrl = this.factory.RootUri; this.Driver = DriverHelper.CreateHeadlessChromeDriver(); } @@ -49,7 +45,6 @@ public void Dispose() { this.Driver.Quit(); this.Driver.Dispose(); - this.factory.Dispose(); } } } diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AuthenticatedAccessibilityTestsFixture.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AuthenticatedAccessibilityTestsFixture.cs index 8fc395da5..6cb3a442f 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AuthenticatedAccessibilityTestsFixture.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AuthenticatedAccessibilityTestsFixture.cs @@ -11,11 +11,10 @@ namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures /// AuthenticatedAccessibilityTestsFixture. /// /// TStartup. - public class AuthenticatedAccessibilityTestsFixture : AccessibilityTestsFixture - where TStartup : class + public class AuthenticatedAccessibilityTestsFixture : AccessibilityTestsFixture { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public AuthenticatedAccessibilityTestsFixture() { diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs index 31aa5087f..84846b6d7 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs @@ -40,15 +40,43 @@ public static void LogOutUser(this IWebDriver driver, string baseUrl) { driver.Navigate().GoToUrl(baseUrl); - // Wait for the element to be present on the page - WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); - IWebElement logoutLink = driver.FindElement(By.XPath("//a[@class='nhsuk-account__login--link' and @href='/Home/Logout']")); + try + { + // Maximum time to wait for the element in seconds + int maxWaitTimeInSeconds = 10; - // Perform an action on the element (e.g., click) - logoutLink.Click(); + // Find the element using XPath + IWebElement logoutLink = null; - // var submitButton = driver.FindElement(By.TagName("form")); - // submitButton.Submit(); + for (int i = 0; i < maxWaitTimeInSeconds; i++) + { + try + { + logoutLink = driver.FindElement(By.XPath("//a[@class='nhsuk-account__login--link' and @href='/Home/Logout']")); + if (logoutLink.Displayed) + { + break; // Exit the loop if element is found and displayed + } + } + catch (NoSuchElementException) + { + // Element not found yet, wait for a second and try again + Thread.Sleep(1000); + } + } + + // Check if the element is found and displayed + if (logoutLink != null && logoutLink.Displayed) + { + // Perform an action on the element (e.g., click) + logoutLink.Click(); + } + } + finally + { + // Close the browser window + driver.Quit(); + } } } } From bfc8d58f43795c0c38d85daf1adf41ff5f56a519 Mon Sep 17 00:00:00 2001 From: binon Date: Tue, 27 Feb 2024 14:18:18 +0000 Subject: [PATCH 3/8] Td-2899 Minor updated chrome driver configuration --- .../AccessibilityTests/MyAccountAccessibiltyTests.cs | 2 +- .../TestHelpers/DriverHelper.cs | 2 +- .../TestHelpers/LoginHelper.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs index 530ec67d1..ca2f2127e 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs @@ -33,7 +33,6 @@ public MyAccountAccessibiltyTests(AuthenticatedAccessibilityTestsFixture fixture public void MyAccountPageHasAccessibilityErrors() { // given - // this.Driver.LogUserInAsAdmin(this.BaseUrl); const string myaccountsUrl = "/myaccount"; // when @@ -43,6 +42,7 @@ public void MyAccountPageHasAccessibilityErrors() // then CheckAccessibilityResult(result); + // Dispose driver this.Driver.LogOutUser(this.BaseUrl); } diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/DriverHelper.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/DriverHelper.cs index b1a23d3fb..cf1e771f6 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/DriverHelper.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/DriverHelper.cs @@ -21,7 +21,7 @@ public static ChromeDriver CreateHeadlessChromeDriver() { var chromeOptions = new ChromeOptions(); - // chromeOptions.AddArgument("--headless"); + chromeOptions.AddArgument("--headless"); return new ChromeDriver(chromeOptions); } diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs index 84846b6d7..ebdabb30b 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs @@ -52,7 +52,7 @@ public static void LogOutUser(this IWebDriver driver, string baseUrl) { try { - logoutLink = driver.FindElement(By.XPath("//a[@class='nhsuk-account__login--link' and @href='/Home/Logout']")); + logoutLink = driver.FindElement(By.CssSelector("a.nhsuk-account__login--link[href='/Home/Logout']")); if (logoutLink.Displayed) { break; // Exit the loop if element is found and displayed From 95d550f50dd3bc91ecfba9f0212b87e30d18c3e4 Mon Sep 17 00:00:00 2001 From: binon Date: Wed, 28 Feb 2024 13:13:53 +0000 Subject: [PATCH 4/8] TD-2899, Merged changes from CI, removed copyright and suppressed warning (globally) --- .../AccessibilityTests/AccessibilityTestsBase.cs | 8 -------- .../AccessibilityTests/BasicAccessibilityTests.cs | 8 +------- .../MyAccountAccessibiltyTests.cs | 10 +++------- .../GlobalSuppressions.cs | 13 +++++++++++++ .../SeleniumServerFactory.cs | 7 +------ .../TestFixtures/AccessibilityTestsFixture.cs | 8 -------- .../AuthenticatedAccessibilityTestsFixture.cs | 4 ---- .../TestHelpers/ConfigurationHelper.cs | 6 +----- .../TestHelpers/DriverHelper.cs | 6 +----- .../TestHelpers/LoginHelper.cs | 5 +---- 10 files changed, 21 insertions(+), 54 deletions(-) create mode 100644 LearningHub.Nhs.WebUI.AutomatedUiTests/GlobalSuppressions.cs diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs index 28a445e13..c8409d921 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs @@ -1,7 +1,3 @@ -// -// Copyright (c) HEE.nhs.uk. -// - namespace LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests { using FluentAssertions; @@ -20,16 +16,12 @@ public class AccessibilityTestsBase /// /// Gets the base URL for the tests. /// -#pragma warning disable SA1401 // Fields should be private internal readonly string BaseUrl; -#pragma warning restore SA1401 // Fields should be private /// /// Gets the WebDriver used for the tests. /// -#pragma warning disable SA1401 // Fields should be private internal readonly IWebDriver Driver; -#pragma warning restore SA1401 // Fields should be private /// /// Initializes a new instance of the class. diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs index 7a4352353..eac9ac28a 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs @@ -1,8 +1,4 @@ -// -// Copyright (c) HEE.nhs.uk. -// - -namespace LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests { using LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures; using Xunit; @@ -25,9 +21,7 @@ public BasicAccessibilityTests(AccessibilityTestsFixture fixture) [Theory] [InlineData("/Home/Index", "A platform for learning and sharing resources")] -#pragma warning disable SA1600 // Elements should be documented public void PageHasNoAccessibilityErrors(string url, string pageTitle) -#pragma warning restore SA1600 // Elements should be documented { // when this.Driver.Navigate().GoToUrl(this.BaseUrl + url); diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs index ca2f2127e..7990f0fa8 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs @@ -1,8 +1,4 @@ -// -// Copyright (c) HEE.nhs.uk. -// - -namespace LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests { using FluentAssertions; using LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures; @@ -49,9 +45,9 @@ public void MyAccountPageHasAccessibilityErrors() private static void CheckAccessibilityResult(AxeResult result) { // Expect axe violation - result.Violations.Should().HaveCount(5); + result.Violations.Should().HaveCount(6); - var violation = result.Violations[0]; + var violation = result.Violations[1]; violation.Id.Should().Be("landmark-contentinfo-is-top-level"); violation.Nodes.Should().HaveCount(1); diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/GlobalSuppressions.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/GlobalSuppressions.cs new file mode 100644 index 000000000..01866c145 --- /dev/null +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/GlobalSuppressions.cs @@ -0,0 +1,13 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Allowed", Scope = "member", Target = "~F:LearningHub.Nhs.WebUI.AutomatedUiTests.SeleniumServerFactory.RootUri")] +[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Allowed", Scope = "member", Target = "~F:LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures.AccessibilityTestsFixture.Driver")] +[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Allowed", Scope = "member", Target = "~F:LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures.AccessibilityTestsFixture.BaseUrl")] +[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Allowed", Scope = "member", Target = "~F:LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests.AccessibilityTestsBase.BaseUrl")] +[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Allowed", Scope = "member", Target = "~F:LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests.AccessibilityTestsBase.Driver")] +[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "Regions allowed", Scope = "member", Target = "~M:LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests.BasicAccessibilityTests.PageHasNoAccessibilityErrors(System.String,System.String)")] diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/SeleniumServerFactory.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/SeleniumServerFactory.cs index bf1274c84..19edcdaef 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/SeleniumServerFactory.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/SeleniumServerFactory.cs @@ -1,8 +1,4 @@ -// -// Copyright (c) HEE.nhs.uk. -// - -namespace LearningHub.Nhs.WebUI.AutomatedUiTests +namespace LearningHub.Nhs.WebUI.AutomatedUiTests { using System; using System; @@ -31,7 +27,6 @@ public class SeleniumServerFactory /// /// Root Uri. /// -#pragma warning disable SA1401 // Fields should be private public string RootUri; /// diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs index eac8a6d68..9ad27df2a 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs @@ -1,7 +1,3 @@ -// -// Copyright (c) HEE.nhs.uk. -// - namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures { using LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers; @@ -15,16 +11,12 @@ public class AccessibilityTestsFixture /// /// Gets the base URL for the tests. /// -#pragma warning disable SA1401 // Fields should be private internal readonly string BaseUrl; -#pragma warning restore SA1401 // Fields should be private /// /// Gets the WebDriver used for the tests. /// -#pragma warning disable SA1401 // Fields should be private internal readonly IWebDriver Driver; -#pragma warning restore SA1401 // Fields should be private private readonly SeleniumServerFactory factory; diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AuthenticatedAccessibilityTestsFixture.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AuthenticatedAccessibilityTestsFixture.cs index 6cb3a442f..130e05036 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AuthenticatedAccessibilityTestsFixture.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AuthenticatedAccessibilityTestsFixture.cs @@ -1,7 +1,3 @@ -// -// Copyright (c) HEE.nhs.uk. -// - namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures { using LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers; diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/ConfigurationHelper.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/ConfigurationHelper.cs index 675564e76..660575162 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/ConfigurationHelper.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/ConfigurationHelper.cs @@ -1,8 +1,4 @@ -// -// Copyright (c) HEE.nhs.uk. -// - -namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers { using Microsoft.Extensions.Configuration; diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/DriverHelper.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/DriverHelper.cs index cf1e771f6..9d467b946 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/DriverHelper.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/DriverHelper.cs @@ -1,8 +1,4 @@ -// -// Copyright (c) HEE.nhs.uk. -// - -namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers { using OpenQA.Selenium; using OpenQA.Selenium.Chrome; diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs index ebdabb30b..8f9786d27 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestHelpers/LoginHelper.cs @@ -1,7 +1,4 @@ -// -// Copyright (c) HEE.nhs.uk. -// -namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers { using OpenQA.Selenium; using OpenQA.Selenium.Support.UI; From a598b1ba8fcd078ebb8e3d92b6516ec6e37a232e Mon Sep 17 00:00:00 2001 From: Arunima George Date: Mon, 17 Feb 2025 09:16:47 +0000 Subject: [PATCH 5/8] latest changes --- .../AccessibilityTestsBase.cs | 6 +- .../BasicAccessibilityTests.cs | 8 +- .../BasicAuthenticatedAccessibilityTests.cs | 11 +- .../AccessibilityTests/BookmarksTests.cs | 119 +++---- .../CatalogueFolderContentTests.cs | 2 +- .../AccessibilityTests/CreateAccountTests.cs | 313 ++++++++---------- .../AccessibilityTests/DashboardTests.cs | 2 +- .../MyAccountAccessibiltyTests.cs | 45 +-- .../MyContributionsTests.cs | 45 +++ .../AccessibilityTests/SearchResultsTests.cs | 35 +- ...rningHub.Nhs.WebUI.AutomatedUiTests.csproj | 8 +- .../TestFixtures/AccessibilityTestsFixture.cs | 2 - .../CreateAccountPrimarySpecialty.cshtml | 2 +- ...ateAccountPrimarySpecialtySelection.cshtml | 2 +- .../Views/Bookmark/Move.cshtml | 3 +- .../Views/Bookmark/_BookmarkItem.cshtml | 4 +- .../NavigationItems/Searchbar.cshtml | 2 +- .../Views/Shared/_NavPartial.cshtml | 2 +- 18 files changed, 287 insertions(+), 324 deletions(-) create mode 100644 LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyContributionsTests.cs diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs index 1653555e2..487b29b79 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/AccessibilityTestsBase.cs @@ -44,11 +44,7 @@ public void AnalyzePageHeadingAndAccessibility(string pageTitle) // then // Exclude conditional radios, see: https://github.com/alphagov/govuk-frontend/issues/979#issuecomment-872300557 var axeResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); - axeResult.Violations.Should().BeEmpty(); - - //// var criticalIssues = axeResult.Violations - ////.Where(v => v.Impact == "critical") // Filter for critical issues - ////.ToList(); + axeResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); } /// diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs index c7062a680..b4de53994 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAccessibilityTests.cs @@ -1,6 +1,8 @@ namespace LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests { + using FluentAssertions; using LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures; + using Selenium.Axe; using Xunit; /// @@ -18,8 +20,12 @@ public BasicAccessibilityTests(AccessibilityTestsFixture fixture) { } + /// + /// PageHasNoAccessibilityErrors. + /// + /// url to the page. + /// title of the page. [Theory] - [InlineData("/Home/Index", "Learning Hub - Home")] [InlineData("/forgotten-password", "Forgotten your username or password")] [InlineData("/Login", "Access your Learning Hub account")] diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAuthenticatedAccessibilityTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAuthenticatedAccessibilityTests.cs index 590cf0f08..60261e33a 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAuthenticatedAccessibilityTests.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BasicAuthenticatedAccessibilityTests.cs @@ -28,13 +28,10 @@ public BasicAuthenticatedAccessibilityTests(AuthenticatedAccessibilityTestsFixtu /// url. /// pageTitle. [Theory] - [InlineData("/?myLearningDashboard=my-in-progress&resourceDashboard=popular-resources&catalogueDashboard=popular-catalogues", "Learning Hub - Home")] [InlineData("/myaccount", "My account details")] [InlineData("/MyLearning", "My learning")] [InlineData("/allcatalogue", "A-Z of catalogues")] [InlineData("/allcataloguesearch?term=test#searchTab", "Search results for test")] - [InlineData("/my-contributions", "Community contributions")] - [InlineData("/bookmark", "Bookmarked learning")] [InlineData("/Resource/309/Item", "IE11 Image test")] [InlineData("/Resource/91/Item", "Removal and disposal of Personal Protective Equipment (PPE)")] [InlineData("/Resource/15458/Item", "Test PDF File 16Dec")] @@ -44,18 +41,12 @@ public void AuthenticatedPageHasNoAccessibilityErrors(string url, string pageTit { // when this.Driver.Navigate().GoToUrl(this.BaseUrl + url); - ////string currentUrl = this.Driver.Url; - ////if (currentUrl.Contains("/myaccount")) - ////{ - //// var submitButton = this.Driver.FindElement(By.TagName("form")); - //// submitButton.Submit(); - ////} // then this.AnalyzePageHeadingAndAccessibility(pageTitle); // Dispose driver - this.Driver.LogOutUser(this.BaseUrl); + ////this.Driver.LogOutUser(this.BaseUrl); } } } diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BookmarksTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BookmarksTests.cs index 0a5098aca..b29c1cf46 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BookmarksTests.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/BookmarksTests.cs @@ -28,89 +28,64 @@ public BookmarksTests(AuthenticatedAccessibilityTestsFixture fixture) [Fact] public void BookmarksPageHasNoAccessibilityErrors() { + // given + const string resourceUrl = "/Resource/91/Item"; + const string addBookmarkPageUrl = "/bookmark/resource?bookmarked=False&title=Understanding%20and%20managing%20conflict%20in%20children%27s%20healthcare&rri=16593&returnUrl=%2FResource%2F16593%2FItem"; + const string myBookmarksPage = "/bookmark"; + const string bookmarkname = "Removal and disposal of Personal Protective Equipment (PPE)"; + IWebElement renameBookmarkElement = null; + IWebElement addBookmarkElement = null; + IWebElement moveBookmarkElement = null; + AxeResult addBookmarkPageResult = null; + + // when + this.Driver.Navigate().GoToUrl(this.BaseUrl + resourceUrl); try { - // given - const string resourceUrl = "/Resource/91/Item"; - const string addBookmarkPageUrl = "/bookmark/resource?bookmarked=False&title=Understanding%20and%20managing%20conflict%20in%20children%27s%20healthcare&rri=16593&returnUrl=%2FResource%2F16593%2FItem"; - const string myBookmarksPage = "/bookmark"; - const string bookmarkname = "Removal and disposal of Personal Protective Equipment (PPE)"; - IWebElement renameBookmarkElement = null; - IWebElement addBookmarkElement = null; - IWebElement moveBookmarkElement = null; - AxeResult addBookmarkPageResult = null; - - // when - this.Driver.Navigate().GoToUrl(this.BaseUrl + resourceUrl); - try - { - addBookmarkElement = this.Driver.FindElement(By.XPath("//a[contains(text(),'Add to my bookmarks')]")); - if (addBookmarkElement.Displayed) - { - this.Driver.ClickLinkContainingText("Add to my bookmarks"); - this.ValidatePageHeading("Add bookmark"); - addBookmarkPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); - this.Driver.ClickButtonByText("Continue"); - } - } - catch (NoSuchElementException) + addBookmarkElement = this.Driver.FindElement(By.XPath("//a[contains(text(),'Add to my bookmarks')]")); + if (addBookmarkElement.Displayed) { - this.Driver.Navigate().GoToUrl(this.BaseUrl + addBookmarkPageUrl); + this.Driver.ClickLinkContainingText("Add to my bookmarks"); this.ValidatePageHeading("Add bookmark"); addBookmarkPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); - this.Driver.ClickLinkContainingText("Cancel"); + this.Driver.ClickButtonByText("Continue"); } + } + catch (NoSuchElementException) + { + this.Driver.Navigate().GoToUrl(this.BaseUrl + addBookmarkPageUrl); + this.ValidatePageHeading("Add bookmark"); + addBookmarkPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); + this.Driver.ClickLinkContainingText("Cancel"); + } - ////addBookmarkElement = this.Driver.FindElement(By.XPath("//a[contains(text(),'Add to my bookmarks')]")); - ////if (addBookmarkElement.Displayed) - ////{ - //// this.Driver.ClickLinkContainingText("Add to my bookmarks"); - //// this.ValidatePageHeading("Add bookmark"); - //// addBookmarkPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); - //// this.Driver.ClickButtonByText("Continue"); - ////} - ////else - ////{ - //// this.Driver.Navigate().GoToUrl(this.BaseUrl + addBookmarkPageUrl); - //// this.ValidatePageHeading("Add bookmark"); - //// addBookmarkPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); - //// this.Driver.ClickLinkContainingText("Cancel"); - ////} - - this.Driver.Navigate().GoToUrl(this.BaseUrl + myBookmarksPage); - this.ValidatePageHeading("Bookmarked learning"); - var myBookmarksPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); + this.Driver.Navigate().GoToUrl(this.BaseUrl + myBookmarksPage); + this.ValidatePageHeading("Bookmarked learning"); + var myBookmarksPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); - this.Driver.ClickLinkContainingText("Add a folder"); - this.ValidatePageHeading("Add a folder"); - var addBookmarkFolderPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); - this.Driver.ClickLinkContainingText("Cancel"); + this.Driver.ClickLinkContainingText("Add a folder"); + this.ValidatePageHeading("Add a folder"); + var addBookmarkFolderPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); + this.Driver.ClickLinkContainingText("Cancel"); - renameBookmarkElement = this.Driver.FindElement(By.XPath($"//tr[td//span[contains(text(), '{bookmarkname}')]]//td//div//form//span//button[contains(text(), 'Rename')]")); - renameBookmarkElement.Click(); - this.ValidatePageHeading("Rename bookmark"); - var renameBookmarkPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); - this.Driver.ClickLinkContainingText("Cancel"); + renameBookmarkElement = this.Driver.FindElement(By.XPath($"//tr[td//span[contains(text(), '{bookmarkname}')]]//td//div//form//span//button[contains(text(), 'Rename')]")); + renameBookmarkElement.Click(); + this.ValidatePageHeading("Rename bookmark"); + var renameBookmarkPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); + this.Driver.ClickLinkContainingText("Cancel"); - moveBookmarkElement = this.Driver.FindElement(By.XPath($"//tr[td//span[contains(text(), '{bookmarkname}')]]//td//div//form//span//button[contains(text(), 'Move')]")); - moveBookmarkElement.Click(); - this.ValidatePageHeading("Move your bookmark"); - var moveBookmarkPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); - this.Driver.ClickLinkContainingText("Cancel"); + moveBookmarkElement = this.Driver.FindElement(By.XPath($"//tr[td//span[contains(text(), '{bookmarkname}')]]//td//div//form//span//button[contains(text(), 'Move')]")); + moveBookmarkElement.Click(); + this.ValidatePageHeading("Move your bookmark"); + var moveBookmarkPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); + this.Driver.ClickLinkContainingText("Cancel"); - // then - addBookmarkPageResult.Violations.Should().BeEmpty(); - myBookmarksPageResult.Violations.Should().BeEmpty(); - addBookmarkFolderPageResult.Violations.Should().BeEmpty(); - renameBookmarkPageResult.Violations.Should().BeEmpty(); - moveBookmarkPageResult.Violations.Should().BeEmpty(); - } - finally - { - // Close the browser window - this.Driver.Quit(); - this.Driver.Dispose(); - } + // then + addBookmarkPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + myBookmarksPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + addBookmarkFolderPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + renameBookmarkPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + moveBookmarkPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); } } } diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/CatalogueFolderContentTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/CatalogueFolderContentTests.cs index 7269836b5..76b87944b 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/CatalogueFolderContentTests.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/CatalogueFolderContentTests.cs @@ -40,7 +40,7 @@ public void CatalogueFolderContentPageHasNoAccessibilityErrors() ////var catalogueManagementPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); // then - cataloguePageResult.Violations.Should().BeEmpty(); + cataloguePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); } } } diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/CreateAccountTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/CreateAccountTests.cs index 7289d11e5..da149920a 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/CreateAccountTests.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/CreateAccountTests.cs @@ -28,104 +28,92 @@ public CreateAccountTests(AccessibilityTestsFixture fixture) [Fact] public void CreateFullUserAccountPageHasNoAccessibilityErrors() { - try - { - // given - const string createAccountUrl = "/Registration/CreateAccountRegInfo"; - - // when - this.Driver.Navigate().GoToUrl(this.BaseUrl + createAccountUrl); - this.ValidatePageHeading("What you need to set up an account"); - var accountPageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.ClickButtonByText("Continue"); - ////string currentUrl = this.Driver.Url; - this.Driver.FindElement(By.XPath("//button[normalize-space(text())='Continue']")).Click(); - - // Wait for the URL to change - ////var wait = new WebDriverWait(this.Driver, TimeSpan.FromSeconds(10)); - ////wait.Until(driver => driver.Url != currentUrl); - - // Verify the heading on the new page - this.ValidatePageHeading("Create an account"); - var emailVerificationPageResult = new AxeBuilder(this.Driver).Analyze(); - - this.Driver.FillTextInput("Email", "testuser4@nhs.net"); - this.Driver.FillTextInput("ComfirmEmail", "testuser4@nhs.net"); - this.Driver.SubmitForm(); - - this.ValidatePageHeading("Full User Account"); - this.Driver.SubmitForm(); - - this.ValidatePageHeading("Enter your personal details"); - var personalDetailsPageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.FillTextInput("FirstName", "test"); - this.Driver.FillTextInput("LastName", "user"); - this.Driver.SubmitForm(); - - this.ValidatePageHeading("Search for your country"); - this.Driver.FillTextInput("FilterText", "England"); - this.Driver.SubmitForm(); - var countryPageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.SelectRadioOptionById("CountryId-0"); - this.Driver.ClickButtonByText("Continue"); - - this.ValidatePageHeading("Select your region"); - var regionPageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.SelectRadioOptionById("RegionId-0"); - this.Driver.SubmitForm(); - - this.ValidatePageHeading("Search for your current role"); - this.Driver.FillTextInput("FilterText", "admin"); - this.Driver.SubmitForm(); - var rolePageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.SelectRadioOptionById("CurrentRole-0"); - this.Driver.ClickButtonByText("Continue"); - - this.ValidatePageHeading("Select your grade"); - var gradePageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.SelectRadioOptionById("GradeId-0"); - this.Driver.SubmitForm(); - - this.ValidatePageHeading("Search for your primary specialty"); - var specialityPageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.SelectRadioOptionById("PrimarySpecialtyId-0"); - this.Driver.ClickButtonByText("Continue"); - - this.ValidatePageHeading("Enter your start date"); - var startDatePageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.FillTextInput("Day", "1"); - this.Driver.FillTextInput("Month", "1"); - this.Driver.FillTextInput("Year", "2022"); - this.Driver.SubmitForm(); - - this.ValidatePageHeading("Search for your place of work"); - this.Driver.FillTextInput("FilterText", "london"); - this.Driver.SubmitForm(); - var placeOfWorkPageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.SelectRadioOptionById("LocationId-0"); - this.Driver.ClickButtonByText("Continue"); - - this.ValidatePageHeading("Check your details"); - var summaryPageResult = new AxeBuilder(this.Driver).Analyze(); - - // then - emailVerificationPageResult.Violations.Should().BeEmpty(); - personalDetailsPageResult.Violations.Should().BeEmpty(); - countryPageResult.Violations.Should().BeEmpty(); - regionPageResult.Violations.Should().BeEmpty(); - rolePageResult.Violations.Should().BeEmpty(); - gradePageResult.Violations.Should().BeEmpty(); - specialityPageResult.Violations.Should().BeEmpty(); - startDatePageResult.Violations.Should().BeEmpty(); - placeOfWorkPageResult.Violations.Should().BeEmpty(); - summaryPageResult.Violations.Should().BeEmpty(); - } - finally - { - // Close the browser window - this.Driver.Quit(); - this.Driver.Dispose(); - } + // given + const string createAccountUrl = "/Registration/CreateAccountRegInfo"; + + // when + this.Driver.Navigate().GoToUrl(this.BaseUrl); + this.Driver.ClickLinkContainingText("Create new account"); + this.ValidatePageHeading("What you need to set up an account"); + var accountPageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.ClickButtonByText("Continue"); + this.Driver.FindElement(By.XPath("//button[normalize-space(text())='Continue']")).Click(); + + // Verify the heading on the new page + this.ValidatePageHeading("Create an account"); + var emailVerificationPageResult = new AxeBuilder(this.Driver).Analyze(); + + this.Driver.FillTextInput("Email", "testuser4@nhs.net"); + this.Driver.FillTextInput("ComfirmEmail", "testuser4@nhs.net"); + this.Driver.SubmitForm(); + + this.ValidatePageHeading("Full User Account"); + this.Driver.SubmitForm(); + + this.ValidatePageHeading("Enter your personal details"); + var personalDetailsPageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.FillTextInput("FirstName", "test"); + this.Driver.FillTextInput("LastName", "user"); + this.Driver.SubmitForm(); + + this.ValidatePageHeading("Search for your country"); + this.Driver.FillTextInput("FilterText", "England"); + this.Driver.SubmitForm(); + var countryPageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.SelectRadioOptionById("CountryId-0"); + this.Driver.ClickButtonByText("Continue"); + + this.ValidatePageHeading("Select your region"); + var regionPageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.SelectRadioOptionById("RegionId-0"); + this.Driver.SubmitForm(); + + this.ValidatePageHeading("Search for your current role"); + this.Driver.FillTextInput("FilterText", "admin"); + this.Driver.SubmitForm(); + var rolePageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.SelectRadioOptionById("CurrentRole-0"); + this.Driver.ClickButtonByText("Continue"); + + this.ValidatePageHeading("Select your grade"); + var gradePageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.SelectRadioOptionById("GradeId-0"); + this.Driver.SubmitForm(); + + this.ValidatePageHeading("Search for your primary specialty"); + var specialityPageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.SelectRadioOptionById("PrimarySpecialtyId-0"); + this.Driver.ClickButtonByText("Continue"); + + this.ValidatePageHeading("Enter your start date"); + var startDatePageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.FillTextInput("Day", "1"); + this.Driver.FillTextInput("Month", "1"); + this.Driver.FillTextInput("Year", "2022"); + this.Driver.SubmitForm(); + + this.ValidatePageHeading("Search for your place of work"); + this.Driver.FillTextInput("FilterText", "london"); + this.Driver.SubmitForm(); + var placeOfWorkPageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.SelectRadioOptionById("LocationId-0"); + this.Driver.ClickButtonByText("Continue"); + + this.ValidatePageHeading("Check your details"); + var summaryPageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.Navigate().GoToUrl(this.BaseUrl); + + // then + emailVerificationPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + personalDetailsPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + countryPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + regionPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + rolePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + gradePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + specialityPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + startDatePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + placeOfWorkPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + summaryPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); } /// @@ -134,76 +122,65 @@ public void CreateFullUserAccountPageHasNoAccessibilityErrors() [Fact] public void CreateGeneralUserAccountPageHasNoAccessibilityErrors() { - try - { - // given - const string createAccountUrl = "/Registration/CreateAccountRegInfo"; - - // when - this.Driver.Navigate().GoToUrl(this.BaseUrl + createAccountUrl); - this.ValidatePageHeading("What you need to set up an account"); - var accountPageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.ClickButtonByText("Continue"); - string currentUrl = this.Driver.Url; - this.Driver.FindElement(By.XPath("//button[normalize-space(text())='Continue']")).Click(); - - ////// Wait for the URL to change - ////var wait = new WebDriverWait(this.Driver, TimeSpan.FromSeconds(10)); - ////wait.Until(driver => driver.Url != currentUrl); - - // Verify the heading on the new page - this.ValidatePageHeading("Create an account"); - var emailVerificationPageResult = new AxeBuilder(this.Driver).Analyze(); - - this.Driver.FillTextInput("Email", "testuser4@gmail.com"); - this.Driver.FillTextInput("ComfirmEmail", "testuser4@gmail.com"); - this.Driver.SubmitForm(); - - this.ValidatePageHeading("General User Account"); - this.Driver.SubmitForm(); - - this.ValidatePageHeading("Enter your personal details"); - var personalDetailsPageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.FillTextInput("FirstName", "test"); - this.Driver.FillTextInput("LastName", "user"); - this.Driver.SubmitForm(); - - this.ValidatePageHeading("Search for your country"); - this.Driver.FillTextInput("FilterText", "England"); - this.Driver.SubmitForm(); - var countryPageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.SelectRadioOptionById("CountryId-0"); - this.Driver.ClickButtonByText("Continue"); - - this.ValidatePageHeading("Select your region"); - var regionPageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.SelectRadioOptionById("RegionId-0"); - this.Driver.SubmitForm(); - - this.ValidatePageHeading("Search for your current role"); - this.Driver.FillTextInput("FilterText", "admin"); - this.Driver.SubmitForm(); - var rolePageResult = new AxeBuilder(this.Driver).Analyze(); - this.Driver.SelectRadioOptionById("CurrentRole-0"); - this.Driver.ClickButtonByText("Continue"); - - this.ValidatePageHeading("Check your details"); - var summaryPageResult = new AxeBuilder(this.Driver).Analyze(); - - // then - emailVerificationPageResult.Violations.Should().BeEmpty(); - personalDetailsPageResult.Violations.Should().BeEmpty(); - countryPageResult.Violations.Should().BeEmpty(); - regionPageResult.Violations.Should().BeEmpty(); - rolePageResult.Violations.Should().BeEmpty(); - summaryPageResult.Violations.Should().BeEmpty(); - } - finally - { - // Close the browser window - this.Driver.Quit(); - this.Driver.Dispose(); - } + // given + const string createAccountUrl = "/Registration/CreateAccountRegInfo"; + + // when + this.Driver.Navigate().GoToUrl(this.BaseUrl); + ////this.Driver.Navigate().GoToUrl(this.BaseUrl + createAccountUrl); + this.Driver.ClickLinkContainingText("Create new account"); + this.ValidatePageHeading("What you need to set up an account"); + var accountPageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.ClickButtonByText("Continue"); + this.Driver.FindElement(By.XPath("//button[normalize-space(text())='Continue']")).Click(); + + // Verify the heading on the new page + this.ValidatePageHeading("Create an account"); + var emailVerificationPageResult = new AxeBuilder(this.Driver).Analyze(); + + this.Driver.FillTextInput("Email", "testuser4@gmail.com"); + this.Driver.FillTextInput("ComfirmEmail", "testuser4@gmail.com"); + this.Driver.SubmitForm(); + + this.ValidatePageHeading("General User Account"); + this.Driver.SubmitForm(); + + this.ValidatePageHeading("Enter your personal details"); + var personalDetailsPageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.FillTextInput("FirstName", "test"); + this.Driver.FillTextInput("LastName", "user"); + this.Driver.SubmitForm(); + + this.ValidatePageHeading("Search for your country"); + this.Driver.FillTextInput("FilterText", "England"); + this.Driver.SubmitForm(); + var countryPageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.SelectRadioOptionById("CountryId-0"); + this.Driver.ClickButtonByText("Continue"); + + this.ValidatePageHeading("Select your region"); + var regionPageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.SelectRadioOptionById("RegionId-0"); + this.Driver.SubmitForm(); + + this.ValidatePageHeading("Search for your current role"); + this.Driver.FillTextInput("FilterText", "admin"); + this.Driver.SubmitForm(); + var rolePageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.SelectRadioOptionById("CurrentRole-0"); + this.Driver.ClickButtonByText("Continue"); + + this.ValidatePageHeading("Check your details"); + var summaryPageResult = new AxeBuilder(this.Driver).Analyze(); + this.Driver.Navigate().GoToUrl(this.BaseUrl); + + // then + emailVerificationPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + personalDetailsPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + countryPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + regionPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + rolePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + summaryPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); } } } diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/DashboardTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/DashboardTests.cs index e3c09a4f3..c89ae663f 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/DashboardTests.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/DashboardTests.cs @@ -40,7 +40,7 @@ public void DashboardPageHasNoAccessibilityErrors() private static void CheckAccessibilityResult(AxeResult result) { - result.Violations.Should().BeEmpty(); + result.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); } } } diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs index 8be44d81b..5a2e85d33 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyAccountAccessibiltyTests.cs @@ -30,18 +30,6 @@ public void MyAccountPageHasAccessibilityErrors() { // given const string myaccountsUrl = "/myaccount"; - ////const string changeFirstNameUrl = "/myaccount/ChangeFirstname"; - ////const string changeLastNameUrl = "/myaccount/ChangeLastName"; - ////const string changePreferredNameUrl = "/myaccount/ChangePreferredName"; - ////const string changeCountryUrl = "/myaccount/ChangeCountry"; - ////const string changeSecEmailUrl = "/myaccount/ChangeSecondaryEmail"; - ////const string changeFirstQuestionUrl = "/MyAccount/SecurityQuestionsDetails?questionIndex=0"; - ////const string changeSecQuestionUrl = "/MyAccount/SecurityQuestionsDetails?questionIndex=1"; - ////const string changeCurrentRoleUrl = "/my-account/change-current-role"; - ////const string changeGradeUrl = "/myaccount"; - ////const string changePrimarySpecialityUrl = "/myaccount"; - ////const string changeStartDateUrl = "/myaccount"; - ////const string changePlaceOfWorkUrl = "/my-account/change-work-place"; // when this.Driver.Navigate().GoToUrl(this.BaseUrl + myaccountsUrl); @@ -68,11 +56,6 @@ public void MyAccountPageHasAccessibilityErrors() var countryChangePageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); this.Driver.ClickLinkContainingText("Go back"); - ////this.Driver.ClickLinkContainingText("region"); - ////this.ValidatePageHeading("Update your region"); - ////var regionChangePageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); - ////this.Driver.ClickLinkContainingText("Go back"); - this.Driver.ClickLinkContainingText("secondry email"); this.ValidatePageHeading("Enter your new secondary email address"); var emailChangePageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); @@ -114,24 +97,24 @@ public void MyAccountPageHasAccessibilityErrors() this.Driver.ClickLinkContainingText("Go back"); // then - myAccountPageResult.Violations.Should().BeEmpty(); - firstNameChangePageResult.Violations.Should().BeEmpty(); - lastNameChangePageResult.Violations.Should().BeEmpty(); - preferredNameChangeResult.Violations.Should().BeEmpty(); - countryChangePageResult.Violations.Should().BeEmpty(); + myAccountPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + firstNameChangePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + lastNameChangePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + preferredNameChangeResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + countryChangePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); ////regionChangePageResult.Violations.Should().BeEmpty(); - emailChangePageResult.Violations.Should().BeEmpty(); - securityQuestChangePageResult.Violations.Should().BeEmpty(); - securityQuest2ChangePageResult.Violations.Should().BeEmpty(); - roleChangePageResult.Violations.Should().BeEmpty(); - gradeChangePageResult.Violations.Should().BeEmpty(); - primarySpecialityChangePageResult.Violations.Should().BeEmpty(); - startDateChangePageResult.Violations.Should().BeEmpty(); - placeOfWorkChangePageResult.Violations.Should().BeEmpty(); + emailChangePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + securityQuestChangePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + securityQuest2ChangePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + roleChangePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + gradeChangePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + primarySpecialityChangePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + startDateChangePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + placeOfWorkChangePageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); ////CheckAccessibilityResult(result); // Dispose driver - this.Driver.LogOutUser(this.BaseUrl); + ////this.Driver.LogOutUser(this.BaseUrl); } private static void CheckAccessibilityResult(AxeResult result) diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyContributionsTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyContributionsTests.cs new file mode 100644 index 000000000..85c1bf38f --- /dev/null +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/MyContributionsTests.cs @@ -0,0 +1,45 @@ +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests +{ + using FluentAssertions; + using LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures; + using Selenium.Axe; + using Xunit; + + /// + /// Contributions Tests. + /// + public class MyContributionsTests : AccessibilityTestsBase, + IClassFixture + { + /// + /// Initializes a new instance of the class. + /// + /// fixture. + public MyContributionsTests(AuthenticatedAccessibilityTestsFixture fixture) + : base(fixture) + { + } + + /// + /// MyContributionsPageHasNoAccessibilityErrors. + /// + [Fact] + public void MyContributionsPageHasNoAccessibilityErrors() + { + // given + const string myContributionUrl = "/my-contributions"; + + // when + this.Driver.Navigate().GoToUrl(this.BaseUrl + myContributionUrl); + var axeResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); + + // then + CheckAccessibilityResult(axeResult); + } + + private static void CheckAccessibilityResult(AxeResult result) + { + result.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + } + } +} diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/SearchResultsTests.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/SearchResultsTests.cs index f9d43d405..658e4633e 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/SearchResultsTests.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/AccessibilityTests/SearchResultsTests.cs @@ -26,31 +26,22 @@ public SearchResultsTests(AuthenticatedAccessibilityTestsFixture fixture) [Fact] public void SearchResultPageHasNoAccessibilityErrors() { - try - { - // given - const string searchResultUrl = "/search/results?term=test"; - const string catalogueSearchResultUrl = "/catalogues?term=test"; + // given + const string searchResultUrl = "/search/results?term=test"; + const string catalogueSearchResultUrl = "/catalogues?term=test"; - // when - this.Driver.Navigate().GoToUrl(this.BaseUrl + searchResultUrl); - this.ValidatePageHeading("Search results for test"); - var searchResultPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); + // when + this.Driver.Navigate().GoToUrl(this.BaseUrl + searchResultUrl); + this.ValidatePageHeading("Search results for test"); + var searchResultPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); - this.Driver.Navigate().GoToUrl(this.BaseUrl + catalogueSearchResultUrl); - this.ValidatePageHeading("Search results for test"); - var catalogueSearchResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); + this.Driver.Navigate().GoToUrl(this.BaseUrl + catalogueSearchResultUrl); + this.ValidatePageHeading("Search results for test"); + var catalogueSearchResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); - // then - searchResultPageResult.Violations.Should().BeEmpty(); - catalogueSearchResult.Violations.Should().BeEmpty(); - } - finally - { - // Close the browser window - this.Driver.Quit(); - this.Driver.Dispose(); - } + // then + searchResultPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); + catalogueSearchResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); } } } diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/LearningHub.Nhs.WebUI.AutomatedUiTests.csproj b/LearningHub.Nhs.WebUI.AutomatedUiTests/LearningHub.Nhs.WebUI.AutomatedUiTests.csproj index d3be2dc12..d4f40f3a1 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/LearningHub.Nhs.WebUI.AutomatedUiTests.csproj +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/LearningHub.Nhs.WebUI.AutomatedUiTests.csproj @@ -32,10 +32,10 @@ - - - - + + + + diff --git a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs index c1a0ad566..28eafbe22 100644 --- a/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs +++ b/LearningHub.Nhs.WebUI.AutomatedUiTests/TestFixtures/AccessibilityTestsFixture.cs @@ -29,8 +29,6 @@ public AccessibilityTestsFixture() this.factory = new SeleniumServerFactory(); this.BaseUrl = this.factory.RootUri; this.Driver = DriverHelper.CreateHeadlessChromeDriver(); - ////this.Driver.Manage().Timeouts().PageLoad = TimeSpan.FromMinutes(2); // Adjust as needed - ////this.Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30); // Optional AssertionOptions.FormattingOptions.MaxLines = 500; AssertionOptions.FormattingOptions.MaxDepth = 10; } diff --git a/LearningHub.Nhs.WebUI/Views/Account/CreateAccountPrimarySpecialty.cshtml b/LearningHub.Nhs.WebUI/Views/Account/CreateAccountPrimarySpecialty.cshtml index 0bc9979cf..fb35d21ad 100644 --- a/LearningHub.Nhs.WebUI/Views/Account/CreateAccountPrimarySpecialty.cshtml +++ b/LearningHub.Nhs.WebUI/Views/Account/CreateAccountPrimarySpecialty.cshtml @@ -63,7 +63,7 @@
-
diff --git a/LearningHub.Nhs.WebUI/Views/Account/CreateAccountPrimarySpecialtySelection.cshtml b/LearningHub.Nhs.WebUI/Views/Account/CreateAccountPrimarySpecialtySelection.cshtml index 495df4081..393d5c76a 100644 --- a/LearningHub.Nhs.WebUI/Views/Account/CreateAccountPrimarySpecialtySelection.cshtml +++ b/LearningHub.Nhs.WebUI/Views/Account/CreateAccountPrimarySpecialtySelection.cshtml @@ -145,7 +145,7 @@
-
diff --git a/LearningHub.Nhs.WebUI/Views/Bookmark/Move.cshtml b/LearningHub.Nhs.WebUI/Views/Bookmark/Move.cshtml index 462133de2..10677a0b6 100644 --- a/LearningHub.Nhs.WebUI/Views/Bookmark/Move.cshtml +++ b/LearningHub.Nhs.WebUI/Views/Bookmark/Move.cshtml @@ -52,7 +52,7 @@ }
- +
@@ -72,6 +72,7 @@ required="@(Model.SelectedFolderId == 0)" />
+
@if (Model.Bookmark.ParentId.HasValue || (Model.Folders != null && Model.Folders.Any())) { diff --git a/LearningHub.Nhs.WebUI/Views/Bookmark/_BookmarkItem.cshtml b/LearningHub.Nhs.WebUI/Views/Bookmark/_BookmarkItem.cshtml index d3698d691..19d19e07a 100644 --- a/LearningHub.Nhs.WebUI/Views/Bookmark/_BookmarkItem.cshtml +++ b/LearningHub.Nhs.WebUI/Views/Bookmark/_BookmarkItem.cshtml @@ -24,11 +24,11 @@ @Model.Bookmark.Title - + Type @GetResourceTypeName(Model.Bookmark.BookmarkTypeId, Model.Bookmark.ResourceTypeId) - + Organise diff --git a/LearningHub.Nhs.WebUI/Views/Shared/Components/NavigationItems/Searchbar.cshtml b/LearningHub.Nhs.WebUI/Views/Shared/Components/NavigationItems/Searchbar.cshtml index 2a2bbb281..bb4e7f8b0 100644 --- a/LearningHub.Nhs.WebUI/Views/Shared/Components/NavigationItems/Searchbar.cshtml +++ b/LearningHub.Nhs.WebUI/Views/Shared/Components/NavigationItems/Searchbar.cshtml @@ -9,7 +9,7 @@
@if (Model.ShowSearch) { - + } @if (User.Identity.IsAuthenticated) { - +