diff --git a/src/client/automation/utils/utils.js b/src/client/automation/utils/utils.js index 44084693097..557e2c5999d 100644 --- a/src/client/automation/utils/utils.js +++ b/src/client/automation/utils/utils.js @@ -59,6 +59,10 @@ export function focusAndSetSelection (element, simulateFocus, caretPos) { return; } + var focusWithSilentMode = !simulateFocus; + var focusForMouseEvent = true; + var preventScrolling = false; + if (!isElementFocusable && !isContentEditable) { var curDocument = domUtils.findDocument(elementForFocus); var curActiveElement = curDocument.activeElement; @@ -76,12 +80,10 @@ export function focusAndSetSelection (element, simulateFocus, caretPos) { return; } - elementForFocus = focusableParent || curDocument.body; + elementForFocus = focusableParent || curDocument.body; + preventScrolling = true; } - var focusWithSilentMode = !simulateFocus; - var focusForMouseEvent = true; - focusBlurSandbox.focus(elementForFocus, () => { // NOTE: if a different element was focused in the focus event handler, we should not set selection if (simulateFocus && !isContentEditable && element !== domUtils.getActiveElement()) { @@ -97,7 +99,7 @@ export function focusAndSetSelection (element, simulateFocus, caretPos) { focusBlurSandbox.focus(activeElement, resolve, true, true); else resolve(); - }, focusWithSilentMode, focusForMouseEvent); + }, focusWithSilentMode, focusForMouseEvent, false, preventScrolling); }); } diff --git a/test/functional/fixtures/regression/gh-913/pages/index.html b/test/functional/fixtures/regression/gh-913/pages/index.html new file mode 100644 index 00000000000..4283a4fe2b7 --- /dev/null +++ b/test/functional/fixtures/regression/gh-913/pages/index.html @@ -0,0 +1,11 @@ + + + + GH-913 + + +
+
+
+ + \ No newline at end of file diff --git a/test/functional/fixtures/regression/gh-913/test.js b/test/functional/fixtures/regression/gh-913/test.js new file mode 100644 index 00000000000..9ff20d48bd9 --- /dev/null +++ b/test/functional/fixtures/regression/gh-913/test.js @@ -0,0 +1,5 @@ +describe('[Regression](GH-913)', function () { + it("Shouldn't scroll to the focusable parent while performing click on non-focusable element", function () { + return runTests('testcafe-fixtures/index-test.js', "Shouldn't scroll to target parent while performing click"); + }); +}); diff --git a/test/functional/fixtures/regression/gh-913/testcafe-fixtures/index-test.js b/test/functional/fixtures/regression/gh-913/testcafe-fixtures/index-test.js new file mode 100644 index 00000000000..7c534171e5b --- /dev/null +++ b/test/functional/fixtures/regression/gh-913/testcafe-fixtures/index-test.js @@ -0,0 +1,17 @@ +import { expect } from 'chai'; +import { ClientFunction } from 'testcafe'; + +fixture `gh-913` + .page `http://localhost:3000/fixtures/regression/gh-913/pages/index.html`; + +const getWindowScrollTop = ClientFunction(() => window.pageYOffset); + +test("Shouldn't scroll to target parent while performing click", async t => { + const oldWindowScrollValue = await getWindowScrollTop(); + + await t.click('#child'); + + const newWindowScrollValue = await getWindowScrollTop(); + + expect(newWindowScrollValue).eql(oldWindowScrollValue); +});