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/Extensions/IWebApplicationInstanceExtensions.cs b/Lombiq.Tests.UI/Extensions/IWebApplicationInstanceExtensions.cs index ee5a98876..5ab63efe5 100644 --- a/Lombiq.Tests.UI/Extensions/IWebApplicationInstanceExtensions.cs +++ b/Lombiq.Tests.UI/Extensions/IWebApplicationInstanceExtensions.cs @@ -49,8 +49,7 @@ public static async Task UsingScopeAsync( // Creating a fake HttpContext like in ModularBackgroundService. httpContextAccessor.HttpContext = shellScope.ShellContext.CreateHttpContext(); var httpContext = httpContextAccessor.HttpContext; - - httpContext.Request.PathBase = "/" + shellHost.GetSettings(tenant).RequestUrlPrefix ?? string.Empty; + httpContext.Request.PathBase = "/" + shellHost.GetSettings(tenant).RequestUrlPrefix; httpContext.Features.Set(new RecipeEnvironmentFeature()); await shellScope.UsingAsync(execute, activateShell); 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 @@ - + - + diff --git a/Lombiq.Tests.UI/Models/SafeWaitAsync.cs b/Lombiq.Tests.UI/Models/SafeWaitAsync.cs index 46fc061c7..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 is true) return true; + if (resultBool) return true; } else if (!Equals(result, default(TResult)) && (result is not IEnumerable enumerable || enumerable.Cast().Any())) 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 } } } diff --git a/Lombiq.Tests.UI/Services/AtataFactory.cs b/Lombiq.Tests.UI/Services/AtataFactory.cs index 7acdd04c9..2cf23f84b 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,14 +89,14 @@ Task FromAsync(Func> factory) } catch (WebDriverException ex) { - if (!ex.Message.ContainsOrdinalIgnoreCase("Cannot start the driver service on") || currentTry >= maxTryCount) + currentTry++; + var retryCount = maxTryCount - currentTry; + + if (!ex.Message.ContainsOrdinalIgnoreCase("Cannot start the driver service on") || retryCount <= 0) { throw; } - currentTry++; - var retryCount = maxTryCount - currentTry; - // Not using parameters because the exception can throw off the string format. testOutputHelper.WriteLineTimestampedAndDebug( "While creating the web driver failed with the following exception, it'll be retried " + 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}");