fix: replace isDisplayed() with viewport check in autoScrollIntoView()#2158
fix: replace isDisplayed() with viewport check in autoScrollIntoView()#2158mcollovati merged 3 commits intomainfrom
isDisplayed() with viewport check in autoScrollIntoView()#2158Conversation
…ew()`
`doubleClick()`, `click(x,y)` and `contextClick()` threw
`MoveTargetOutOfBoundsException` when the target element was inside a
scrollable container (e.g. vaadin-grid) but scrolled out of the visible
area. The root cause was that `autoScrollIntoView()` used
`wrappedElement.isDisplayed()` which returns true for elements that are
in the DOM but positioned outside the viewport.
Replace the check with `isElementInViewport()`, a JavaScript-based
visibility test that verifies the element's bounding rect intersects
the viewport and is not clipped by any scrollable ancestor. When the
element is outside the viewport, call `scrollIntoView({nearest})` to
bring it into view before Selenium's `Actions.moveToElement` reads the
element coordinates.
Also add a `scrollIntoView(Map)` public overload accepting scroll
options.
Fixes #2156
|
Running flow-components tests locally, I got the following errors Moved the PR to draft for further investigation |
|
Previously mentioned tests were just flaky. However, other tests are failing like Basically, the test cycle over elements that are currently rendered but not visible on screen without scrolling, and the use |
|
So the current situation is that there are several methods calling I wonder if we should make |
|
Why should |
|
They both will do scrollIntoView, but based on different conditions. One only needs isDisplayed to be true, the other needs the element to be effectively visible and intractable like in the browser |
…lement` Rename `autoScrollIntoView()` to `ensureVisible()` and `autoScrollIntoViewport()` to `ensureInteractable()` to better communicate intent rather than mechanism.
|
Tested the latest changes with flow-components and validation passed. |
|
Flow validation also passed locally |
… or viewport based on the use case (#2158) * fix: replace `isDisplayed()` with viewport check in `autoScrollIntoView()` `doubleClick()`, `click(x,y)` and `contextClick()` threw `MoveTargetOutOfBoundsException` when the target element was inside a scrollable container (e.g. vaadin-grid) but scrolled out of the visible area. The root cause was that `autoScrollIntoView()` used `wrappedElement.isDisplayed()` which returns true for elements that are in the DOM but positioned outside the viewport. Replace the check with `isElementInViewport()`, a JavaScript-based visibility test that verifies the element's bounding rect intersects the viewport and is not clipped by any scrollable ancestor. When the element is outside the viewport, call `scrollIntoView({nearest})` to bring it into view before Selenium's `Actions.moveToElement` reads the element coordinates. Also add a `scrollIntoView(Map)` public overload accepting scroll options. Fixes #2156 * refactor: rename scroll helpers to goal-oriented names in `TestBenchElement` Rename `autoScrollIntoView()` to `ensureVisible()` and `autoScrollIntoViewport()` to `ensureInteractable()` to better communicate intent rather than mechanism. * use Selenium API to scroll into viewport
…) (CP: 9.6) (#2164) * fix: refactor `autoScrollIntoView()` feature to check `isDisplayed()` or viewport based on the use case (#2158) * fix: replace `isDisplayed()` with viewport check in `autoScrollIntoView()` `doubleClick()`, `click(x,y)` and `contextClick()` threw `MoveTargetOutOfBoundsException` when the target element was inside a scrollable container (e.g. vaadin-grid) but scrolled out of the visible area. The root cause was that `autoScrollIntoView()` used `wrappedElement.isDisplayed()` which returns true for elements that are in the DOM but positioned outside the viewport. Replace the check with `isElementInViewport()`, a JavaScript-based visibility test that verifies the element's bounding rect intersects the viewport and is not clipped by any scrollable ancestor. When the element is outside the viewport, call `scrollIntoView({nearest})` to bring it into view before Selenium's `Actions.moveToElement` reads the element coordinates. Also add a `scrollIntoView(Map)` public overload accepting scroll options. Fixes #2156 * refactor: rename scroll helpers to goal-oriented names in `TestBenchElement` Rename `autoScrollIntoView()` to `ensureVisible()` and `autoScrollIntoViewport()` to `ensureInteractable()` to better communicate intent rather than mechanism. * use Selenium API to scroll into viewport * fix: do not use getCoordinates().inViewPort() to scroll into view (#2161) Calling getCoordinates().inViewPort() seems to always scroll even if the element is alredy visibile and interactable. This migth cause issue in existing tests. This change partially reverts the previous fix to just use scrollIntoView after viewport check.
…) (CP: 9.6) (#2164) * fix: refactor `autoScrollIntoView()` feature to check `isDisplayed()` or viewport based on the use case (#2158) * fix: replace `isDisplayed()` with viewport check in `autoScrollIntoView()` `doubleClick()`, `click(x,y)` and `contextClick()` threw `MoveTargetOutOfBoundsException` when the target element was inside a scrollable container (e.g. vaadin-grid) but scrolled out of the visible area. The root cause was that `autoScrollIntoView()` used `wrappedElement.isDisplayed()` which returns true for elements that are in the DOM but positioned outside the viewport. Replace the check with `isElementInViewport()`, a JavaScript-based visibility test that verifies the element's bounding rect intersects the viewport and is not clipped by any scrollable ancestor. When the element is outside the viewport, call `scrollIntoView({nearest})` to bring it into view before Selenium's `Actions.moveToElement` reads the element coordinates. Also add a `scrollIntoView(Map)` public overload accepting scroll options. Fixes #2156 * refactor: rename scroll helpers to goal-oriented names in `TestBenchElement` Rename `autoScrollIntoView()` to `ensureVisible()` and `autoScrollIntoViewport()` to `ensureInteractable()` to better communicate intent rather than mechanism. * use Selenium API to scroll into viewport * fix: do not use getCoordinates().inViewPort() to scroll into view (#2161) Calling getCoordinates().inViewPort() seems to always scroll even if the element is alredy visibile and interactable. This migth cause issue in existing tests. This change partially reverts the previous fix to just use scrollIntoView after viewport check.
…) (CP: 9.6) (#2164) (#2166) * fix: refactor `autoScrollIntoView()` feature to check `isDisplayed()` or viewport based on the use case (#2158) * fix: replace `isDisplayed()` with viewport check in `autoScrollIntoView()` `doubleClick()`, `click(x,y)` and `contextClick()` threw `MoveTargetOutOfBoundsException` when the target element was inside a scrollable container (e.g. vaadin-grid) but scrolled out of the visible area. The root cause was that `autoScrollIntoView()` used `wrappedElement.isDisplayed()` which returns true for elements that are in the DOM but positioned outside the viewport. Replace the check with `isElementInViewport()`, a JavaScript-based visibility test that verifies the element's bounding rect intersects the viewport and is not clipped by any scrollable ancestor. When the element is outside the viewport, call `scrollIntoView({nearest})` to bring it into view before Selenium's `Actions.moveToElement` reads the element coordinates. Also add a `scrollIntoView(Map)` public overload accepting scroll options. Fixes #2156 * refactor: rename scroll helpers to goal-oriented names in `TestBenchElement` Rename `autoScrollIntoView()` to `ensureVisible()` and `autoScrollIntoViewport()` to `ensureInteractable()` to better communicate intent rather than mechanism. * use Selenium API to scroll into viewport * fix: do not use getCoordinates().inViewPort() to scroll into view (#2161) Calling getCoordinates().inViewPort() seems to always scroll even if the element is alredy visibile and interactable. This migth cause issue in existing tests. This change partially reverts the previous fix to just use scrollIntoView after viewport check. Co-authored-by: Marco Collovati <marco@vaadin.com>
doubleClick(),click(x,y)andcontextClick()threwMoveTargetOutOfBoundsExceptionwhen the target element was inside a scrollable container (e.g. vaadin-grid) but scrolled out of the visible area. The root cause was thatautoScrollIntoView()usedwrappedElement.isDisplayed()which returns true for elements that are in the DOM but positioned outside the viewport.Replace the check with
isElementInViewport(), a JavaScript-based visibility test that verifies the element's bounding rect intersects the viewport and is not clipped by any scrollable ancestor. When the element is outside the viewport, callscrollIntoView({nearest})to bring it into view before Selenium'sActions.moveToElementreads the element coordinates.Also add a
scrollIntoView(Map)public overload accepting scroll options.Fixes #2156