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/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/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 c5a11682..bb78ea33 100644 --- a/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLoginSteps.cs +++ b/SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLoginSteps.cs @@ -53,31 +53,37 @@ 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")] - 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")] 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"); }); @@ -165,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."); + }); } } @@ -184,16 +189,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(); @@ -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,