diff --git a/src/client/automation/playback/click/click-command.js b/src/client/automation/playback/click/click-command.js index 8d42f3fefc9..70dc1c8dd48 100644 --- a/src/client/automation/playback/click/click-command.js +++ b/src/client/automation/playback/click/click-command.js @@ -32,8 +32,8 @@ class LabelElementClickCommand extends ElementClickCommand { constructor (eventState, eventArgs) { super(eventState, eventArgs); - this.label = this.eventArgs.element; - this.input = getElementBoundToLabel(this.eventArgs.element); + this.targetElement = this.eventArgs.element; + this.input = getElementBoundToLabel(this.eventArgs.element); } run () { @@ -49,7 +49,7 @@ class LabelElementClickCommand extends ElementClickCommand { listeners.removeInternalEventBeforeListener(window, ['focus'], ensureFocusRaised); - if (domUtils.isElementFocusable(this.label) && !focusRaised) + if (domUtils.isElementFocusable(this.targetElement) && !focusRaised) this._ensureBoundElementFocusRaised(); } @@ -114,7 +114,10 @@ class LabelledCheckboxElementClickCommand extends LabelElementClickCommand { listeners.removeInternalEventBeforeListener(window, ['change'], onChange); - if (browserUtils.isChrome && !changed) + // NOTE: Two overlapping issues: https://github.com/DevExpress/testcafe/issues/3348 and https://github.com/DevExpress/testcafe/issues/6949 + // When label contains or + + + + diff --git a/test/functional/fixtures/regression/gh-6949/pages/with-div.html b/test/functional/fixtures/regression/gh-6949/pages/with-div.html new file mode 100644 index 00000000000..3c42a80d1f5 --- /dev/null +++ b/test/functional/fixtures/regression/gh-6949/pages/with-div.html @@ -0,0 +1,18 @@ + + + + + Title + + +
+ + +
+ + diff --git a/test/functional/fixtures/regression/gh-6949/pages/with-link-without-href.html b/test/functional/fixtures/regression/gh-6949/pages/with-link-without-href.html new file mode 100644 index 00000000000..703bb57a635 --- /dev/null +++ b/test/functional/fixtures/regression/gh-6949/pages/with-link-without-href.html @@ -0,0 +1,18 @@ + + + + + Title + + +
+ + + terms and conditions. + + +
+ + diff --git a/test/functional/fixtures/regression/gh-6949/pages/with-link.html b/test/functional/fixtures/regression/gh-6949/pages/with-link.html new file mode 100644 index 00000000000..41b50808340 --- /dev/null +++ b/test/functional/fixtures/regression/gh-6949/pages/with-link.html @@ -0,0 +1,18 @@ + + + + + Title + + +
+ + +
+ + diff --git a/test/functional/fixtures/regression/gh-6949/test.js b/test/functional/fixtures/regression/gh-6949/test.js new file mode 100644 index 00000000000..f797b254b23 --- /dev/null +++ b/test/functional/fixtures/regression/gh-6949/test.js @@ -0,0 +1,23 @@ +describe('[Regression](GH-6949)', () => { + it('Should change checkbox state when clicking checkbox label', () => { + return runTests('./testcafe-fixtures/with-link.js', 'Click checkbox label'); + }); + + it('Should NOT change checkbox state when clicking a LINK inside the checkbox label', () => { + return runTests('./testcafe-fixtures/with-link.js', 'Click link inside checkbox label'); + }); + + it('Should change checkbox state when clicking a LINK without href attribute inside the checkbox label', () => { + //The behaviour in IE is different, so we should to exclude it from this test: + return runTests('./testcafe-fixtures/with-link-without-href.js', 'Click link without href inside checkbox label', { skip: 'ie' }); + }); + + it('Should NOT change checkbox state when clicking a BUTTON inside the checkbox label', () => { + //The behaviour in IE is different, so we should to exclude it from this test: + return runTests('./testcafe-fixtures/with-button.js', 'Click button inside checkbox label', { skip: 'ie' }); + }); + + it('Should change checkbox state when clicking a DIV with onclick handler inside the checkbox label', () => { + return runTests('./testcafe-fixtures/with-div.js', 'Click div inside checkbox label'); + }); +}); diff --git a/test/functional/fixtures/regression/gh-6949/testcafe-fixtures/with-button.js b/test/functional/fixtures/regression/gh-6949/testcafe-fixtures/with-button.js new file mode 100644 index 00000000000..609e83eb630 --- /dev/null +++ b/test/functional/fixtures/regression/gh-6949/testcafe-fixtures/with-button.js @@ -0,0 +1,12 @@ +import { Selector } from 'testcafe'; + +fixture`Getting Started` + .page`http://localhost:3000/fixtures/regression/gh-6949/pages/with-button.html`; + +test('Click button inside checkbox label', async t => { + const button = Selector('#clickable-element'); + const checkBox = Selector('#checkbox'); + + await t.click(button); + await t.expect(checkBox.checked).eql(false); +}); diff --git a/test/functional/fixtures/regression/gh-6949/testcafe-fixtures/with-div.js b/test/functional/fixtures/regression/gh-6949/testcafe-fixtures/with-div.js new file mode 100644 index 00000000000..745ebdb259c --- /dev/null +++ b/test/functional/fixtures/regression/gh-6949/testcafe-fixtures/with-div.js @@ -0,0 +1,12 @@ +import { Selector } from 'testcafe'; + +fixture`Getting Started` + .page`http://localhost:3000/fixtures/regression/gh-6949/pages/with-div.html`; + +test('Click div inside checkbox label', async t => { + const div = Selector('#clickable-element'); + const checkBox = Selector('#checkbox'); + + await t.click(div); + await t.expect(checkBox.checked).eql(true); +}); diff --git a/test/functional/fixtures/regression/gh-6949/testcafe-fixtures/with-link-without-href.js b/test/functional/fixtures/regression/gh-6949/testcafe-fixtures/with-link-without-href.js new file mode 100644 index 00000000000..529e447447c --- /dev/null +++ b/test/functional/fixtures/regression/gh-6949/testcafe-fixtures/with-link-without-href.js @@ -0,0 +1,12 @@ +import { Selector } from 'testcafe'; + +fixture`Getting Started` + .page`http://localhost:3000/fixtures/regression/gh-6949/pages/with-link-without-href.html`; + +test('Click link without href inside checkbox label', async t => { + const link = Selector('#clickable-element'); + const checkBox = Selector('#checkbox'); + + await t.click(link); + await t.expect(checkBox.checked).eql(true); +}); diff --git a/test/functional/fixtures/regression/gh-6949/testcafe-fixtures/with-link.js b/test/functional/fixtures/regression/gh-6949/testcafe-fixtures/with-link.js new file mode 100644 index 00000000000..bb4440aebaf --- /dev/null +++ b/test/functional/fixtures/regression/gh-6949/testcafe-fixtures/with-link.js @@ -0,0 +1,20 @@ +import { Selector } from 'testcafe'; + +fixture`Getting Started` + .page`http://localhost:3000/fixtures/regression/gh-6949/pages/with-link.html`; + +test('Click checkbox label', async t => { + const label = Selector('#checkbox-label'); + const checkBox = Selector('#checkbox'); + + await t.click(label); + await t.expect(checkBox.checked).eql(true); +}); + +test('Click link inside checkbox label', async t => { + const link = Selector('#clickable-element'); + const checkBox = Selector('#checkbox'); + + await t.click(link); + await t.expect(checkBox.checked).eql(false); +});