Skip to content

Commit

Permalink
proxyless: ignore the paste option of TypeAutomation (#7617)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev authored Apr 13, 2023
1 parent 8429284 commit ab760e0
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/client/automation/playback/type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ export default class TypeAutomation {
}

if (this._canUseNativeAutomationInput()) {
if (this.paste)
return this.nativeAutomationInput.executeInsertText(this.typingText);

const eventSequence = this._calculateCDPEventSequence();

return this.nativeAutomationInput.executeEventSequence(eventSequence);
Expand Down Expand Up @@ -213,10 +216,6 @@ export default class TypeAutomation {
if (!this.nativeAutomationInput)
return false;

// NOTE: 'paste' is a synthetic option that don't have equivalent for native user action.
if (this.paste)
return false;

// NOTE: Type to non text-editable and content-editable elements are not supported in the native automation mode.
// In this case, TestCafe just set element value with raising events.
if (!domUtils.isTextEditableElement(this.element)
Expand Down
4 changes: 4 additions & 0 deletions src/native-automation/client/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export default class NativeAutomationInput {
return this._dispatchEventFn.sequence(eventSequence);
}

public async executeInsertText (text: string): Promise<any> {
return this._dispatchEventFn.single(EventType.InsertText, { text });
}

public async createMouseMoveEvent (currPosition: AxisValuesData<number>): Promise<any> {
const options = await CDPEventDescriptor.createMouseEventOptions('mouseMoved', {
options: {
Expand Down
1 change: 1 addition & 0 deletions src/native-automation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ export enum EventType {
Keyboard,
Touch,
Delay,
InsertText,
}
3 changes: 3 additions & 0 deletions src/native-automation/utils/cdp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export async function dispatchEvent (client: ProtocolApi, type: EventType, optio
case EventType.Keyboard:
await client.Input.dispatchKeyEvent(options);
break;
case EventType.InsertText:
await client.Input.insertText({ text: options.text });
break;
case EventType.Touch:
await client.Input.dispatchTouchEvent(options);
break;
Expand Down
4 changes: 4 additions & 0 deletions test/functional/fixtures/api/es-next/type/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ describe('[API] t.typeText()', function () {
return runTests('./testcafe-fixtures/type-test.js', 'Type text in input', { only: 'chrome' });
});

it('Should type text in input with the `paste` option enabled', function () {
return runTests('./testcafe-fixtures/type-test.js', 'Enable the `paste` option', { only: 'chrome' });
});

it('Should validate options', function () {
return runTests('./testcafe-fixtures/type-test.js', 'Incorrect action options', {
shouldFail: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// NOTE: to preserve callsites, add new tests AFTER the existing ones
import { ClientFunction } from 'testcafe';
import { ClientFunction, Selector } from 'testcafe';
import { expect } from 'chai';

fixture `Type`
Expand Down Expand Up @@ -30,3 +30,13 @@ test('Incorrect action options', async t => {
test('Not found selector', async t => {
await t.typeText('#not-found', 'a');
});

test('Enable the `paste` option', async t => {
const input = Selector('#input');

await t.typeText(input, 'qwerty', { replace: true, paste: true });
await t.expect(input.value).eql('qwerty');

await t.typeText(input, 'qwerty', { replace: false, paste: true });
await t.expect(input.value).eql('qwertyqwerty');
});
3 changes: 2 additions & 1 deletion test/functional/fixtures/api/raw/type/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { skipInNativeAutomation } = require('../../../../utils/skip-in');
const expect = require('chai').expect;
const errorInEachBrowserContains = require('../../../../assertion-helper.js').errorInEachBrowserContains;

Expand All @@ -9,7 +10,7 @@ describe('[Raw API] Type action', function () {
});
});

it("Should type all text in one keystroke if using 'paste' option", function () {
skipInNativeAutomation("Should type all text in one keystroke if using 'paste' option", function () {
return runTests('./testcafe-fixtures/type.testcafe', 'Type with paste option', { shouldFail: true })
.catch(function (errs) {
errorInEachBrowserContains(errs, 'Type block in one keystroke raised', 0);
Expand Down

0 comments on commit ab760e0

Please sign in to comment.