From 014728ef7e86205799a5d4a5a092b0b0c30cdce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 16 Sep 2023 13:36:07 +0200 Subject: [PATCH 01/11] Update all NuGet dependencies. --- .../Lombiq.Tests.UI.Samples.csproj | 4 ++-- Lombiq.Tests.UI/Lombiq.Tests.UI.csproj | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Lombiq.Tests.UI.Samples/Lombiq.Tests.UI.Samples.csproj b/Lombiq.Tests.UI.Samples/Lombiq.Tests.UI.Samples.csproj index 9f3b8b9a1..f9f6942ea 100644 --- a/Lombiq.Tests.UI.Samples/Lombiq.Tests.UI.Samples.csproj +++ b/Lombiq.Tests.UI.Samples/Lombiq.Tests.UI.Samples.csproj @@ -23,8 +23,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Lombiq.Tests.UI/Lombiq.Tests.UI.csproj b/Lombiq.Tests.UI/Lombiq.Tests.UI.csproj index 66906553f..61bd65ca6 100644 --- a/Lombiq.Tests.UI/Lombiq.Tests.UI.csproj +++ b/Lombiq.Tests.UI/Lombiq.Tests.UI.csproj @@ -51,14 +51,14 @@ - + - + - - + + - + @@ -68,12 +68,12 @@ - + - + From 65a8d3eb0782ef29bac1a3632678b73d3ff875a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 16 Sep 2023 18:23:28 +0200 Subject: [PATCH 02/11] Resolving analyzer warning. --- Lombiq.Tests.UI/Models/SafeWaitAsync.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.Tests.UI/Models/SafeWaitAsync.cs b/Lombiq.Tests.UI/Models/SafeWaitAsync.cs index 46fc061c7..64ef92e11 100644 --- a/Lombiq.Tests.UI/Models/SafeWaitAsync.cs +++ b/Lombiq.Tests.UI/Models/SafeWaitAsync.cs @@ -132,7 +132,7 @@ protected virtual bool DoesConditionResultSatisfy(TResult result) { if (typeof(TResult) == typeof(bool)) { - if (result is true) return true; + if (result.Equals(true)) return true; } else if (!Equals(result, default(TResult)) && (result is not IEnumerable enumerable || enumerable.Cast().Any())) From 0f963da93d18aae236986a8e6769e93dc079b359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 16 Sep 2023 18:35:35 +0200 Subject: [PATCH 03/11] Resolving analyzer warning. --- Lombiq.Tests.UI/Services/AtataFactory.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lombiq.Tests.UI/Services/AtataFactory.cs b/Lombiq.Tests.UI/Services/AtataFactory.cs index 7acdd04c9..7e174b197 100644 --- a/Lombiq.Tests.UI/Services/AtataFactory.cs +++ b/Lombiq.Tests.UI/Services/AtataFactory.cs @@ -32,10 +32,7 @@ public static async Task StartAtataScopeAsync( var browserConfiguration = configuration.BrowserConfiguration; var builder = AtataContext.Configure() - // The drivers are disposed when disposing AtataScope. -#pragma warning disable CA2000 // Dispose objects before losing scope .UseDriver(await CreateDriverAsync(browserConfiguration, timeoutConfiguration, testOutputHelper)) -#pragma warning restore CA2000 // Dispose objects before losing scope .UseBaseUrl(baseUri.ToString()) .UseCulture(browserConfiguration.AcceptLanguage.ToString()) .UseTestName(configuration.AtataConfiguration.TestName) @@ -92,10 +89,13 @@ Task FromAsync(Func> factory) } catch (WebDriverException ex) { + // This warning seems to be a false positive as there is nothing that indicates its validity. +#pragma warning disable S2589 // Boolean expressions should not be gratuitous if (!ex.Message.ContainsOrdinalIgnoreCase("Cannot start the driver service on") || currentTry >= maxTryCount) { throw; } +#pragma warning restore S2589 // Boolean expressions should not be gratuitous currentTry++; var retryCount = maxTryCount - currentTry; From 1c24c0fc96529e0c91f8a2f36504f72a6fbd3125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 16 Sep 2023 18:48:51 +0200 Subject: [PATCH 04/11] Resolving analyzer warning. --- Lombiq.Tests.UI/Services/UITestExecutionSession.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.Tests.UI/Services/UITestExecutionSession.cs b/Lombiq.Tests.UI/Services/UITestExecutionSession.cs index 48199cdef..c66926f65 100644 --- a/Lombiq.Tests.UI/Services/UITestExecutionSession.cs +++ b/Lombiq.Tests.UI/Services/UITestExecutionSession.cs @@ -205,7 +205,7 @@ private Exception PrepareAndLogException(Exception ex) else if (_context?.Driver is not null) { _testOutputHelper.WriteLineTimestampedAndDebug( - $"An exception has occurred while interacting with the page {_context?.GetPageTitleAndAddress()}."); + $"An exception has occurred while interacting with the page {_context.GetPageTitleAndAddress()}."); } _testOutputHelper.WriteLineTimestampedAndDebug($"The test failed with the following exception: {ex}"); From ffc59432ee1d1354d7ea8f6054cea376ab50002a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 16 Sep 2023 18:54:54 +0200 Subject: [PATCH 05/11] Resolving analyzer warning. --- Lombiq.Tests.UI/OrchardCoreUITestBase.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lombiq.Tests.UI/OrchardCoreUITestBase.cs b/Lombiq.Tests.UI/OrchardCoreUITestBase.cs index 145d9e8fc..cf260eb32 100644 --- a/Lombiq.Tests.UI/OrchardCoreUITestBase.cs +++ b/Lombiq.Tests.UI/OrchardCoreUITestBase.cs @@ -263,7 +263,10 @@ protected virtual async Task ExecuteTestAsync( finally { _testOutputHelper = originalTestOutputHelper; + // This warning is a false positive as it is not considering the evaluation of the if statement above. +#pragma warning disable S2583 // Conditionally executed code should be reachable afterTest?.Invoke(); +#pragma warning restore S2583 // Conditionally executed code should be reachable } } } From bcb787d36b2bd70e6bc39320dab42585384bfcd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 16 Sep 2023 19:56:20 +0200 Subject: [PATCH 06/11] Resolving analyzer warning. --- .../Extensions/IWebApplicationInstanceExtensions.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lombiq.Tests.UI/Extensions/IWebApplicationInstanceExtensions.cs b/Lombiq.Tests.UI/Extensions/IWebApplicationInstanceExtensions.cs index ee5a98876..7e3642bff 100644 --- a/Lombiq.Tests.UI/Extensions/IWebApplicationInstanceExtensions.cs +++ b/Lombiq.Tests.UI/Extensions/IWebApplicationInstanceExtensions.cs @@ -50,7 +50,10 @@ public static async Task UsingScopeAsync( httpContextAccessor.HttpContext = shellScope.ShellContext.CreateHttpContext(); var httpContext = httpContextAccessor.HttpContext; + // Seems to be a false positive warning. IDE thinks that left hand side can't be null. +#pragma warning disable S2583 // Conditionally executed code should be reachable httpContext.Request.PathBase = "/" + shellHost.GetSettings(tenant).RequestUrlPrefix ?? string.Empty; +#pragma warning restore S2583 // Conditionally executed code should be reachable httpContext.Features.Set(new RecipeEnvironmentFeature()); await shellScope.UsingAsync(execute, activateShell); From 53894ddc1d86f0c4bf9e231badcdd431636c8634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 23 Sep 2023 12:22:09 +0200 Subject: [PATCH 07/11] Removing ?? string.Empty as it is redundant. --- .../Extensions/IWebApplicationInstanceExtensions.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Lombiq.Tests.UI/Extensions/IWebApplicationInstanceExtensions.cs b/Lombiq.Tests.UI/Extensions/IWebApplicationInstanceExtensions.cs index 7e3642bff..5ab63efe5 100644 --- a/Lombiq.Tests.UI/Extensions/IWebApplicationInstanceExtensions.cs +++ b/Lombiq.Tests.UI/Extensions/IWebApplicationInstanceExtensions.cs @@ -49,11 +49,7 @@ public static async Task UsingScopeAsync( // Creating a fake HttpContext like in ModularBackgroundService. httpContextAccessor.HttpContext = shellScope.ShellContext.CreateHttpContext(); var httpContext = httpContextAccessor.HttpContext; - - // Seems to be a false positive warning. IDE thinks that left hand side can't be null. -#pragma warning disable S2583 // Conditionally executed code should be reachable - httpContext.Request.PathBase = "/" + shellHost.GetSettings(tenant).RequestUrlPrefix ?? string.Empty; -#pragma warning restore S2583 // Conditionally executed code should be reachable + httpContext.Request.PathBase = "/" + shellHost.GetSettings(tenant).RequestUrlPrefix; httpContext.Features.Set(new RecipeEnvironmentFeature()); await shellScope.UsingAsync(execute, activateShell); From 2117eb30e613868a59d6a3ad4d99298104549b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 23 Sep 2023 12:34:33 +0200 Subject: [PATCH 08/11] Removing suppress an reordering code. --- Lombiq.Tests.UI/Services/AtataFactory.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Lombiq.Tests.UI/Services/AtataFactory.cs b/Lombiq.Tests.UI/Services/AtataFactory.cs index 7e174b197..49b273406 100644 --- a/Lombiq.Tests.UI/Services/AtataFactory.cs +++ b/Lombiq.Tests.UI/Services/AtataFactory.cs @@ -89,16 +89,13 @@ Task FromAsync(Func> factory) } catch (WebDriverException ex) { - // This warning seems to be a false positive as there is nothing that indicates its validity. -#pragma warning disable S2589 // Boolean expressions should not be gratuitous + currentTry++; + var retryCount = maxTryCount - currentTry; + if (!ex.Message.ContainsOrdinalIgnoreCase("Cannot start the driver service on") || currentTry >= maxTryCount) { throw; } -#pragma warning restore S2589 // Boolean expressions should not be gratuitous - - currentTry++; - var retryCount = maxTryCount - currentTry; // Not using parameters because the exception can throw off the string format. testOutputHelper.WriteLineTimestampedAndDebug( From 57066b57e8c278d6d6a29d666d878d09c1f10029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 23 Sep 2023 12:35:32 +0200 Subject: [PATCH 09/11] Using is operator. --- Lombiq.Tests.UI/Models/SafeWaitAsync.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lombiq.Tests.UI/Models/SafeWaitAsync.cs b/Lombiq.Tests.UI/Models/SafeWaitAsync.cs index 64ef92e11..c865cbcdc 100644 --- a/Lombiq.Tests.UI/Models/SafeWaitAsync.cs +++ b/Lombiq.Tests.UI/Models/SafeWaitAsync.cs @@ -130,9 +130,9 @@ public async Task UntilAsync(Func> condition) protected virtual bool DoesConditionResultSatisfy(TResult result) { - if (typeof(TResult) == typeof(bool)) + if (result is bool resultBool) { - if (result.Equals(true)) return true; + if (resultBool) return true; } else if (!Equals(result, default(TResult)) && (result is not IEnumerable enumerable || enumerable.Cast().Any())) From 42f06de94864c0a02850420ac92f941fc8765cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 23 Sep 2023 12:36:21 +0200 Subject: [PATCH 10/11] Adjusting initial value. --- Lombiq.Tests.UI/Services/AtataFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.Tests.UI/Services/AtataFactory.cs b/Lombiq.Tests.UI/Services/AtataFactory.cs index 49b273406..a2c679873 100644 --- a/Lombiq.Tests.UI/Services/AtataFactory.cs +++ b/Lombiq.Tests.UI/Services/AtataFactory.cs @@ -66,7 +66,7 @@ Task FromAsync(Func> factory) // Driver creation can fail with "Cannot start the driver service on http://localhost:56686/" exceptions if the // machine is under load. Retrying it here so not the whole test needs to be re-run. const int maxTryCount = 3; - var currentTry = 1; + var currentTry = 0; // Force headless mode if we are in Linux without a working graphical environment. if (!browserConfiguration.Headless && RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) From c883246f3504b83462596d9123541d33140638e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 23 Sep 2023 12:50:09 +0200 Subject: [PATCH 11/11] Fix. --- Lombiq.Tests.UI/Services/AtataFactory.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lombiq.Tests.UI/Services/AtataFactory.cs b/Lombiq.Tests.UI/Services/AtataFactory.cs index a2c679873..2cf23f84b 100644 --- a/Lombiq.Tests.UI/Services/AtataFactory.cs +++ b/Lombiq.Tests.UI/Services/AtataFactory.cs @@ -66,7 +66,7 @@ Task FromAsync(Func> factory) // Driver creation can fail with "Cannot start the driver service on http://localhost:56686/" exceptions if the // machine is under load. Retrying it here so not the whole test needs to be re-run. const int maxTryCount = 3; - var currentTry = 0; + var currentTry = 1; // Force headless mode if we are in Linux without a working graphical environment. if (!browserConfiguration.Headless && RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) @@ -92,7 +92,7 @@ Task FromAsync(Func> factory) currentTry++; var retryCount = maxTryCount - currentTry; - if (!ex.Message.ContainsOrdinalIgnoreCase("Cannot start the driver service on") || currentTry >= maxTryCount) + if (!ex.Message.ContainsOrdinalIgnoreCase("Cannot start the driver service on") || retryCount <= 0) { throw; }