Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public void CanUseJsInteropToReferenceElements()
[Fact]
public void CanUseFocusExtensionToFocusElement()
{
Browser.Manage().Window.Size = new System.Drawing.Size(100, 300);
Browser.SetWindowSize(100, 300);
var appElement = Browser.MountTestComponent<ElementFocusComponent>();

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

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

var buttonElement = Browser.Exists(By.Id("focus-button-prevented"));
Expand Down
6 changes: 6 additions & 0 deletions src/Components/test/E2ETest/Tests/StandaloneAppTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public void NavMenuHighlightsCurrentLocation()
var activeNavLinksSelector = By.CssSelector(".sidebar a.active");
var mainHeaderSelector = By.TagName("h1");

// The sidebar is hidden if the screen is too narrow.
// Without setting the window size explicitly, visibility-sensitive properties
// such as IWebElement.Text can return empty strings, causing assertions to fail.
// In particular, this happens in the headless mode (used when running without debugger).
Browser.SetWindowSize(1920, 1080);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this doesn't fail if the physical screen size is lower than this right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on docs and empirical testing:

  • In GUI mode the size is clamped so that the window fits into the screen.
  • In headless mode the window size is set to whatever is specified and the rest of the test executes fine. (I tried 10000x10000 and had no issues.)


// Verify we start at home, with the home link highlighted
Assert.Equal("Hello, world!", Browser.Exists(mainHeaderSelector).Text);
Assert.Collection(Browser.FindElements(activeNavLinksSelector),
Expand Down
7 changes: 7 additions & 0 deletions src/Shared/E2ETesting/WebDriverExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@ private static bool ShouldIgnore(LogEntry entry)

return false;
}

public static void SetWindowSize(this IWebDriver driver, int width, int height)
{
ArgumentNullException.ThrowIfNull(driver);

driver.Manage().Window.Size = new System.Drawing.Size(width, height);
}
}
Loading