Skip to content

Commit

Permalink
fix: add check prev element
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelMor25 committed Sep 27, 2024
1 parent 4c9f03b commit 72f2f88
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/client/automation/playback/move/event-sequence/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export default class MoveEventSequenceBase {
}

run (currentElement, prevElement, options, dragElement, dragDataStore) {

const prevElementInDocument = prevElement && domUtils.isElementInDocument(prevElement);

const prevElementInRemovedIframe = prevElement && domUtils.isElementInIframe(prevElement) &&
!domUtils.getIframeByElement(prevElement);

if (!prevElementInDocument || prevElementInRemovedIframe)
prevElement = null;

const elementChanged = currentElement !== prevElement;
const commonAncestor = elementChanged ? domUtils.getCommonAncestor(currentElement, prevElement) : null;

Expand Down
17 changes: 17 additions & 0 deletions test/functional/fixtures/regression/gh-8264/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<a href="#" id="link">Click me to remove</a>
<button id="btn">Button</button>

<script>
document.getElementById('link').addEventListener('click', function(event) {
event.preventDefault(); // Prevent the default link behavior
this.remove(); // Remove the link element from the page
});
</script>
</body>
</html>
5 changes: 5 additions & 0 deletions test/functional/fixtures/regression/gh-8264/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('[Regression](GH-8264)', function () {
it('Test should not fails with Uncaught object error on leaveElement when the prevElement is removed from the DOM', function () {
return runTests('testcafe-fixtures/index.js', 'Callsite Issue', { only: 'chrome' });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

fixture('GH-8264 - Callsite Issue')
.page`http://localhost:3000/fixtures/regression/gh-8264/pages/index.html`;

test('Callsite Issue', async t => {
await t
.click('#link')
.click('#btn');
});

0 comments on commit 72f2f88

Please sign in to comment.