Skip to content

Commit 2e428a0

Browse files
committed
fix build
1 parent 78112e1 commit 2e428a0

2 files changed

Lines changed: 53 additions & 11 deletions

File tree

tests/PrompterOne.Web.UITests/Infrastructure/StandaloneAppFixture.Warmup.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Playwright;
22
using PrompterOne.Shared.Contracts;
3+
using PrompterOne.Testing;
34
using static Microsoft.Playwright.Assertions;
45

56
namespace PrompterOne.Web.UITests;
@@ -49,6 +50,27 @@ await page.EvaluateAsync(
4950
await page.EvaluateAsync(BrowserTestLibrarySeedData.CreateInitializationScript());
5051
}
5152

53+
private static async Task WarmUpContextPageIfNeededAsync(IPage page, string baseAddress)
54+
{
55+
if (!TestEnvironment.IsCiEnvironment)
56+
{
57+
return;
58+
}
59+
60+
var browserErrors = BrowserErrorCollector.Attach(page);
61+
62+
try
63+
{
64+
await WarmUpRouteAsync(page, BrowserTestConstants.Routes.Library, UiTestIds.Library.Page);
65+
await PrimeIsolatedBrowserStorageAsync(page, baseAddress);
66+
await browserErrors.AssertNoCriticalUiErrorsAsync();
67+
}
68+
catch (Exception exception)
69+
{
70+
throw BuildContextWarmupFailure(exception, browserErrors.Describe());
71+
}
72+
}
73+
5274
private static async Task WarmUpRuntimeAsync(IBrowser browser, string baseAddress)
5375
{
5476
var context = await CreateBrowserContextAsync(browser, baseAddress);
@@ -94,6 +116,14 @@ private static InvalidOperationException BuildWarmupFailure(Exception exception,
94116
exception,
95117
exception);
96118

119+
private static InvalidOperationException BuildContextWarmupFailure(Exception exception, string browserDiagnostics) =>
120+
new(
121+
"Browser context warmup failed." + Environment.NewLine +
122+
"Captured browser errors:" + Environment.NewLine +
123+
browserDiagnostics + Environment.NewLine +
124+
exception,
125+
exception);
126+
97127
private static async Task DisposeContextAsync(IBrowserContext context)
98128
{
99129
try

tests/PrompterOne.Web.UITests/Infrastructure/StandaloneAppFixture.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,23 @@ public async Task<IReadOnlyList<IPage>> NewSharedPagesAsync(
7272

7373
private async Task<IPage> CreateAdditionalPageAsync()
7474
{
75-
var context = await CreateTrackedContextAsync();
76-
var page = await context.NewPageAsync();
77-
PreparePage(page);
78-
await PrimeIsolatedBrowserStorageAsync(page);
79-
return page;
75+
while (true)
76+
{
77+
var context = await CreateTrackedContextAsync();
78+
79+
try
80+
{
81+
var page = await context.NewPageAsync();
82+
PreparePage(page);
83+
await PrimeIsolatedBrowserStorageAsync(page);
84+
await WarmUpContextPageIfNeededAsync(page, BaseAddress);
85+
return page;
86+
}
87+
catch (PlaywrightException exception) when (IsBrowserClosedException(exception))
88+
{
89+
await DisposeContextAsync(context);
90+
}
91+
}
8092
}
8193

8294
private async Task<IPage> CreateSharedPageAsync(string contextKey)
@@ -90,14 +102,14 @@ private async Task<IPage> CreateSharedPageAsync(string contextKey)
90102
var page = await context.NewPageAsync();
91103
PreparePage(page);
92104

93-
await page.GotoAsync($"{BaseAddress}{UiTestHostConstants.BlankPagePath}");
94-
95105
if (isNewSharedContext)
96106
{
97-
await page.EvaluateAsync(
98-
UiTestHostConstants.ResetBrowserStorageScript,
99-
UiTestHostConstants.BrowserStorageDatabaseName);
100-
await page.EvaluateAsync(BrowserTestLibrarySeedData.CreateInitializationScript());
107+
await PrimeIsolatedBrowserStorageAsync(page);
108+
await WarmUpContextPageIfNeededAsync(page, BaseAddress);
109+
}
110+
else
111+
{
112+
await page.GotoAsync($"{BaseAddress}{UiTestHostConstants.BlankPagePath}");
101113
}
102114

103115
return page;

0 commit comments

Comments
 (0)