diff --git a/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/Argument.cs b/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/Argument.cs index a421e56c3..740a9ae22 100644 --- a/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/Argument.cs +++ b/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/Argument.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using OpenQA.Selenium; namespace Microsoft.DotNet.XHarness.CLI.CommandArguments; @@ -283,6 +284,32 @@ public override void Action(string argumentValue) public override string ToString() => Value ? "true" : "false"; } +public abstract class EnumPageLoadStrategyArgument : Argument +{ + private readonly PageLoadStrategy _defaultValue; + + public EnumPageLoadStrategyArgument(string prototype, string description, PageLoadStrategy defaultValue) + : base(prototype, description, defaultValue) + { + _defaultValue = defaultValue; + } + + public override void Action(string argumentValue) + { + if (string.IsNullOrEmpty(argumentValue)) + { + Value = _defaultValue; + } + else + { + Value = argumentValue.Equals("none", StringComparison.OrdinalIgnoreCase) ? PageLoadStrategy.None : + argumentValue.Equals("eager", StringComparison.OrdinalIgnoreCase) ? PageLoadStrategy.Eager : + argumentValue.Equals("normal", StringComparison.OrdinalIgnoreCase) ? PageLoadStrategy.Normal : + _defaultValue; + } + } +} + public abstract class RepeatableArgument : Argument> { private readonly List _values = new(); diff --git a/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASM/Arguments/PageLoadStrategyArgument.cs b/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASM/Arguments/PageLoadStrategyArgument.cs new file mode 100644 index 000000000..8a7a29356 --- /dev/null +++ b/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASM/Arguments/PageLoadStrategyArgument.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Wasm; + +using OpenQA.Selenium; +using System; + +internal class PageLoadStrategyArgument : EnumPageLoadStrategyArgument +{ + private const string HelpMessage = + $@"Decides how long WebDriver will hold off on completing a navigation method. + NORMAL (default): Does not block WebDriver at all. Ready state: complete. + EAGER: DOM access is ready, but other resources like images may still be loading. Ready state: interactive. + NONE: Does not block WebDriver at all. Ready state: any."; + + public PageLoadStrategyArgument(PageLoadStrategy defaultValue) + : base("pageLoadStrategy=", HelpMessage, defaultValue) + {} +} diff --git a/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASM/WasmTestBrowserCommandArguments.cs b/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASM/WasmTestBrowserCommandArguments.cs index 503281a65..25678458e 100644 --- a/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASM/WasmTestBrowserCommandArguments.cs +++ b/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASM/WasmTestBrowserCommandArguments.cs @@ -26,6 +26,7 @@ internal class WasmTestBrowserCommandArguments : XHarnessCommandArguments, IWebS public NoQuitArgument NoQuit { get; } = new(); public BackgroundThrottlingArgument BackgroundThrottling { get; } = new(); public LocaleArgument Locale { get; } = new("en-US"); + public PageLoadStrategyArgument PageLoadStrategy { get; } = new(OpenQA.Selenium.PageLoadStrategy.Normal); public SymbolMapFileArgument SymbolMapFileArgument { get; } = new(); public SymbolicatePatternsFileArgument SymbolicatePatternsFileArgument { get; } = new(); @@ -56,6 +57,7 @@ internal class WasmTestBrowserCommandArguments : XHarnessCommandArguments, IWebS NoQuit, BackgroundThrottling, Locale, + PageLoadStrategy, SymbolMapFileArgument, SymbolicatePatternsFileArgument, SymbolicatorArgument, diff --git a/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASM/WasmTestCommandArguments.cs b/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASM/WasmTestCommandArguments.cs index 71339054b..44fd3b2b6 100644 --- a/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASM/WasmTestCommandArguments.cs +++ b/src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASM/WasmTestCommandArguments.cs @@ -18,6 +18,7 @@ internal class WasmTestCommandArguments : XHarnessCommandArguments, IWebServerAr public OutputDirectoryArgument OutputDirectory { get; } = new(); public TimeoutArgument Timeout { get; } = new(TimeSpan.FromMinutes(15)); public LocaleArgument Locale { get; } = new("en-US"); + public PageLoadStrategyArgument PageLoadStrategy { get; } = new(OpenQA.Selenium.PageLoadStrategy.Normal); public SymbolMapFileArgument SymbolMapFileArgument { get; } = new(); public SymbolicatePatternsFileArgument SymbolicatePatternsFileArgument { get; } = new(); @@ -42,6 +43,7 @@ internal class WasmTestCommandArguments : XHarnessCommandArguments, IWebServerAr Timeout, ExpectedExitCode, Locale, + PageLoadStrategy, SymbolMapFileArgument, SymbolicatePatternsFileArgument, SymbolicatorArgument, diff --git a/src/Microsoft.DotNet.XHarness.CLI/Commands/WASM/Browser/WasmTestBrowserCommand.cs b/src/Microsoft.DotNet.XHarness.CLI/Commands/WASM/Browser/WasmTestBrowserCommand.cs index 50a89b78f..e1db5fd5a 100644 --- a/src/Microsoft.DotNet.XHarness.CLI/Commands/WASM/Browser/WasmTestBrowserCommand.cs +++ b/src/Microsoft.DotNet.XHarness.CLI/Commands/WASM/Browser/WasmTestBrowserCommand.cs @@ -177,7 +177,9 @@ protected override async Task InvokeInternal(ILogger logger) if (!Arguments.NoIncognito) options.AddArguments("-private-window"); - logger.LogInformation($"Starting Firefox with args: {string.Join(' ', options.ToCapabilities())}"); + options.PageLoadStrategy = Arguments.PageLoadStrategy.Value; + + logger.LogInformation($"Starting Firefox with args: {string.Join(' ', options.ToCapabilities())} and load strategy: {Arguments.PageLoadStrategy.Value}"); return CreateWebDriver( () => FirefoxDriverService.CreateDefaultService(), @@ -265,7 +267,12 @@ protected override async Task InvokeInternal(ILogger logger) if (Arguments.NoQuit) options.LeaveBrowserRunning = true; - logger.LogInformation($"Starting {driverName} with args: {string.Join(' ', options.Arguments)}"); + if (options is ChromeOptions chromeOptions) + chromeOptions.PageLoadStrategy = Arguments.PageLoadStrategy.Value; + if (options is EdgeOptions edgeOptions) + edgeOptions.PageLoadStrategy = Arguments.PageLoadStrategy.Value; + + logger.LogInformation($"Starting {driverName} with args: {string.Join(' ', options.Arguments)} and load strategy: {Arguments.PageLoadStrategy.Value}"); // We want to explicitly specify a timeout here. This is for for the // driver commands, like getLog. The default is 60s, which ends up