Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-88: Fixing TestAdminBackgroundTasksAsMonkeyRecursivelyShouldWorkWithAdminUser occasionally failing #145

Merged
merged 10 commits into from
Mar 21, 2022
Merged
3 changes: 3 additions & 0 deletions Lombiq.Tests.UI.Samples/Tests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public Task ApplicationInsightsTrackingShouldBePresent(Browser browser) =>
ExecuteTestAfterSetupAsync(
async context =>
{
await context.EnableFeatureDirectlyAsync("Lombiq.Privacy.ConsentBanner");
await context.GoToHomePageAsync();

// Now there's a bit of a pickle though: The Lombiq Privacy module is also enabled from the test recipe
// and shows its privacy consent banner. For tracking to be enabled, even in offline mode, the user
// needs to give consent. This is what we do now:
Expand Down
15 changes: 14 additions & 1 deletion Lombiq.Tests.UI.Samples/Tests/MonkeyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using Lombiq.Tests.UI.MonkeyTesting;
using Lombiq.Tests.UI.MonkeyTesting.UrlFilters;
using Lombiq.Tests.UI.Services;
using Shouldly;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes outside this file and LoggingWebDriverExtensions are coming from issue/OSOE-64.

using System;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -58,7 +60,12 @@ public Task TestAdminPagesAsMonkeyRecursivelyShouldWorkWithAdminUser(Browser bro
context =>
// Monkey tests needn't all start from the homepage. This one starts from the Orchard admin dashboard.
context.TestAdminAsMonkeyRecursivelyAsync(CreateMonkeyTestingOptions()),
browser);
browser,
configuration =>
// This is necessary to work around this bug: https://github.com/OrchardCMS/OrchardCore/issues/11420.
configuration.AssertBrowserLog = messages => messages.ShouldNotContain(
message => IsValidAdminBrowserLogMessage(message),
messages.Where(IsValidAdminBrowserLogMessage).ToFormattedString()));

// Let's just test the background tasks management admin area.
[Theory, Chrome]
Expand Down Expand Up @@ -87,6 +94,12 @@ private static MonkeyTestingOptions CreateMonkeyTestingOptions() =>
{
PageTestTime = TimeSpan.FromSeconds(10),
};

private static bool IsValidAdminBrowserLogMessage(BrowserLogMessage message) =>
OrchardCoreUITestExecutorConfiguration.IsValidBrowserLogMessage(message) &&
!(message.Source == BrowserLogMessage.Sources.Intervention &&
message.Message.ContainsOrdinalIgnoreCase(
"Blocked attempt to show a 'beforeunload' confirmation panel for a frame that never had a user gesture since its load."));
}

// END OF TRAINING SECTION: Monkey tests.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lombiq.HelpfulLibraries.Libraries.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OrchardCore.Environment.Extensions;
using OrchardCore.Environment.Extensions.Features;
Expand All @@ -10,6 +11,7 @@
namespace Lombiq.Tests.UI.Shortcuts.Controllers;

[DevelopmentAndLocalhostOnly]
[AllowAnonymous]
public class ShellFeaturesController : Controller
{
private readonly IShellFeaturesManager _shellFeatureManager;
Expand Down
1 change: 1 addition & 0 deletions Lombiq.Tests.UI/Extensions/LoggingWebDriverExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static class Sources
{
public const string ConsoleApi = "console-api";
public const string Deprecation = "deprecation";
public const string Intervention = "intervention";
public const string Javascript = "javascript";
public const string Network = "network";
public const string Recommendation = "recommendation";
Expand Down
2 changes: 1 addition & 1 deletion Lombiq.Tests.UI/Services/OrchardCoreInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public async Task<Uri> StartUpAsync()
argumentsBuilder = argumentsBuilder
.Add("--urls").Add(url)
.Add("--contentRoot").Add(_contentRootPath)
.Add("--webroot=").Add(Path.Combine(_contentRootPath, "wwwroot"))
.Add("--webroot").Add(Path.Combine(_contentRootPath, "wwwroot"))
.Add("--environment").Add("Development");

if (!useExeToExecuteApp) argumentsBuilder = argumentsBuilder.Add(_configuration.AppAssemblyPath);
Expand Down