|
| 1 | +namespace LearningHub.Nhs.WebUI.AutomatedUiTests.AccessibilityTests |
| 2 | +{ |
| 3 | + using FluentAssertions; |
| 4 | + using LearningHub.Nhs.WebUI.AutomatedUiTests.TestFixtures; |
| 5 | + using LearningHub.Nhs.WebUI.AutomatedUiTests.TestHelpers; |
| 6 | + using Microsoft.AspNetCore.Components.Web; |
| 7 | + using OpenQA.Selenium; |
| 8 | + using Selenium.Axe; |
| 9 | + using Xunit; |
| 10 | + |
| 11 | + /// <summary> |
| 12 | + /// Bookmarks Tests. |
| 13 | + /// </summary> |
| 14 | + public class BookmarksTests : AccessibilityTestsBase, |
| 15 | + IClassFixture<AuthenticatedAccessibilityTestsFixture> |
| 16 | + { |
| 17 | + /// <summary> |
| 18 | + /// Initializes a new instance of the <see cref="BookmarksTests"/> class. |
| 19 | + /// </summary> |
| 20 | + /// <param name="fixture">fixture.</param> |
| 21 | + public BookmarksTests(AuthenticatedAccessibilityTestsFixture fixture) |
| 22 | + : base(fixture) |
| 23 | + { |
| 24 | + } |
| 25 | + |
| 26 | + /// <summary> |
| 27 | + /// BookmarksPageHasNoAccessibilityErrors. |
| 28 | + /// </summary> |
| 29 | + [Fact] |
| 30 | + public void BookmarksPageHasNoAccessibilityErrors() |
| 31 | + { |
| 32 | + // given |
| 33 | + const string resourceUrl = "/Resource/17844/Item"; |
| 34 | + const string resourceProdUrl = "/Resource/48180/Item"; |
| 35 | + const string addBookmarkPageUrl = "/bookmark/resource?bookmarked=False&title=Understanding%20and%20managing%20conflict%20in%20children%27s%20healthcare&rri=16593&returnUrl=%2FResource%2F16593%2FItem"; |
| 36 | + const string myBookmarksPage = "/bookmark"; |
| 37 | + const string bookmarkname = "Primary care clinicians"; |
| 38 | + IWebElement renameBookmarkElement = null; |
| 39 | + IWebElement addBookmarkElement = null; |
| 40 | + IWebElement moveBookmarkElement = null; |
| 41 | + AxeResult addBookmarkPageResult = null; |
| 42 | + |
| 43 | + // when |
| 44 | + this.Driver.Navigate().GoToUrl(this.BaseUrl + resourceProdUrl); |
| 45 | + |
| 46 | + var h1Element = this.Driver.FindElement(By.TagName("h1")); |
| 47 | + if (h1Element.Text == "Unknown error" || h1Element.Text != bookmarkname) |
| 48 | + { |
| 49 | + this.Driver.Navigate().GoToUrl(this.BaseUrl + resourceUrl); |
| 50 | + } |
| 51 | + |
| 52 | + try |
| 53 | + { |
| 54 | + addBookmarkElement = this.Driver.FindElement(By.XPath("//a[contains(text(),'Add to my bookmarks')]")); |
| 55 | + if (addBookmarkElement.Displayed) |
| 56 | + { |
| 57 | + this.Driver.ClickLinkContainingText("Add to my bookmarks"); |
| 58 | + this.ValidatePageHeading("Add bookmark"); |
| 59 | + addBookmarkPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); |
| 60 | + this.Driver.ClickButtonByText("Continue"); |
| 61 | + } |
| 62 | + } |
| 63 | + catch (NoSuchElementException) |
| 64 | + { |
| 65 | + this.Driver.Navigate().GoToUrl(this.BaseUrl + addBookmarkPageUrl); |
| 66 | + this.ValidatePageHeading("Add bookmark"); |
| 67 | + addBookmarkPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); |
| 68 | + this.Driver.ClickLinkContainingText("Cancel"); |
| 69 | + } |
| 70 | + |
| 71 | + this.Driver.Navigate().GoToUrl(this.BaseUrl + myBookmarksPage); |
| 72 | + this.ValidatePageHeading("Bookmarked learning"); |
| 73 | + var myBookmarksPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); |
| 74 | + |
| 75 | + this.Driver.ClickLinkContainingText("Add a folder"); |
| 76 | + this.ValidatePageHeading("Add a folder"); |
| 77 | + var addBookmarkFolderPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); |
| 78 | + this.Driver.ClickLinkContainingText("Cancel"); |
| 79 | + |
| 80 | + renameBookmarkElement = this.Driver.FindElement(By.XPath($"//tr[td//span[contains(text(), '{bookmarkname}')]]//td//div//form//span//button[contains(text(), 'Rename')]")); |
| 81 | + renameBookmarkElement.Click(); |
| 82 | + this.ValidatePageHeading("Rename bookmark"); |
| 83 | + var renameBookmarkPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); |
| 84 | + this.Driver.ClickLinkContainingText("Cancel"); |
| 85 | + |
| 86 | + moveBookmarkElement = this.Driver.FindElement(By.XPath($"//tr[td//span[contains(text(), '{bookmarkname}')]]//td//div//form//span//button[contains(text(), 'Move')]")); |
| 87 | + moveBookmarkElement.Click(); |
| 88 | + this.ValidatePageHeading("Move your bookmark"); |
| 89 | + var moveBookmarkPageResult = new AxeBuilder(this.Driver).Exclude("div.nhsuk-radios--conditional div.nhsuk-radios__item input.nhsuk-radios__input").Analyze(); |
| 90 | + this.Driver.ClickLinkContainingText("Cancel"); |
| 91 | + |
| 92 | + // then |
| 93 | + addBookmarkPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); |
| 94 | + myBookmarksPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); |
| 95 | + addBookmarkFolderPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); |
| 96 | + renameBookmarkPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); |
| 97 | + moveBookmarkPageResult.Violations.Where(v => !v.Tags.Contains("best-practice")).Should().BeEmpty(); |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments