Skip to content

Commit 33edda9

Browse files
committed
Fix NavMenuHighlightsCurrentLocation in headless mode by setting window size explictly, add SetWindowSize extension method
1 parent 963ca78 commit 33edda9

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/Components/test/E2ETest/Tests/ComponentRenderingTestBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public void CanUseJsInteropToReferenceElements()
374374
[Fact]
375375
public void CanUseFocusExtensionToFocusElement()
376376
{
377-
Browser.Manage().Window.Size = new System.Drawing.Size(100, 300);
377+
Browser.SetWindowSize(100, 300);
378378
var appElement = Browser.MountTestComponent<ElementFocusComponent>();
379379

380380
// y scroll position before click
@@ -408,7 +408,7 @@ public void CanUseFocusExtensionToFocusElement()
408408
[Fact]
409409
public void CanUseFocusExtensionToFocusSvgElement()
410410
{
411-
Browser.Manage().Window.Size = new System.Drawing.Size(100, 300);
411+
Browser.SetWindowSize(100, 300);
412412
var appElement = Browser.MountTestComponent<SvgFocusComponent>();
413413

414414
var buttonElement = appElement.FindElement(By.Id("focus-button"));
@@ -430,7 +430,7 @@ public void CanUseFocusExtensionToFocusSvgElement()
430430
[Fact]
431431
public void CanUseFocusExtensionToFocusElementPreventScroll()
432432
{
433-
Browser.Manage().Window.Size = new System.Drawing.Size(600, 600);
433+
Browser.SetWindowSize(600, 600);
434434
var appElement = Browser.MountTestComponent<ElementFocusComponent>();
435435

436436
var buttonElement = Browser.Exists(By.Id("focus-button-prevented"));

src/Components/test/E2ETest/Tests/StandaloneAppTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public void NavMenuHighlightsCurrentLocation()
4444
var activeNavLinksSelector = By.CssSelector(".sidebar a.active");
4545
var mainHeaderSelector = By.TagName("h1");
4646

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+
4753
// Verify we start at home, with the home link highlighted
4854
Assert.Equal("Hello, world!", Browser.Exists(mainHeaderSelector).Text);
4955
Assert.Collection(Browser.FindElements(activeNavLinksSelector),

src/Shared/E2ETesting/WebDriverExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,11 @@ private static bool ShouldIgnore(LogEntry entry)
5151

5252
return false;
5353
}
54+
55+
public static void SetWindowSize(this IWebDriver driver, int width, int height)
56+
{
57+
ArgumentNullException.ThrowIfNull(driver);
58+
59+
driver.Manage().Window.Size = new System.Drawing.Size(width, height);
60+
}
5461
}

0 commit comments

Comments
 (0)