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

Allow overwriting PageLoadStrategy in wasm tests #1268

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Microsoft.DotNet.XHarness.CLI/CommandArguments/Argument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using OpenQA.Selenium;

namespace Microsoft.DotNet.XHarness.CLI.CommandArguments;

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

public abstract class EnumPageLoadStrategyArgument : Argument<PageLoadStrategy>
{
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<IEnumerable<string>>
{
private readonly List<string> _values = new();
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -56,6 +57,7 @@ internal class WasmTestBrowserCommandArguments : XHarnessCommandArguments, IWebS
NoQuit,
BackgroundThrottling,
Locale,
PageLoadStrategy,
SymbolMapFileArgument,
SymbolicatePatternsFileArgument,
SymbolicatorArgument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -42,6 +43,7 @@ internal class WasmTestCommandArguments : XHarnessCommandArguments, IWebServerAr
Timeout,
ExpectedExitCode,
Locale,
PageLoadStrategy,
SymbolMapFileArgument,
SymbolicatePatternsFileArgument,
SymbolicatorArgument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ protected override async Task<ExitCode> 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(),
Expand Down Expand Up @@ -265,7 +267,12 @@ protected override async Task<ExitCode> 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;
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
Loading