Skip to content

Commit 58353d3

Browse files
committed
Pause Changes
1 parent 135c24a commit 58353d3

3 files changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
testSuite:
2+
testSuiteName: Pause Function Tests
3+
testSuiteDescription: Verifies that the Pause function works correctly
4+
persona: User1
5+
appLogicalName: mda_input_controls_app
6+
7+
testCases:
8+
- testCaseName: Test Pause Function - Non-Headless Mode
9+
testCaseDescription: Tests that Pause function works when headless is false
10+
testSteps: |
11+
=
12+
Screenshot("before_pause.png");
13+
Pause();
14+
Screenshot("after_pause.png");
15+
Assert(true, "Test continued after Pause function");
16+
17+
testSettings:
18+
headless: false
19+
browserConfigurations:
20+
- browser: Chromium
21+
channel: msedge
22+
extensionModules:
23+
enable: true
24+
parameters:
25+
enableCorePause: true
26+
27+
environmentVariables:
28+
users:
29+
- personaName: User1
30+
emailKey: user1Email
31+
passwordKey: NotNeeded
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
using Microsoft.Extensions.Logging;
5+
using Microsoft.PowerApps.TestEngine.Config;
6+
using Microsoft.PowerApps.TestEngine.TestInfra;
7+
using Microsoft.PowerFx;
8+
using Microsoft.PowerFx.Types;
9+
10+
namespace Microsoft.PowerApps.TestEngine.PowerFx.Functions
11+
{
12+
/// <summary>
13+
/// This will pause the current test and allow the user to interact with the browser and inspect state when headless mode is false
14+
/// </summary>
15+
public class PauseFunction : ReflectionFunction
16+
{
17+
private readonly ITestInfraFunctions _testInfraFunctions;
18+
private readonly ITestState _testState;
19+
private readonly ILogger _logger;
20+
21+
public PauseFunction(ITestInfraFunctions testInfraFunctions, ITestState testState, ILogger logger)
22+
: base("Pause", FormulaType.Blank)
23+
{
24+
_testInfraFunctions = testInfraFunctions;
25+
_testState = testState;
26+
_logger = logger;
27+
}
28+
29+
public BlankValue Execute()
30+
{
31+
_logger.LogInformation("------------------------------\n\n" +
32+
"Executing Pause function.");
33+
34+
var testSettings = _testState.GetTestSettings();
35+
36+
if (!IsPreviewEnabledInOriginalConfig(testSettings))
37+
{
38+
_logger.LogInformation("Pause function is disabled - Preview namespace not explicitly enabled in YAML configuration.");
39+
return FormulaValue.NewBlank();
40+
}
41+
42+
if (!testSettings.Headless)
43+
{
44+
var page = _testInfraFunctions.GetContext().Pages.First();
45+
page.PauseAsync().Wait();
46+
_logger.LogInformation("Successfully finished executing Pause function.");
47+
}
48+
else
49+
{
50+
_logger.LogInformation("Skip Pause function as in headless mode.");
51+
}
52+
53+
return FormulaValue.NewBlank();
54+
}
55+
56+
private bool IsPreviewEnabledInOriginalConfig(TestSettings testSettings)
57+
{
58+
return testSettings?.ExtensionModules?.Parameters?.ContainsKey("enableCorePause") == true &&
59+
testSettings.ExtensionModules.Parameters["enableCorePause"]?.ToString().ToLower() == "true";
60+
}
61+
}
62+
}

src/Microsoft.PowerApps.TestEngine/PowerFx/PowerFxEngine.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public void Setup(TestSettings settings)
102102
powerFxConfig.AddFunction(new AssertNotErrorFunction(Logger));
103103
powerFxConfig.AddFunction(new SetPropertyFunction(_testWebProvider, Logger));
104104
powerFxConfig.AddFunction(new IsMatchFunction(Logger));
105+
powerFxConfig.AddFunction(new PauseFunction(TestInfraFunctions, TestState, Logger));
105106

106107
if (settings != null && settings.ExtensionModules != null && settings.ExtensionModules.Enable)
107108
{
@@ -112,6 +113,11 @@ public void Setup(TestSettings settings)
112113
}
113114
foreach (var module in modules)
114115
{
116+
if (module.GetType().Name.Contains("Pause"))
117+
{
118+
Logger.LogInformation("Skipping pause module as core Pause function is enabled");
119+
continue;
120+
}
115121
module.RegisterPowerFxFunction(powerFxConfig, TestInfraFunctions, _testWebProvider, SingleTestInstanceState, TestState, _fileSystem);
116122
}
117123
}

0 commit comments

Comments
 (0)