@@ -59,7 +59,9 @@ private static IBrowser CreateBrowser()
59
59
}
60
60
61
61
public static Task < IBrowserContext > CreateNewBrowserContextAsync ( )
62
- => Browser . Value . NewContextAsync ( new BrowserNewContextOptions { IgnoreHTTPSErrors = true } ) ;
62
+ => BuildEnvironment . HasPlaywrightSupport
63
+ ? Browser . Value . NewContextAsync ( new BrowserNewContextOptions { IgnoreHTTPSErrors = true } )
64
+ : throw new InvalidOperationException ( "Playwright is not available" ) ;
63
65
64
66
protected Task < ResourceRow [ ] > CheckDashboardHasResourcesAsync ( IPage dashboardPage , IEnumerable < ResourceRow > expectedResources , int timeoutSecs = 120 )
65
67
=> CheckDashboardHasResourcesAsync ( dashboardPage , expectedResources , _testOutput , timeoutSecs ) ;
@@ -203,29 +205,37 @@ public static IEnumerable<string> GetProjectNamesForTest()
203
205
yield return "aspire" ;
204
206
}
205
207
206
- public static async Task AssertStarterTemplateRunAsync ( IBrowserContext context , AspireProject project , string config , ITestOutputHelper _testOutput )
208
+ public static async Task AssertStarterTemplateRunAsync ( IBrowserContext ? context , AspireProject project , string config , ITestOutputHelper _testOutput )
207
209
{
208
210
await project . StartAppHostAsync ( extraArgs : [ $ "-c { config } "] , noBuild : false ) ;
209
211
210
- var page = await project . OpenDashboardPageAsync ( context ) ;
211
- ResourceRow [ ] resourceRows ;
212
- try
212
+ if ( context is not null )
213
213
{
214
- resourceRows = await CheckDashboardHasResourcesAsync (
215
- page ,
216
- StarterTemplateRunTestsBase < StarterTemplateFixture > . GetExpectedResources ( project , hasRedisCache : false ) ,
217
- _testOutput ) . ConfigureAwait ( false ) ;
214
+ var page = await project . OpenDashboardPageAsync ( context ) ;
215
+ ResourceRow [ ] resourceRows ;
216
+ try
217
+ {
218
+ resourceRows = await CheckDashboardHasResourcesAsync (
219
+ page ,
220
+ StarterTemplateRunTestsBase < StarterTemplateFixture > . GetExpectedResources ( project , hasRedisCache : false ) ,
221
+ _testOutput ) . ConfigureAwait ( false ) ;
222
+ }
223
+ catch
224
+ {
225
+ string screenshotPath = Path . Combine ( project . LogPath , "dashboard-fail.png" ) ;
226
+ await page . ScreenshotAsync ( new PageScreenshotOptions { Path = screenshotPath } ) ;
227
+ _testOutput . WriteLine ( $ "Dashboard screenshot saved to { screenshotPath } ") ;
228
+ throw ;
229
+ }
230
+
231
+ string url = resourceRows . First ( r => r . Name == "webfrontend" ) . Endpoints [ 0 ] ;
232
+ await StarterTemplateRunTestsBase < StarterTemplateFixture > . CheckWebFrontendWorksAsync ( context , url , _testOutput , project . LogPath ) ;
218
233
}
219
- catch
234
+ else
220
235
{
221
- string screenshotPath = Path . Combine ( project . LogPath , "dashboard-fail.png" ) ;
222
- await page . ScreenshotAsync ( new PageScreenshotOptions { Path = screenshotPath } ) ;
223
- _testOutput . WriteLine ( $ "Dashboard screenshot saved to { screenshotPath } ") ;
224
- throw ;
236
+ _testOutput . WriteLine ( $ "Skipping playwright part of the test") ;
225
237
}
226
238
227
- string url = resourceRows . First ( r => r . Name == "webfrontend" ) . Endpoints [ 0 ] ;
228
- await StarterTemplateRunTestsBase < StarterTemplateFixture > . CheckWebFrontendWorksAsync ( context , url , _testOutput , project . LogPath ) ;
229
239
await project . StopAppHostAsync ( ) ;
230
240
}
231
241
0 commit comments