From 66460e4bcc899ac3e576059d4ccab640cba78e99 Mon Sep 17 00:00:00 2001 From: Bayheck Date: Thu, 31 Oct 2024 17:46:24 +0500 Subject: [PATCH 1/7] fix: drag and click --- src/client/automation/playback/drag/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/automation/playback/drag/base.js b/src/client/automation/playback/drag/base.js index 862191e6451..b7037f39637 100644 --- a/src/client/automation/playback/drag/base.js +++ b/src/client/automation/playback/drag/base.js @@ -126,7 +126,7 @@ export default class DragAutomationBase extends VisibleElementAutomation { }) .then(element => { //B231323 - if (topElement && element === topElement && !this.dragAndDropState.enabled) + if (topElement && element === topElement && !this.dragAndDropState.enabled && this.dragAndDropState.element) eventSimulator.click(topElement, options); }); }); From eca82ad9bfd3071c53b02217acd835b6a9694bea Mon Sep 17 00:00:00 2001 From: Bayheck Date: Tue, 5 Nov 2024 14:46:41 +0500 Subject: [PATCH 2/7] fix --- src/client/automation/playback/drag/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/automation/playback/drag/base.js b/src/client/automation/playback/drag/base.js index b7037f39637..b55d4277454 100644 --- a/src/client/automation/playback/drag/base.js +++ b/src/client/automation/playback/drag/base.js @@ -126,7 +126,7 @@ export default class DragAutomationBase extends VisibleElementAutomation { }) .then(element => { //B231323 - if (topElement && element === topElement && !this.dragAndDropState.enabled && this.dragAndDropState.element) + if (topElement && element === topElement && !this.dragAndDropState.enabled && this.dragAndDropState.dropAllowed) eventSimulator.click(topElement, options); }); }); From 79520c899c76513841d8f49521dfe9b80e55ac8b Mon Sep 17 00:00:00 2001 From: Bayheck Date: Tue, 5 Nov 2024 17:58:11 +0500 Subject: [PATCH 3/7] testing --- src/client/automation/playback/drag/base.js | 2 +- .../automation/playback/drag/to-element.js | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/client/automation/playback/drag/base.js b/src/client/automation/playback/drag/base.js index b55d4277454..862191e6451 100644 --- a/src/client/automation/playback/drag/base.js +++ b/src/client/automation/playback/drag/base.js @@ -126,7 +126,7 @@ export default class DragAutomationBase extends VisibleElementAutomation { }) .then(element => { //B231323 - if (topElement && element === topElement && !this.dragAndDropState.enabled && this.dragAndDropState.dropAllowed) + if (topElement && element === topElement && !this.dragAndDropState.enabled) eventSimulator.click(topElement, options); }); }); diff --git a/src/client/automation/playback/drag/to-element.js b/src/client/automation/playback/drag/to-element.js index 43268039236..cef28fafe78 100644 --- a/src/client/automation/playback/drag/to-element.js +++ b/src/client/automation/playback/drag/to-element.js @@ -1,8 +1,13 @@ import testCafeCore from '../../deps/testcafe-core'; import DragAutomationBase from './base'; import { getOffsetOptions } from '../../../core/utils/offsets'; +import getElementFromPoint from '../../get-element'; +import cursor from '../../cursor'; +import hammerhead from '../../deps/hammerhead'; const positionUtils = testCafeCore.positionUtils; +const eventSimulator = hammerhead.eventSandbox.eventSimulator; +const extend = hammerhead.utils.extend; export default class DragToElementAutomation extends DragAutomationBase { @@ -26,4 +31,39 @@ export default class DragToElementAutomation extends DragAutomationBase { return { element, offsets, endPoint }; } + + _mouseup () { + return cursor + .buttonUp() + .then(() => { + const point = positionUtils.offsetToClientCoords(this.endPoint); + let topElement = null; + const options = extend({ + clientX: point.x, + clientY: point.y, + }, this.modifiers); + + return getElementFromPoint(point) + .then(element => { + topElement = element; + + if (!topElement) + return topElement; + + if (this.dragAndDropState.enabled) { + options.dataTransfer = this.dragAndDropState.dataTransfer; + + if (this.dragAndDropState.dropAllowed) + eventSimulator.drop(topElement, options); + + eventSimulator.dragend(this.dragAndDropState.element, options); + this.dragAndDropState.dataStore.setProtectedMode(); + } + else + eventSimulator[this.upEvent](topElement, options); + + return getElementFromPoint(point); + }); + }); + } } From e4505f63edbb46506a2d36e11ca3e9b978797c6e Mon Sep 17 00:00:00 2001 From: Bayheck Date: Tue, 5 Nov 2024 19:15:39 +0500 Subject: [PATCH 4/7] refactor --- src/client/automation/playback/drag/base.js | 5 ++- .../automation/playback/drag/to-element.js | 42 +------------------ 2 files changed, 5 insertions(+), 42 deletions(-) diff --git a/src/client/automation/playback/drag/base.js b/src/client/automation/playback/drag/base.js index 862191e6451..eb83edc3f17 100644 --- a/src/client/automation/playback/drag/base.js +++ b/src/client/automation/playback/drag/base.js @@ -35,7 +35,8 @@ export default class DragAutomationBase extends VisibleElementAutomation { this.downEvent = featureDetection.isTouchDevice ? 'touchstart' : 'mousedown'; this.upEvent = featureDetection.isTouchDevice ? 'touchend' : 'mouseup'; - this.dragAndDropState = null; + this.dragAndDropState = null; + this.shouldClickOnMouseUp = true; } _getEndPoint () { @@ -126,7 +127,7 @@ export default class DragAutomationBase extends VisibleElementAutomation { }) .then(element => { //B231323 - if (topElement && element === topElement && !this.dragAndDropState.enabled) + if (this.shouldClickOnMouseUp && topElement && element === topElement && !this.dragAndDropState.enabled) eventSimulator.click(topElement, options); }); }); diff --git a/src/client/automation/playback/drag/to-element.js b/src/client/automation/playback/drag/to-element.js index cef28fafe78..cad6bf9d04a 100644 --- a/src/client/automation/playback/drag/to-element.js +++ b/src/client/automation/playback/drag/to-element.js @@ -1,13 +1,8 @@ import testCafeCore from '../../deps/testcafe-core'; import DragAutomationBase from './base'; import { getOffsetOptions } from '../../../core/utils/offsets'; -import getElementFromPoint from '../../get-element'; -import cursor from '../../cursor'; -import hammerhead from '../../deps/hammerhead'; const positionUtils = testCafeCore.positionUtils; -const eventSimulator = hammerhead.eventSandbox.eventSimulator; -const extend = hammerhead.utils.extend; export default class DragToElementAutomation extends DragAutomationBase { @@ -17,6 +12,8 @@ export default class DragToElementAutomation extends DragAutomationBase { this.destinationElement = destinationElement; this.destinationOffsetX = dragToElementOptions.destinationOffsetX; this.destinationOffsetY = dragToElementOptions.destinationOffsetY; + + this.shouldClickOnMouseUp = false; } async _getDestination () { @@ -31,39 +28,4 @@ export default class DragToElementAutomation extends DragAutomationBase { return { element, offsets, endPoint }; } - - _mouseup () { - return cursor - .buttonUp() - .then(() => { - const point = positionUtils.offsetToClientCoords(this.endPoint); - let topElement = null; - const options = extend({ - clientX: point.x, - clientY: point.y, - }, this.modifiers); - - return getElementFromPoint(point) - .then(element => { - topElement = element; - - if (!topElement) - return topElement; - - if (this.dragAndDropState.enabled) { - options.dataTransfer = this.dragAndDropState.dataTransfer; - - if (this.dragAndDropState.dropAllowed) - eventSimulator.drop(topElement, options); - - eventSimulator.dragend(this.dragAndDropState.element, options); - this.dragAndDropState.dataStore.setProtectedMode(); - } - else - eventSimulator[this.upEvent](topElement, options); - - return getElementFromPoint(point); - }); - }); - } } From d9f8742471abc3beedb9dbeb332f8a5de9885510 Mon Sep 17 00:00:00 2001 From: Bayheck Date: Wed, 6 Nov 2024 16:02:49 +0500 Subject: [PATCH 5/7] test: added test for gh-8250 --- .../fixtures/regression/gh-8250/pages/index.html | 11 +++++++++++ test/functional/fixtures/regression/gh-8250/test.js | 5 +++++ .../regression/gh-8250/testcafe-fixtures/index.js | 12 ++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 test/functional/fixtures/regression/gh-8250/pages/index.html create mode 100644 test/functional/fixtures/regression/gh-8250/test.js create mode 100644 test/functional/fixtures/regression/gh-8250/testcafe-fixtures/index.js diff --git a/test/functional/fixtures/regression/gh-8250/pages/index.html b/test/functional/fixtures/regression/gh-8250/pages/index.html new file mode 100644 index 00000000000..174a0ff9340 --- /dev/null +++ b/test/functional/fixtures/regression/gh-8250/pages/index.html @@ -0,0 +1,11 @@ + + + + + gh-8250 + + +

Example

+ + + diff --git a/test/functional/fixtures/regression/gh-8250/test.js b/test/functional/fixtures/regression/gh-8250/test.js new file mode 100644 index 00000000000..2d51acd015f --- /dev/null +++ b/test/functional/fixtures/regression/gh-8250/test.js @@ -0,0 +1,5 @@ +describe('[Regression](GH-8250)', function () { + it('Click should not be called after dragToElement', function () { + return runTests('testcafe-fixtures/index.js', 'Click should not be called', { only: 'chrome' }); + }); +}); diff --git a/test/functional/fixtures/regression/gh-8250/testcafe-fixtures/index.js b/test/functional/fixtures/regression/gh-8250/testcafe-fixtures/index.js new file mode 100644 index 00000000000..4ccdff3b9de --- /dev/null +++ b/test/functional/fixtures/regression/gh-8250/testcafe-fixtures/index.js @@ -0,0 +1,12 @@ +import { Selector } from 'testcafe'; + +fixture('GH-8250- Click should not be called after dragToElement') + .page`http://localhost:3000/fixtures/regression/gh-8250/pages/index.html`; + +test('Click should not be called', async t => { + const h1Label = Selector('h1').withText('Example'); + const radioInput = Selector('#example'); + + await t.dragToElement(h1Label, radioInput); + await t.expect(radioInput.checked).eql(false); +}); From 86419baf473f99507aa3a2686d23b0bdbd05eb08 Mon Sep 17 00:00:00 2001 From: Bayheck Date: Mon, 18 Nov 2024 16:36:21 +0500 Subject: [PATCH 6/7] fix: pr comments fixed --- src/client/automation/playback/drag/base.js | 9 ++++----- src/client/automation/playback/drag/to-element.js | 2 -- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/client/automation/playback/drag/base.js b/src/client/automation/playback/drag/base.js index eb83edc3f17..a4ccb73b4c9 100644 --- a/src/client/automation/playback/drag/base.js +++ b/src/client/automation/playback/drag/base.js @@ -35,8 +35,7 @@ export default class DragAutomationBase extends VisibleElementAutomation { this.downEvent = featureDetection.isTouchDevice ? 'touchstart' : 'mousedown'; this.upEvent = featureDetection.isTouchDevice ? 'touchend' : 'mouseup'; - this.dragAndDropState = null; - this.shouldClickOnMouseUp = true; + this.dragAndDropState = null; } _getEndPoint () { @@ -93,7 +92,7 @@ export default class DragAutomationBase extends VisibleElementAutomation { }); } - _mouseup () { + _mouseup (eventArgs) { return cursor .buttonUp() .then(() => { @@ -127,7 +126,7 @@ export default class DragAutomationBase extends VisibleElementAutomation { }) .then(element => { //B231323 - if (this.shouldClickOnMouseUp && topElement && element === topElement && !this.dragAndDropState.enabled) + if (topElement && element === topElement && !this.dragAndDropState.enabled && element === eventArgs.element) eventSimulator.click(topElement, options); }); }); @@ -153,6 +152,6 @@ export default class DragAutomationBase extends VisibleElementAutomation { return Promise.all([delay(this.automationSettings.mouseActionStepDelay), this._mousedown(eventArgs)]); }) .then(() => this._drag()) - .then(() => this._mouseup()); + .then(() => this._mouseup(eventArgs)); } } diff --git a/src/client/automation/playback/drag/to-element.js b/src/client/automation/playback/drag/to-element.js index cad6bf9d04a..43268039236 100644 --- a/src/client/automation/playback/drag/to-element.js +++ b/src/client/automation/playback/drag/to-element.js @@ -12,8 +12,6 @@ export default class DragToElementAutomation extends DragAutomationBase { this.destinationElement = destinationElement; this.destinationOffsetX = dragToElementOptions.destinationOffsetX; this.destinationOffsetY = dragToElementOptions.destinationOffsetY; - - this.shouldClickOnMouseUp = false; } async _getDestination () { From 14f25695264db180f2bb5bb045974aec213b9f33 Mon Sep 17 00:00:00 2001 From: Bayheck Date: Mon, 18 Nov 2024 16:39:58 +0500 Subject: [PATCH 7/7] refactor: renamed vars --- src/client/automation/playback/drag/base.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/automation/playback/drag/base.js b/src/client/automation/playback/drag/base.js index a4ccb73b4c9..34e5c2e187d 100644 --- a/src/client/automation/playback/drag/base.js +++ b/src/client/automation/playback/drag/base.js @@ -92,7 +92,7 @@ export default class DragAutomationBase extends VisibleElementAutomation { }); } - _mouseup (eventArgs) { + _mouseup (draggedElement) { return cursor .buttonUp() .then(() => { @@ -126,7 +126,7 @@ export default class DragAutomationBase extends VisibleElementAutomation { }) .then(element => { //B231323 - if (topElement && element === topElement && !this.dragAndDropState.enabled && element === eventArgs.element) + if (topElement && element === topElement && !this.dragAndDropState.enabled && element === draggedElement) eventSimulator.click(topElement, options); }); }); @@ -152,6 +152,6 @@ export default class DragAutomationBase extends VisibleElementAutomation { return Promise.all([delay(this.automationSettings.mouseActionStepDelay), this._mousedown(eventArgs)]); }) .then(() => this._drag()) - .then(() => this._mouseup(eventArgs)); + .then(() => this._mouseup(eventArgs.element)); } }