-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Fix NavMenuHighlightsCurrentLocation in headless mode #63583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix NavMenuHighlightsCurrentLocation in headless mode #63583
Conversation
…ow size explictly, add SetWindowSize extension method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a failing test in headless mode by addressing viewport size issues that cause sidebar elements to be hidden, leading to empty text properties in assertions.
Key changes:
- Adds a
SetWindowSize
extension method forIWebDriver
to standardize window size manipulation - Sets explicit window size (1920x1080) in the failing
NavMenuHighlightsCurrentLocation
test - Refactors existing window size manipulations to use the new extension method
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/Shared/E2ETesting/WebDriverExtensions.cs | Adds new SetWindowSize extension method for consistent window size management |
src/Components/test/E2ETest/Tests/StandaloneAppTest.cs | Sets explicit window size to prevent sidebar visibility issues in headless mode |
src/Components/test/E2ETest/Tests/ComponentRenderingTestBase.cs | Refactors three existing tests to use the new SetWindowSize extension method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see any tests that would manipulate with window size or would rely on a specific view, so setting it globally for all sounds like a good idea.
There are few in |
// 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.)
34dc672
to
27c3f2f
Compare
27c3f2f
to
46df082
Compare
We also decided to add a mechanism for resetting the window size between individual tests to prevent unexpected dependencies between tests in the future. |
/backport to release/10.0 |
Started backporting to release/10.0: https://github.com/dotnet/aspnetcore/actions/runs/17613935455 |
This test is failing in CI and when run locally without debugger. The reason is that in the headless mode the window width is too small and the sidebar UI is hidden. This causes visibility-sensitive properties such as
IWebElement.Text
to return empty strings for hidden elements from the sidebar, causing assertions to fail.The PR solves the issue by explicitly setting the window size for this particular test. We can discuss if the preferred solution is to set the window size globally when creating the test browser in the headless mode. Alternatively, the test could be fixed by using a visibility-independent API such as
IWebElement.GetDomProperty("innerText")
for reading the relevant values. However, using a realistic window size seems more appropriate for an E2E test.The PR also adds the
IWebDriver.SetWindowSize
extension method. A few existing cases where window size is manipulated were refactored to use this method in order to make such cases more discoverable.Fixes #54497