1010namespace Microsoft . AspNetCore . Components . E2ETest . Tests ;
1111
1212public class StandaloneAppTest
13- : ServerTestBase < BlazorWasmTestAppFixture < StandaloneApp . Program > > , IDisposable
13+ : ServerTestBase < BlazorWasmTestAppFixture < StandaloneApp . Program > >
1414{
1515 public StandaloneAppTest (
1616 BrowserFixture browserFixture ,
@@ -22,6 +22,12 @@ public StandaloneAppTest(
2222
2323 protected override void InitializeAsyncCore ( )
2424 {
25+ // The sidebar is hidden if the screen is too narrow.
26+ // Without setting the window size explicitly, visibility-sensitive properties (e.g. IWebElement.Text)
27+ // and element finders (e.g. By.LinkText) can behave unexpectedly, causing assertions to fail.
28+ // In particular, this happens in the headless mode (used when running without debugger).
29+ Browser . SetWindowSize ( 1920 , 1080 ) ;
30+
2531 Navigate ( "/" ) ;
2632 WaitUntilLoaded ( ) ;
2733 }
@@ -44,12 +50,6 @@ public void NavMenuHighlightsCurrentLocation()
4450 var activeNavLinksSelector = By . CssSelector ( ".sidebar a.active" ) ;
4551 var mainHeaderSelector = By . TagName ( "h1" ) ;
4652
47- // The sidebar is hidden if the screen is too narrow.
48- // Without setting the window size explicitly, visibility-sensitive properties
49- // such as IWebElement.Text can return empty strings, causing assertions to fail.
50- // In particular, this happens in the headless mode (used when running without debugger).
51- Browser . SetWindowSize ( 1920 , 1080 ) ;
52-
5353 // Verify we start at home, with the home link highlighted
5454 Assert . Equal ( "Hello, world!" , Browser . Exists ( mainHeaderSelector ) . Text ) ;
5555 Assert . Collection ( Browser . FindElements ( activeNavLinksSelector ) ,
@@ -132,10 +132,12 @@ private void WaitUntilLoaded()
132132 Browser . NotEqual ( "Loading..." , ( ) => app . Text ) ;
133133 }
134134
135- public void Dispose ( )
135+ public override async Task DisposeAsync ( )
136136 {
137137 // Make the tests run faster by navigating back to the home page when we are done
138138 // If we don't, then the next test will reload the whole page before it starts
139139 Browser . Exists ( By . LinkText ( "Home" ) ) . Click ( ) ;
140+
141+ await base . DisposeAsync ( ) ;
140142 }
141143}
0 commit comments