11
11
using Microsoft . AspNetCore . Testing ;
12
12
using Microsoft . Extensions . CommandLineUtils ;
13
13
using Newtonsoft . Json . Linq ;
14
- using PlaywrightSharp ;
14
+ using Microsoft . Playwright ;
15
15
using Templates . Test . Helpers ;
16
16
17
17
namespace BlazorTemplates . Tests ;
@@ -56,7 +56,7 @@ public async Task BlazorWasmStandaloneTemplate_Works(BrowserKind browserKind)
56
56
private static async Task < IPage > NavigateToPage ( IBrowserContext browser , string listeningUri )
57
57
{
58
58
var page = await browser . NewPageAsync ( ) ;
59
- await page . GoToAsync ( listeningUri , LifecycleEvent . Networkidle ) ;
59
+ await page . GotoAsync ( listeningUri , new ( ) { WaitUntil = WaitUntilState . NetworkIdle } ) ;
60
60
return page ;
61
61
}
62
62
@@ -133,9 +133,9 @@ public async Task BlazorWasmStandalonePwaTemplate_Works(BrowserKind browserKind)
133
133
134
134
// The PWA template supports offline use. By now, the browser should have cached everything it needs,
135
135
// so we can continue working even without the server.
136
- await page . GoToAsync ( "about:blank" ) ;
136
+ await page . GotoAsync ( "about:blank" ) ;
137
137
await browser . SetOfflineAsync ( true ) ;
138
- await page . GoToAsync ( listeningUri ) ;
138
+ await page . GotoAsync ( listeningUri ) ;
139
139
await TestBasicNavigation ( project . ProjectName , page , skipFetchData : true ) ;
140
140
await page . CloseAsync ( ) ;
141
141
}
@@ -181,9 +181,9 @@ public async Task BlazorWasmHostedPwaTemplate_Works(BrowserKind browserKind)
181
181
// The PWA template supports offline use. By now, the browser should have cached everything it needs,
182
182
// so we can continue working even without the server.
183
183
// Since this is the hosted project, backend APIs won't work offline, so we need to skip "fetchdata"
184
- await page . GoToAsync ( "about:blank" ) ;
184
+ await page . GotoAsync ( "about:blank" ) ;
185
185
await browser . SetOfflineAsync ( true ) ;
186
- await page . GoToAsync ( listeningUri ) ;
186
+ await page . GotoAsync ( listeningUri ) ;
187
187
await TestBasicNavigation ( project . ProjectName , page , skipFetchData : true ) ;
188
188
await page . CloseAsync ( ) ;
189
189
}
@@ -416,11 +416,11 @@ private static async Task TestBasicNavigation(string appName, IPage page, bool u
416
416
// Initially displays the home page
417
417
await page . WaitForSelectorAsync ( "h1 >> text=Hello, world!" ) ;
418
418
419
- Assert . Equal ( "Index" , ( await page . GetTitleAsync ( ) ) . Trim ( ) ) ;
419
+ Assert . Equal ( "Index" , ( await page . TitleAsync ( ) ) . Trim ( ) ) ;
420
420
421
421
// Can navigate to the counter page
422
422
await Task . WhenAll (
423
- page . WaitForNavigationAsync ( "**/counter" ) ,
423
+ page . WaitForNavigationAsync ( new ( ) { UrlString = "**/counter" } ) ,
424
424
page . WaitForSelectorAsync ( "h1 >> text=Counter" ) ,
425
425
page . WaitForSelectorAsync ( "p >> text=Current count: 0" ) ,
426
426
page . ClickAsync ( "a[href=counter]" ) ) ;
@@ -433,12 +433,12 @@ await Task.WhenAll(
433
433
if ( usesAuth )
434
434
{
435
435
await Task . WhenAll (
436
- page . WaitForNavigationAsync ( "**/Identity/Account/Login**" , LifecycleEvent . Networkidle ) ,
436
+ page . WaitForNavigationAsync ( new ( ) { UrlString = "**/Identity/Account/Login**" , WaitUntil = WaitUntilState . NetworkIdle } ) ,
437
437
page . ClickAsync ( "text=Log in" ) ) ;
438
438
439
439
await Task . WhenAll (
440
440
page . WaitForSelectorAsync ( "[name=\" Input.Email\" ]" ) ,
441
- page . WaitForNavigationAsync ( "**/Identity/Account/Register**" , LifecycleEvent . Networkidle ) ,
441
+ page . WaitForNavigationAsync ( new ( ) { UrlString = "**/Identity/Account/Register**" , WaitUntil = WaitUntilState . NetworkIdle } ) ,
442
442
page . ClickAsync ( "text=Register as a new user" ) ) ;
443
443
444
444
var userName = $ "{ Guid . NewGuid ( ) } @example.com";
@@ -450,12 +450,12 @@ await Task.WhenAll(
450
450
451
451
// We will be redirected to the RegisterConfirmation
452
452
await Task . WhenAll (
453
- page . WaitForNavigationAsync ( "**/Identity/Account/RegisterConfirmation**" , LifecycleEvent . Networkidle ) ,
453
+ page . WaitForNavigationAsync ( new ( ) { UrlString = "**/Identity/Account/RegisterConfirmation**" , WaitUntil = WaitUntilState . NetworkIdle } ) ,
454
454
page . ClickAsync ( "#registerSubmit" ) ) ;
455
455
456
456
// We will be redirected to the ConfirmEmail
457
457
await Task . WhenAll (
458
- page . WaitForNavigationAsync ( "**/Identity/Account/ConfirmEmail**" , LifecycleEvent . Networkidle ) ,
458
+ page . WaitForNavigationAsync ( new ( ) { UrlString = "**/Identity/Account/ConfirmEmail**" , WaitUntil = WaitUntilState . NetworkIdle } ) ,
459
459
page . ClickAsync ( "text=Click here to confirm your account" ) ) ;
460
460
461
461
// Now we can login
@@ -466,21 +466,21 @@ await Task.WhenAll(
466
466
await page . ClickAsync ( "#login-submit" ) ;
467
467
468
468
// Need to navigate to fetch page
469
- await page . GoToAsync ( new Uri ( page . Url ) . GetLeftPart ( UriPartial . Authority ) ) ;
470
- Assert . Equal ( appName . Trim ( ) , ( await page . GetTitleAsync ( ) ) . Trim ( ) ) ;
469
+ await page . GotoAsync ( new Uri ( page . Url ) . GetLeftPart ( UriPartial . Authority ) ) ;
470
+ Assert . Equal ( appName . Trim ( ) , ( await page . TitleAsync ( ) ) . Trim ( ) ) ;
471
471
}
472
472
473
473
if ( ! skipFetchData )
474
474
{
475
475
// Can navigate to the 'fetch data' page
476
476
await Task . WhenAll (
477
- page . WaitForNavigationAsync ( "**/fetchdata" ) ,
477
+ page . WaitForNavigationAsync ( new ( ) { UrlString = "**/fetchdata" } ) ,
478
478
page . WaitForSelectorAsync ( "h1 >> text=Weather forecast" ) ,
479
479
page . ClickAsync ( "text=Fetch data" ) ) ;
480
480
481
481
// Asynchronously loads and displays the table of weather forecasts
482
482
await page . WaitForSelectorAsync ( "table>tbody>tr" ) ;
483
- Assert . Equal ( 5 , ( await page . QuerySelectorAllAsync ( "p+table>tbody>tr" ) ) . Count ( ) ) ;
483
+ Assert . Equal ( 5 , await page . Locator ( "p+table>tbody>tr" ) . CountAsync ( ) ) ;
484
484
}
485
485
}
486
486
0 commit comments