Skip to content

Commit

Permalink
0.0.18: sendKeys / setValue
Browse files Browse the repository at this point in the history
  • Loading branch information
truongsinh committed Aug 26, 2019
1 parent 415a806 commit 1aace44
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ Legend:
| [checkHealth](https://api.flutter.dev/flutter/flutter_driver/FlutterDriver/checkHealth.html) | :ok: | `driver.execute('flutter:checkHealth')` | Session |
| [clearTimeline](https://api.flutter.dev/flutter/flutter_driver/FlutterDriver/clearTimeline.html) | :ok: | `driver.execute('flutter:clearTimeline')` | Session |
| [close](https://api.flutter.dev/flutter/flutter_driver/FlutterDriver/close.html) | :ok: | [`driver.deleteSession()`](https://github.com/truongsinh/appium-flutter-driver/blob/5df7386b59bb99008cb4cff262552c7259bb2af2/example/src/index.js#L55) | Session |
| [enterText](https://api.flutter.dev/flutter/flutter_driver/FlutterDriver/enterText.html) | :x: | `driver.execute('flutter:enterText', 'I can enter text')` | Session |
| [enterText](https://api.flutter.dev/flutter/flutter_driver/FlutterDriver/enterText.html) | :x: | `driver.elementSendKeys(find.byType('TextField'), 'I can enter text')` (no focus required)\
`driver.elementClick(find.byType('TextField')); driver.execute('flutter:enterText', 'I can enter text')` (focus required by tap/click first) | Session |
| [forceGC](https://api.flutter.dev/flutter/flutter_driver/FlutterDriver/forceGC.html) | :ok: | `driver.execute('flutter:forceGC')` | Session |
| [getBottomLeft](https://api.flutter.dev/flutter/flutter_driver/FlutterDriver/getBottomLeft.html) | :ok: | `driver.execute('flutter:getBottomLeft', buttonFinder)` | Widget |
| [getBottomRight](https://api.flutter.dev/flutter/flutter_driver/FlutterDriver/getBottomRight.html) | :ok: | `driver.execute('flutter:getBottomRight', buttonFinder)` | Widget |
Expand Down
14 changes: 14 additions & 0 deletions driver/lib/commands/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@ export const getText = async function(this: FlutterDriver, el: string) {
const response = await this.executeElementCommand(`get_text`, el);
return response.text;
};

export const setValue = async function(this: FlutterDriver, textInput: string | [string], el: string) {
const clickPromise = this.click(el); // acquire focus
let text = ``;
if (textInput instanceof Array) {
text = textInput.reduce((previousValue, currentValue) => `${previousValue}${currentValue}`);
} else if (typeof textInput === `string`) {
text = textInput;
} else {
throw new Error(`Invalid textInput: ${textInput}`);
}
await clickPromise;
await this.execute(`flutter:enterText`, [text]);
};
3 changes: 2 additions & 1 deletion driver/lib/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createSession, deleteSession } from './sessions/session';

import { driverShouldDoProxyCmd, FLUTTER_CONTEXT_NAME,
getContexts, getCurrentContext, setContext } from './commands/context';
import { getText } from './commands/element';
import { getText, setValue } from './commands/element';
import { execute } from './commands/execute';
import { click, performTouch, tap, tapEl } from './commands/gesture';
import { getScreenshot } from './commands/screen';
Expand All @@ -35,6 +35,7 @@ class FlutterDriver extends BaseDriver {

// element
public getText = getText;
public setValue = setValue;
public getScreenshot = getScreenshot;

// gesture
Expand Down
2 changes: 1 addition & 1 deletion driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"appium",
"flutter"
],
"version": "0.0.17",
"version": "0.0.18",
"author": "TruongSinh Tran-Nguyen <[email protected]>",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion example/flutter_app_under_test/test_driver/main_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void main() {
await driver.waitForAbsent(find.byTooltip('counter_tooltip'));
expect(await driver.getText(find.text('This is 2nd route')),
'This is 2nd route');
await driver.scrollUntilVisible(find.byType('ListView'), find.byType('TextField'), dxScroll: 90, dyScroll: -40);
await driver.scrollUntilVisible(find.byType('ListView'), find.byType('TextField'), dxScroll: 90, dyScroll: -400);
await driver.scroll(find.byType('ListView'), 50, 100, Duration(milliseconds: 200), frequency: 30);
await driver.scrollIntoView(find.byType('ListView'), alignment: 1.4);
await driver.tap(find.byType('TextField'));
Expand Down
3 changes: 1 addition & 2 deletions example/nodejs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ const opts = {
await driver.execute('flutter:scrollUntilVisible', find.byType('ListView'), {item:find.byType('TextField'), dxScroll: 90, dyScroll: -400});
await driver.execute('flutter:scroll', find.byType('ListView'), {dx: 50, dy: 100, durationMilliseconds: 200, frequency: 30});
await driver.execute('flutter:scrollIntoView', find.byType('TextField'), {alignment: 0.1});
await driver.elementClick(find.byType('TextField')); // acquire focus
await driver.execute('flutter:enterText', 'I can enter text'); // enter text
await driver.elementSendKeys(find.byType('TextField'), 'I can enter text');
await driver.execute('flutter:waitFor', find.byText('I can enter text')); // verify text appears on UI

await driver.elementClick(find.pageBack());
Expand Down

0 comments on commit 1aace44

Please sign in to comment.