From fd0def31d4409aa8335a387eb2b3df521cf4b178 Mon Sep 17 00:00:00 2001 From: Popov Aleksey Date: Thu, 13 Jul 2023 11:32:58 +0300 Subject: [PATCH] fix: added pressure for click in NA (#7876) [closes #7867] ## Purpose Fix issue `Some clicks don't work in native automation mode` ## Approach 1. Find out the reason why click doesn't work correctly in NA 2. Add a test 3. Fix issue ## References https://github.com/DevExpress/testcafe/issues/7867 ## Pre-Merge TODO - [X] Write tests for your proposed changes - [x] Make sure that existing tests do not fail --- src/native-automation/client/event-descriptor.ts | 1 + .../functional/fixtures/api/es-next/click/pages/index.html | 6 ++++++ test/functional/fixtures/api/es-next/click/test.js | 7 ++++++- .../api/es-next/click/testcafe-fixtures/click-test.js | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/native-automation/client/event-descriptor.ts b/src/native-automation/client/event-descriptor.ts index 4e0a83b385f..e90537ccf24 100644 --- a/src/native-automation/client/event-descriptor.ts +++ b/src/native-automation/client/event-descriptor.ts @@ -15,6 +15,7 @@ const messageSandbox = eventSandbox.message; const MOUSE_EVENT_OPTIONS = { clickCount: 1, + force: 0.5, }; const CALCULATE_TOP_LEFT_POINT_REQUEST_CMD = 'native-automation|calculate-top-left-point|request'; diff --git a/test/functional/fixtures/api/es-next/click/pages/index.html b/test/functional/fixtures/api/es-next/click/pages/index.html index e91d29b714e..c93e3869972 100644 --- a/test/functional/fixtures/api/es-next/click/pages/index.html +++ b/test/functional/fixtures/api/es-next/click/pages/index.html @@ -31,6 +31,12 @@ status.textContent = 'Clicked!'; }); + + document.querySelector('#statusBtn').addEventListener('pointerdown', function (e) { + window.pointerdownPressure = e.pressure; + }); + + window.pointerdownPressure = 0;
diff --git a/test/functional/fixtures/api/es-next/click/test.js b/test/functional/fixtures/api/es-next/click/test.js index 9a89a4c7f66..7c9916963b3 100644 --- a/test/functional/fixtures/api/es-next/click/test.js +++ b/test/functional/fixtures/api/es-next/click/test.js @@ -1,4 +1,5 @@ -const expect = require('chai').expect; +const { onlyInNativeAutomation } = require('../../../../utils/skip-in'); +const expect = require('chai').expect; //GH-1674 const TEST_DURATION_BOUND = 10000; @@ -234,4 +235,8 @@ describe('[API] t.click()', function () { }); }); }); + + onlyInNativeAutomation('Should set pressure in Native Automation', () => { + return runTests('./testcafe-fixtures/click-test.js', 'Check click pressure', { only: 'chrome' }); + }); }); diff --git a/test/functional/fixtures/api/es-next/click/testcafe-fixtures/click-test.js b/test/functional/fixtures/api/es-next/click/testcafe-fixtures/click-test.js index 2f795505386..04d51771404 100644 --- a/test/functional/fixtures/api/es-next/click/testcafe-fixtures/click-test.js +++ b/test/functional/fixtures/api/es-next/click/testcafe-fixtures/click-test.js @@ -107,3 +107,9 @@ test('Click on an element with overlapped center', async t => { test('Click overlapped element', async t => { await t.click('.child1'); }).page('http://localhost:3000/fixtures/api/es-next/click/pages/overlapped.html'); + +test('Check click pressure', async t => { + await t.click('#statusBtn'); + + expect(await t.eval(() => window.pointerdownPressure)).gt(0); +});