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

Using msedge with user persistence #262

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 5 additions & 1 deletion src/Microsoft.PowerApps.TestEngine/SingleTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ public async Task RunTestAsync(string testRunId, string testRunDirectory, TestSu
Logger.LogInformation("Successfully navigated to target URL");

// Log in user
await _userManager.LoginAsUserAsync(desiredUrl);
// await _userManager.LoginAsUserAsync(desiredUrl);

// IF USING "LOCAL USER MANUAL LOGIN", THEN CONSIDER
// WAITING HERE FOR THE USER TO LOG IN & REDIRECT
// BACK TO THE APP

// Set up network request mocking if any
await _testInfraFunctions.SetupNetworkRequestMockAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,44 +70,33 @@ public async Task SetupAsync()
throw new InvalidOperationException();
}

var launchOptions = new BrowserTypeLaunchOptions()
var launchOptions = new BrowserTypeLaunchPersistentContextOptions()
{
Headless = testSettings.Headless,
Timeout = testSettings.Timeout
Timeout = testSettings.Timeout,
Channel = "msedge",
ViewportSize = new ViewportSize()
{
Width = browserConfig.ScreenWidth ?? 800,
Height = browserConfig.ScreenHeight ?? 600
}
};

if (testSettings.RecordVideo)
{
launchOptions.RecordVideoDir = _singleTestInstanceState.GetTestResultsDirectory();
}

var browser = PlaywrightObject[browserConfig.Browser];
if (browser == null)
{
_singleTestInstanceState.GetLogger().LogError("Browser not supported by Playwright, for more details check https://playwright.dev/dotnet/docs/browsers");
throw new InvalidOperationException("Browser not supported.");
}

Browser = await browser.LaunchAsync(launchOptions);
_singleTestInstanceState.GetLogger().LogInformation("Browser setup finished");

var contextOptions = new BrowserNewContextOptions();

if (!string.IsNullOrEmpty(browserConfig.Device))
{
contextOptions = PlaywrightObject.Devices[browserConfig.Device];
}

if (testSettings.RecordVideo)
{
contextOptions.RecordVideoDir = _singleTestInstanceState.GetTestResultsDirectory();
}

if (browserConfig.ScreenWidth != null && browserConfig.ScreenHeight != null)
{
contextOptions.ViewportSize = new ViewportSize()
{
Width = browserConfig.ScreenWidth.Value,
Height = browserConfig.ScreenHeight.Value
};
}
BrowserContext = await browser.LaunchPersistentContextAsync(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), launchOptions);
Browser = BrowserContext.Browser;

BrowserContext = await Browser.NewContextAsync(contextOptions);
_singleTestInstanceState.GetLogger().LogInformation("Browser context created");
}

Expand Down Expand Up @@ -206,7 +195,7 @@ public async Task GoToUrlAsync(string url)
}

// TODO: consider whether to make waiting for network idle state part of the function input
var response = await Page.GotoAsync(url, new PageGotoOptions() { WaitUntil = WaitUntilState.NetworkIdle });
var response = await Page.GotoAsync(url, new PageGotoOptions() { WaitUntil = WaitUntilState.Load });

// The response might be null because "The method either throws an error or returns a main resource response.
// The only exceptions are navigation to about:blank or navigation to the same URL with a different hash, which would succeed and return null."
Expand Down
3 changes: 3 additions & 0 deletions src/PowerAppsTestEngine/PowerAppsTestEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
</ItemGroup>

<ItemGroup>
<None Update="config.dev.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="config.dev.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down