Skip to content

Commit f20e52f

Browse files
authored
Allow overwriting PageLoadStrategy in wasm tests (#1268)
* Add the arg. * Feedback
1 parent 9a7efc6 commit f20e52f

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

src/Microsoft.DotNet.XHarness.CLI/CommandArguments/Argument.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.IO;
88
using System.Linq;
9+
using OpenQA.Selenium;
910

1011
namespace Microsoft.DotNet.XHarness.CLI.CommandArguments;
1112

@@ -283,6 +284,32 @@ public override void Action(string argumentValue)
283284
public override string ToString() => Value ? "true" : "false";
284285
}
285286

287+
public abstract class EnumPageLoadStrategyArgument : Argument<PageLoadStrategy>
288+
{
289+
private readonly PageLoadStrategy _defaultValue;
290+
291+
public EnumPageLoadStrategyArgument(string prototype, string description, PageLoadStrategy defaultValue)
292+
: base(prototype, description, defaultValue)
293+
{
294+
_defaultValue = defaultValue;
295+
}
296+
297+
public override void Action(string argumentValue)
298+
{
299+
if (string.IsNullOrEmpty(argumentValue))
300+
{
301+
Value = _defaultValue;
302+
}
303+
else
304+
{
305+
Value = argumentValue.Equals("none", StringComparison.OrdinalIgnoreCase) ? PageLoadStrategy.None :
306+
argumentValue.Equals("eager", StringComparison.OrdinalIgnoreCase) ? PageLoadStrategy.Eager :
307+
argumentValue.Equals("normal", StringComparison.OrdinalIgnoreCase) ? PageLoadStrategy.Normal :
308+
_defaultValue;
309+
}
310+
}
311+
}
312+
286313
public abstract class RepeatableArgument : Argument<IEnumerable<string>>
287314
{
288315
private readonly List<string> _values = new();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Wasm;
6+
7+
using OpenQA.Selenium;
8+
using System;
9+
10+
internal class PageLoadStrategyArgument : EnumPageLoadStrategyArgument
11+
{
12+
private const string HelpMessage =
13+
$@"Decides how long WebDriver will hold off on completing a navigation method.
14+
NORMAL (default): Does not block WebDriver at all. Ready state: complete.
15+
EAGER: DOM access is ready, but other resources like images may still be loading. Ready state: interactive.
16+
NONE: Does not block WebDriver at all. Ready state: any.";
17+
18+
public PageLoadStrategyArgument(PageLoadStrategy defaultValue)
19+
: base("pageLoadStrategy=", HelpMessage, defaultValue)
20+
{}
21+
}

src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASM/WasmTestBrowserCommandArguments.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal class WasmTestBrowserCommandArguments : XHarnessCommandArguments, IWebS
2626
public NoQuitArgument NoQuit { get; } = new();
2727
public BackgroundThrottlingArgument BackgroundThrottling { get; } = new();
2828
public LocaleArgument Locale { get; } = new("en-US");
29+
public PageLoadStrategyArgument PageLoadStrategy { get; } = new(OpenQA.Selenium.PageLoadStrategy.Normal);
2930

3031
public SymbolMapFileArgument SymbolMapFileArgument { get; } = new();
3132
public SymbolicatePatternsFileArgument SymbolicatePatternsFileArgument { get; } = new();
@@ -56,6 +57,7 @@ internal class WasmTestBrowserCommandArguments : XHarnessCommandArguments, IWebS
5657
NoQuit,
5758
BackgroundThrottling,
5859
Locale,
60+
PageLoadStrategy,
5961
SymbolMapFileArgument,
6062
SymbolicatePatternsFileArgument,
6163
SymbolicatorArgument,

src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASM/WasmTestCommandArguments.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ internal class WasmTestCommandArguments : XHarnessCommandArguments, IWebServerAr
1818
public OutputDirectoryArgument OutputDirectory { get; } = new();
1919
public TimeoutArgument Timeout { get; } = new(TimeSpan.FromMinutes(15));
2020
public LocaleArgument Locale { get; } = new("en-US");
21+
public PageLoadStrategyArgument PageLoadStrategy { get; } = new(OpenQA.Selenium.PageLoadStrategy.Normal);
2122

2223
public SymbolMapFileArgument SymbolMapFileArgument { get; } = new();
2324
public SymbolicatePatternsFileArgument SymbolicatePatternsFileArgument { get; } = new();
@@ -42,6 +43,7 @@ internal class WasmTestCommandArguments : XHarnessCommandArguments, IWebServerAr
4243
Timeout,
4344
ExpectedExitCode,
4445
Locale,
46+
PageLoadStrategy,
4547
SymbolMapFileArgument,
4648
SymbolicatePatternsFileArgument,
4749
SymbolicatorArgument,

src/Microsoft.DotNet.XHarness.CLI/Commands/WASM/Browser/WasmTestBrowserCommand.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ protected override async Task<ExitCode> InvokeInternal(ILogger logger)
177177
if (!Arguments.NoIncognito)
178178
options.AddArguments("-private-window");
179179

180-
logger.LogInformation($"Starting Firefox with args: {string.Join(' ', options.ToCapabilities())}");
180+
options.PageLoadStrategy = Arguments.PageLoadStrategy.Value;
181+
182+
logger.LogInformation($"Starting Firefox with args: {string.Join(' ', options.ToCapabilities())} and load strategy: {Arguments.PageLoadStrategy.Value}");
181183

182184
return CreateWebDriver(
183185
() => FirefoxDriverService.CreateDefaultService(),
@@ -265,7 +267,12 @@ protected override async Task<ExitCode> InvokeInternal(ILogger logger)
265267
if (Arguments.NoQuit)
266268
options.LeaveBrowserRunning = true;
267269

268-
logger.LogInformation($"Starting {driverName} with args: {string.Join(' ', options.Arguments)}");
270+
if (options is ChromeOptions chromeOptions)
271+
chromeOptions.PageLoadStrategy = Arguments.PageLoadStrategy.Value;
272+
if (options is EdgeOptions edgeOptions)
273+
edgeOptions.PageLoadStrategy = Arguments.PageLoadStrategy.Value;
274+
275+
logger.LogInformation($"Starting {driverName} with args: {string.Join(' ', options.Arguments)} and load strategy: {Arguments.PageLoadStrategy.Value}");
269276

270277
// We want to explicitly specify a timeout here. This is for for the
271278
// driver commands, like getLog. The default is 60s, which ends up

0 commit comments

Comments
 (0)