Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added replaceText action #65

Merged
merged 2 commits into from
Dec 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions detox/src/ios/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
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 @@ -36,6 +36,12 @@ describe('Actions', function () {
expect(element(by.label('Clear Working!!!'))).toBeVisible();
});

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();
});

// directions: 'up'/'down'/'left'/'right'
it('should scroll for a small amount in direction', function () {
expect(element(by.label('Text1'))).toBeVisible();
Expand Down
17 changes: 17 additions & 0 deletions detox/test/src/Screens/ActionsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export default class ActionsScreen extends Component {
testID='UniqueId005'
/>

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

<View style={{height: 100, borderColor: '#c0c0c0', borderWidth: 1, backgroundColor: '#f8f8ff', marginBottom: 20}}>
<ScrollView testID='ScrollView161'>
<Text style={{height: 30, backgroundColor: '#e8e8f8', padding: 5, margin: 10}}>Text1</Text>
Expand Down Expand Up @@ -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
Expand Down