Skip to content

Commit 30c6212

Browse files
mcollovatiZheSun88
andauthored
revert: Revert "fix: Fix click count in TestBenchElement#click() (#2120) (#2125) (#2130)
* revert: Revert "fix: Fix click count in TestBenchElement#click() (#2120) (#2125)" This reverts commit 7ec04dc. * update workflow for mainteannce branch --------- Co-authored-by: Zhe Sun <31067185+ZheSun88@users.noreply.github.com>
1 parent 7ec04dc commit 30c6212

4 files changed

Lines changed: 24 additions & 174 deletions

File tree

.github/workflows/validation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: TestBench Validation
22

33
on:
4-
pull_request_target:
4+
pull_request:
55
branches:
6-
- main
6+
- 10.0
77
types: [opened, synchronize, reopened, edited]
88
workflow_dispatch:
99

vaadin-testbench-integration-tests/src/main/java/com/vaadin/testUI/ButtonView.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

vaadin-testbench-integration-tests/src/test/java/com/vaadin/tests/elements/ButtonIT.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

vaadin-testbench-shared/src/main/java/com/vaadin/testbench/TestBenchElement.java

Lines changed: 22 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,23 @@ public boolean isFocused() {
191191

192192
@Override
193193
public void click() {
194-
autoScrollIntoView();
195-
waitForVaadin();
196-
new Actions(getDriver()).click(wrappedElement).build().perform();
194+
// JS call to click does not focus element, hence ensure focus
195+
focus();
196+
try {
197+
// Avoid strange "element not clickable at point" problems
198+
callFunction("click");
199+
} catch (Exception e) {
200+
if (e.getMessage()
201+
.contains("Inspected target navigated or closed")) {
202+
// This happens with chromedriver although e.g. navigation
203+
// succeeds
204+
return;
205+
}
206+
// SVG elements and maybe others do not have a 'click' method
207+
autoScrollIntoView();
208+
waitForVaadin();
209+
wrappedElement.click();
210+
}
197211
}
198212

199213
@Override
@@ -349,20 +363,12 @@ public void click(int x, int y, Keys... modifiers) {
349363
actions.build().perform();
350364
}
351365

352-
/**
353-
* Performs a double-click action on this element.
354-
*
355-
* @see click()
356-
*/
357366
public void doubleClick() {
358367
autoScrollIntoView();
359368
waitForVaadin();
360369
new Actions(getDriver()).doubleClick(wrappedElement).build().perform();
361370
}
362371

363-
/**
364-
* Performs a context-click (right click) action on this element.
365-
*/
366372
public void contextClick() {
367373
autoScrollIntoView();
368374
waitForVaadin();
@@ -514,20 +520,7 @@ public boolean compareScreen(BufferedImage reference, String referenceName)
514520
(TakesScreenshot) this, (HasCapabilities) getDriver());
515521
}
516522

517-
/**
518-
* Scrolls the element into the visible area of the browser window with the
519-
* given options. Check
520-
* https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
521-
* for more information on the options.
522-
*
523-
* @param options
524-
* the parameters for scrolling into view
525-
*/
526-
public void scrollIntoView(Map<String, Object> options) {
527-
callFunction("scrollIntoView", options);
528-
}
529-
530-
/**
523+
/***
531524
* Scrolls the element into the visible area of the browser window
532525
*/
533526
public void scrollIntoView() {
@@ -541,65 +534,15 @@ public void scrollIntoView() {
541534
*/
542535
private void autoScrollIntoView() {
543536
try {
544-
if (getCommandExecutor().isAutoScrollIntoView()
545-
&& !isElementInViewport()) {
546-
var params = Map.<String, Object> of("block", "end", "inline",
547-
"end");
548-
scrollIntoView(params);
537+
if (getCommandExecutor().isAutoScrollIntoView()) {
538+
if (!wrappedElement.isDisplayed()) {
539+
scrollIntoView();
540+
}
549541
}
550542
} catch (Exception e) {
551543
}
552544
}
553545

554-
private boolean isElementInViewport() {
555-
try {
556-
Boolean result = (Boolean) executeScript(
557-
"""
558-
function isVisible(elem) {
559-
// Check if element has zero dimensions (truly hidden)
560-
if (!elem.offsetParent && elem.offsetWidth === 0 && elem.offsetHeight === 0) {
561-
return false;
562-
}
563-
564-
var rect = elem.getBoundingClientRect();
565-
if (rect.width === 0 || rect.height === 0) {
566-
return false;
567-
}
568-
569-
// Check if element intersects with viewport
570-
var windowHeight = window.innerHeight || document.documentElement.clientHeight;
571-
var windowWidth = window.innerWidth || document.documentElement.clientWidth;
572-
if (rect.bottom < 0 || rect.top > windowHeight || rect.right < 0 || rect.left > windowWidth) {
573-
return false;
574-
}
575-
576-
// Check if clipped by any scrollable ancestor
577-
var parent = elem.parentElement;
578-
while (parent && parent !== document.body) {
579-
var style = window.getComputedStyle(parent);
580-
var overflow = style.overflow + style.overflowX + style.overflowY;
581-
582-
if (overflow.includes('hidden') || overflow.includes('scroll') || overflow.includes('auto')) {
583-
var parentRect = parent.getBoundingClientRect();
584-
// Check if element is outside parent's visible area
585-
if (rect.bottom < parentRect.top || rect.top > parentRect.bottom ||
586-
rect.right < parentRect.left || rect.left > parentRect.right) {
587-
return false;
588-
}
589-
}
590-
parent = parent.parentElement;
591-
}
592-
return true;
593-
}
594-
return isVisible(arguments[0]);
595-
""",
596-
this);
597-
return result != null && result;
598-
} catch (Exception e) {
599-
return true; // Assume visible on error
600-
}
601-
}
602-
603546
/**
604547
* Waits the given number of seconds for the given condition to become
605548
* neither null nor false. {@link NotFoundException}s are ignored by

0 commit comments

Comments
 (0)