Skip to content

Commit

Permalink
support typing text in elements, closes #26
Browse files Browse the repository at this point in the history
  • Loading branch information
talkol committed Oct 7, 2016
1 parent 7187691 commit d43b17d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions detox/src/ios/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class TapAction extends Action {
}
}

class TypeTextAction extends Action {
constructor(value) {
super();
if (typeof value !== 'string') throw new Error(`TypeTextAction ctor argument must be a string, got ${typeof value}`);
this._call = invoke.call(invoke.IOS.Class('GREYActions'), 'actionForTypeText:', value);
}
}

class Interaction {
execute() {
if (!this._call) throw new Error(`Interaction.execute cannot find a valid _call, got ${typeof this._call}`);
Expand Down Expand Up @@ -91,6 +99,9 @@ class Element {
tap() {
return new ActionInteraction(this, new TapAction()).execute();
}
typeText(value) {
return new ActionInteraction(this, new TypeTextAction(value)).execute();
}
}

class Expect {}
Expand Down
6 changes: 6 additions & 0 deletions detox/test/e2e/c-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ describe.only('Actions', function () {
expect(element(by.label('Tap Working!!!'))).toBeVisible();
});

// Backspace is supported by using "\b" in the string. Return key is supported with "\n"
it('should type in an element', function () {
element(by.id('UniqueId937')).typeText('passcode');
expect(element(by.label('Type Working!!!'))).toBeVisible();
});

});
17 changes: 17 additions & 0 deletions detox/test/src/Screens/ActionsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export default class ActionsScreen extends Component {
<Text style={{color: 'blue', marginBottom: 20}}>Tap Me</Text>
</TouchableOpacity>

<TextInput style={{height: 40, borderColor: 'gray', borderWidth: 1, marginBottom: 20, marginHorizontal: 20, padding: 5}}
onChangeText={this.onChangeTypeText.bind(this)}
value={this.state.typeText}
testID='UniqueId937'
/>

</View>
);
}
Expand All @@ -45,4 +51,15 @@ export default class ActionsScreen extends Component {
});
}

onChangeTypeText(text) {
this.setState({
typeText: text
});
if (text == 'passcode') {
this.setState({
greeting: 'Type Working'
});
}
}

}

0 comments on commit d43b17d

Please sign in to comment.