From 5e32033947fc57d47fab75b77c6d953ca7e41788 Mon Sep 17 00:00:00 2001 From: Yedidya Kennard Date: Tue, 20 Dec 2016 11:38:53 +0200 Subject: [PATCH 1/2] Added replaceText action --- detox/src/ios/expect.js | 12 ++++++++++++ detox/test/e2e/c-actions.js | 6 ++++++ detox/test/src/Screens/ActionsScreen.js | 17 +++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/detox/src/ios/expect.js b/detox/src/ios/expect.js index 5f89d9e64e..39cd0e42b7 100644 --- a/detox/src/ios/expect.js +++ b/detox/src/ios/expect.js @@ -190,6 +190,15 @@ class TypeTextAction extends Action { } } + +class ReplaceTextAction extends Action { + constructor(value) { + super(); + if (typeof value !== 'string') throw new Error(`ReplaceTextAction ctor argument must be a string, got ${typeof value}`); + this._call = invoke.call(invoke.IOS.Class('GREYActions'), 'actionForReplaceText:', value); + } +} + class ClearTextAction extends Action { constructor() { super(); @@ -355,6 +364,9 @@ class Element { typeText(value) { return new ActionInteraction(this, new TypeTextAction(value)).execute(); } + replaceText(value) { + return new ActionInteraction(this, new ReplaceTextAction(value)).execute(); + } clearText() { return new ActionInteraction(this, new ClearTextAction()).execute(); } diff --git a/detox/test/e2e/c-actions.js b/detox/test/e2e/c-actions.js index 869506713c..2c41c3a26c 100644 --- a/detox/test/e2e/c-actions.js +++ b/detox/test/e2e/c-actions.js @@ -36,6 +36,12 @@ describe('Actions', function () { expect(element(by.label('Clear Working!!!'))).toBeVisible(); }); + it.only('should replace text in an element', function () { + element(by.id('UniqueId006')).tap(); + element(by.id('UniqueId006')).replaceText('replaced_text'); + expect(element(by.label('Replace Working!!!'))).toBeVisible(); + }); + // directions: 'up'/'down'/'left'/'right' it('should scroll for a small amount in direction', function () { expect(element(by.label('Text1'))).toBeVisible(); diff --git a/detox/test/src/Screens/ActionsScreen.js b/detox/test/src/Screens/ActionsScreen.js index 16f818fa5d..c0c2c377e7 100644 --- a/detox/test/src/Screens/ActionsScreen.js +++ b/detox/test/src/Screens/ActionsScreen.js @@ -49,6 +49,12 @@ export default class ActionsScreen extends Component { testID='UniqueId005' /> + + Text1 @@ -106,6 +112,17 @@ export default class ActionsScreen extends Component { } } + onReplaceText(text) { + this.setState({ + replaceText: text + }); + if (text == 'replaced_text') { + this.setState({ + greeting: 'Replace Working' + }); + } + } + onChangeClearText(text) { this.setState({ clearText: text From c91938df6b6118b293f71a03abe64232b7cc92d2 Mon Sep 17 00:00:00 2001 From: Leo Natan Date: Tue, 20 Dec 2016 11:49:16 +0200 Subject: [PATCH 2/2] Update c-actions.js --- detox/test/e2e/c-actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detox/test/e2e/c-actions.js b/detox/test/e2e/c-actions.js index 2c41c3a26c..3c339ca258 100644 --- a/detox/test/e2e/c-actions.js +++ b/detox/test/e2e/c-actions.js @@ -36,7 +36,7 @@ describe('Actions', function () { expect(element(by.label('Clear Working!!!'))).toBeVisible(); }); - it.only('should replace text in an element', function () { + it('should replace text in an element', function () { element(by.id('UniqueId006')).tap(); element(by.id('UniqueId006')).replaceText('replaced_text'); expect(element(by.label('Replace Working!!!'))).toBeVisible();