Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed focus for click automation (closes #913) #921

Merged
merged 1 commit into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/client/automation/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()) {
Expand All @@ -97,7 +99,7 @@ export function focusAndSetSelection (element, simulateFocus, caretPos) {
focusBlurSandbox.focus(activeElement, resolve, true, true);
else
resolve();
}, focusWithSilentMode, focusForMouseEvent);
}, focusWithSilentMode, focusForMouseEvent, false, preventScrolling);
});
}

Expand Down
11 changes: 11 additions & 0 deletions test/functional/fixtures/regression/gh-913/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>GH-913</title>
</head>
<body>
<div id="parent" style="width:500px; height:2000px; top:200px; position:absolute; background:grey;" tabindex="0">
<div id="child" style="width:100px; height:100px; top:100px; position:absolute; background:red;"></div>
</div>
</body>
</html>
5 changes: 5 additions & 0 deletions test/functional/fixtures/regression/gh-913/test.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
Original file line number Diff line number Diff line change
@@ -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);
});