-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathPauseModule.cs
More file actions
69 lines (61 loc) · 2.58 KB
/
PauseModule.cs
File metadata and controls
69 lines (61 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
using System.ComponentModel.Composition;
using Microsoft.Extensions.Logging;
using Microsoft.Playwright;
using Microsoft.PowerApps.TestEngine.Config;
using Microsoft.PowerApps.TestEngine.Modules;
using Microsoft.PowerApps.TestEngine.Providers;
using Microsoft.PowerApps.TestEngine.System;
using Microsoft.PowerApps.TestEngine.TestInfra;
using Microsoft.PowerFx;
namespace testengine.module
{
[Export(typeof(ITestEngineModule))]
public class PauseModule : ITestEngineModule
{
/// <summary>
/// Indicates whether Preview namespace is enabled in YAML testSettings.extensionModules.allowPowerFxNamespaces.
/// </summary>
public virtual bool IsPreviewNamespaceEnabled { get; private set; } = false;
public void ExtendBrowserContextOptions(BrowserNewContextOptions options, TestSettings settings)
{
UpdatePreviewNamespaceProperty(settings);
}
public void RegisterPowerFxFunction(PowerFxConfig config, ITestInfraFunctions testInfraFunctions, ITestWebProvider testWebProvider, ISingleTestInstanceState singleTestInstanceState, ITestState testState, IFileSystem fileSystem)
{
TestSettings testSettings = null;
try
{
if (testState != null)
{
testSettings = testState.GetTestSettings();
}
}
catch
{
testSettings = null;
}
UpdatePreviewNamespaceProperty(testSettings);
ILogger logger = singleTestInstanceState.GetLogger();
// Only register Pause() function if Preview namespace is enabled
if (IsPreviewNamespaceEnabled)
{
config.AddFunction(new PauseFunction(testInfraFunctions, testState, logger));
logger.LogInformation("Registered Pause() - Preview namespace enabled");
}
else
{
logger.LogInformation("Skip registering Pause() - Preview namespace not enabled");
}
}
public async Task RegisterNetworkRoute(ITestState state, ISingleTestInstanceState singleTestInstanceState, IFileSystem fileSystem, IPage Page, NetworkRequestMock mock)
{
await Task.CompletedTask;
}
private void UpdatePreviewNamespaceProperty(TestSettings settings)
{
IsPreviewNamespaceEnabled = settings?.ExtensionModules?.AllowPowerFxNamespaces?.Contains("Preview") ?? false;
}
}
}