From 722135228c7757da4ffea141a97be64c3264acba Mon Sep 17 00:00:00 2001 From: StuartFerguson Date: Thu, 25 Jun 2026 08:38:35 +0100 Subject: [PATCH 1/2] attempt to fix chrome driver tests --- .../Common/Hooks.cs | 7 +++-- .../UserLogin/UserLoginSteps.cs | 28 +++++++++---------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/SecurityService.OpenIdConnect.IntegrationTests/Common/Hooks.cs b/SecurityService.OpenIdConnect.IntegrationTests/Common/Hooks.cs index aa76cbf9..ee9dd77b 100644 --- a/SecurityService.OpenIdConnect.IntegrationTests/Common/Hooks.cs +++ b/SecurityService.OpenIdConnect.IntegrationTests/Common/Hooks.cs @@ -71,14 +71,17 @@ public async Task BeforeScenario() { ChromeOptions options = new ChromeOptions(); options.AddArguments("--disable-gpu"); - options.AddArguments("--headless"); + options.AddArguments("--headless=new"); options.AddArguments("--no-sandbox"); options.AddArguments("--disable-dev-shm-usage"); options.AddArguments("disable-infobars"); options.AddArguments("--disable-extensions"); options.AddArguments("--window-size=1280x1024"); options.AcceptInsecureCertificates = true; - this.WebDriver = new ChromeDriver(options); + await Retry.For(async () => + { + this.WebDriver = new ChromeDriver(options); + }, TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(60)); this.WebDriver.Manage().Window.Maximize(); } diff --git a/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLoginSteps.cs b/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLoginSteps.cs index c5a11682..b935f968 100644 --- a/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLoginSteps.cs +++ b/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLoginSteps.cs @@ -53,10 +53,13 @@ public UserLoginSteps(TestingContext testingContext, #endregion [Given(@"I am on the application home page")] - public void GivenIAmOnTheApplicationHomePage() + public async Task GivenIAmOnTheApplicationHomePage() { this.WebDriver.Navigate().GoToUrl($"https://localhost:{this.TestingContext.DockerHelper.SecurityServiceTestUIPort}"); - this.WebDriver.Title.ShouldBe("Home Page - SecurityServiceTestUI"); + await Retry.For(async () => + { + this.WebDriver.Title.ShouldBe("Home Page - SecurityServiceTestUI"); + }); } [When(@"I click the '(.*)' link")] @@ -68,16 +71,19 @@ public void WhenIClickTheLink(string linkText) [Then(@"I am presented with a login screen")] public async Task ThenIAmPresentedWithALoginScreen() { - IWebElement loginButton = await this.WebDriver.FindButton("Login"); - loginButton.ShouldNotBeNull(); + await Retry.For(async () => + { + IWebElement loginButton = await this.WebDriver.FindButton("Login"); + loginButton.ShouldNotBeNull(); + }); } [When(@"I login with the username '([^']*)' and the provided password")] - public void WhenILoginWithTheUsernameAndTheProvidedPassword(string userName) + public async Task WhenILoginWithTheUsernameAndTheProvidedPassword(string userName) { this.WebDriver.FillIn("Input.Username", userName); this.WebDriver.FillIn("Input.Password", this.TestingContext.Password); - this.WebDriver.ClickButton("Login"); + await this.WebDriver.ClickButton("Login"); } @@ -87,10 +93,6 @@ public async Task ThenIAmPresentedWithThePrivacyScreen() { await Retry.For(async () => { - var page = this.WebDriver.PageSource; - - Console.WriteLine($"Source Is [{page}"); - this.WebDriver.Title.ShouldBe("Privacy Policy - SecurityServiceTestUI"); }); @@ -184,16 +186,14 @@ public static void FillIn(this IWebDriver webDriver, } public static async Task FindButton(this IWebDriver webDriver, - String buttonText) + String buttonText) { IWebElement e = null; await Retry.For(async () => { - - ReadOnlyCollection elements = webDriver.FindElements(By.TagName("button")); - var foundElements = elements.Where(e => e.GetAttribute("innerText") == buttonText).ToList(); + var foundElements = elements.Where(element => element.Text.Trim() == buttonText).ToList(); foundElements.ShouldHaveSingleItem(); e = foundElements.Single(); From 4ca683711a1d91a44e85571e7f25bd7cf56d745c Mon Sep 17 00:00:00 2001 From: StuartFerguson Date: Thu, 25 Jun 2026 09:11:15 +0100 Subject: [PATCH 2/2] hopefully fix failing tests --- .../ChangePassword/ChangePasswordSteps.cs | 8 ++++-- .../ForgotPassword/ForgotPasswordSteps.cs | 2 +- .../UserLogin/UserLoginSteps.cs | 26 ++++++++++++------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/SecurityService.OpenIdConnect.IntegrationTests/ChangePassword/ChangePasswordSteps.cs b/SecurityService.OpenIdConnect.IntegrationTests/ChangePassword/ChangePasswordSteps.cs index 80ad2e7d..25a059a6 100644 --- a/SecurityService.OpenIdConnect.IntegrationTests/ChangePassword/ChangePasswordSteps.cs +++ b/SecurityService.OpenIdConnect.IntegrationTests/ChangePassword/ChangePasswordSteps.cs @@ -10,6 +10,7 @@ namespace SecurityService.OpenIdConnect.IntegrationTests.ChangePassword using OpenQA.Selenium; using Reqnroll; using SecurityService.IntegrationTests.UserLogin; + using Shared.IntegrationTesting; using Shouldly; [Binding] @@ -75,9 +76,12 @@ public async Task WhenIClickTheChangePasswordButton() } [Then(@"I am returned to the application home page")] - public void ThenIAmReturnedToTheApplicationHomePage() + public async Task ThenIAmReturnedToTheApplicationHomePage() { - this.WebDriver.Title.ShouldBe("Home Page - SecurityServiceTestUI"); + await Retry.For(async () => + { + this.WebDriver.Title.ShouldBe("Home Page - SecurityServiceTestUI"); + }); } } diff --git a/SecurityService.OpenIdConnect.IntegrationTests/ForgotPassword/ForgotPasswordSteps.cs b/SecurityService.OpenIdConnect.IntegrationTests/ForgotPassword/ForgotPasswordSteps.cs index 7de23f0f..8cfe7e3e 100644 --- a/SecurityService.OpenIdConnect.IntegrationTests/ForgotPassword/ForgotPasswordSteps.cs +++ b/SecurityService.OpenIdConnect.IntegrationTests/ForgotPassword/ForgotPasswordSteps.cs @@ -115,8 +115,8 @@ public async Task ThenIAmPresentedWithTheResetPasswordScreen() [Then("I am presented with the reset password request sent screen")] public async Task ThenIAmPresentedWithTheResetPasswordRequestSentScreen() { - IWebElement resetPasswordLabel = this.WebDriver.FindElement(By.Id("forgotPasswordMessage")); await Retry.For(async () => { + IWebElement resetPasswordLabel = this.WebDriver.FindElement(By.Id("forgotPasswordMessage")); resetPasswordLabel.ShouldNotBeNull(); }); } diff --git a/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLoginSteps.cs b/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLoginSteps.cs index b935f968..bb78ea33 100644 --- a/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLoginSteps.cs +++ b/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLoginSteps.cs @@ -63,9 +63,9 @@ await Retry.For(async () => } [When(@"I click the '(.*)' link")] - public void WhenIClickTheLink(string linkText) + public async Task WhenIClickTheLink(string linkText) { - this.WebDriver.ClickLink(linkText); + await this.WebDriver.ClickLink(linkText); } [Then(@"I am presented with a login screen")] @@ -167,9 +167,12 @@ public void WhenINavigateToTheConfirmEmailAddress() { } [Then(@"I am presented with the confirm email address successful screen")] - public void ThenIAmPresentedWithTheConfirmEmailAddressSuccessfulScreen() { - IWebElement webElement = this.WebDriver.FindElement(By.Id("userMessage")); - webElement.Text.ShouldBe("Thanks for confirming your email address, you should receive a welcome email soon."); + public async Task ThenIAmPresentedWithTheConfirmEmailAddressSuccessfulScreen() { + await Retry.For(async () => + { + IWebElement webElement = this.WebDriver.FindElement(By.Id("userMessage")); + webElement.Text.ShouldBe("Thanks for confirming your email address, you should receive a welcome email soon."); + }); } } @@ -202,12 +205,15 @@ await Retry.For(async () => return e; } - public static void ClickLink(this IWebDriver webDriver, - String linkText) + public static async Task ClickLink(this IWebDriver webDriver, + String linkText) { - IWebElement webElement = webDriver.FindElement(By.LinkText(linkText)); - webElement.ShouldNotBeNull(); - webElement.Click(); + await Retry.For(async () => + { + IWebElement webElement = webDriver.FindElement(By.LinkText(linkText)); + webElement.ShouldNotBeNull(); + webElement.Click(); + }); } public static async Task ClickButton(this IWebDriver webDriver,