10
10
namespace Microsoft . AspNetCore . Components . E2ETest . Tests ;
11
11
12
12
public class StandaloneAppTest
13
- : ServerTestBase < BlazorWasmTestAppFixture < StandaloneApp . Program > > , IDisposable
13
+ : ServerTestBase < BlazorWasmTestAppFixture < StandaloneApp . Program > >
14
14
{
15
15
public StandaloneAppTest (
16
16
BrowserFixture browserFixture ,
@@ -22,6 +22,12 @@ public StandaloneAppTest(
22
22
23
23
protected override void InitializeAsyncCore ( )
24
24
{
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
+
25
31
Navigate ( "/" ) ;
26
32
WaitUntilLoaded ( ) ;
27
33
}
@@ -44,12 +50,6 @@ public void NavMenuHighlightsCurrentLocation()
44
50
var activeNavLinksSelector = By . CssSelector ( ".sidebar a.active" ) ;
45
51
var mainHeaderSelector = By . TagName ( "h1" ) ;
46
52
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
-
53
53
// Verify we start at home, with the home link highlighted
54
54
Assert . Equal ( "Hello, world!" , Browser . Exists ( mainHeaderSelector ) . Text ) ;
55
55
Assert . Collection ( Browser . FindElements ( activeNavLinksSelector ) ,
@@ -132,10 +132,12 @@ private void WaitUntilLoaded()
132
132
Browser . NotEqual ( "Loading..." , ( ) => app . Text ) ;
133
133
}
134
134
135
- public void Dispose ( )
135
+ public override Task DisposeAsync ( )
136
136
{
137
137
// Make the tests run faster by navigating back to the home page when we are done
138
138
// If we don't, then the next test will reload the whole page before it starts
139
139
Browser . Exists ( By . LinkText ( "Home" ) ) . Click ( ) ;
140
+
141
+ return base . DisposeAsync ( ) ;
140
142
}
141
143
}
0 commit comments