Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/driver/typescript-5.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa authored Dec 9, 2024
2 parents 35b6f46 + 67ce86f commit 15c22b0
Show file tree
Hide file tree
Showing 9 changed files with 924 additions and 673 deletions.
50 changes: 42 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ If you'd like to test a release app, whcih can be released from app store as-is,
- `NATIVE_APP` context is the same as the regular Appium [UIAutomator2](https://github.com/appium/appium-uiautomator2-driver)/[XCUITest](https://github.com/appium/appium-xcuitest-driver) driver
- `WEBVIEW` context manages the WebView contents over Appium UiAutomator2/XCUITest driver
- (**Recommended** if possible) Appium [UIAutomator2](https://github.com/appium/appium-uiautomator2-driver)/[XCUITest](https://github.com/appium/appium-xcuitest-driver) driver directly must be sufficient to achieve automation if the application under test had `semanticLabel` properly. Then, the accessibility mechanism in each OS can expose elements for Appium through OS's accessibility features.
- For example, [Key](https://api.flutter.dev/flutter/foundation/Key-class.html) does not work in the Appium UiAutomator2/XCUITest drivers, but can work in the Appium Flutter Driver
- Flutter 3.19 may have [`identifier` for `SemanticsProperties`](https://api.flutter.dev/flutter/semantics/SemanticsProperties/identifier.html) (introduced by https://github.com/flutter/flutter/pull/138331). It sets `resource-id` and `accessibilityIdentifier` for Android and iOS, then UiAutomator2/XCUITest drivers also can handle `Key` without this driver
- In addition to `semanticLabel`, Flutter 3.19+ may have [`identifier` for `SemanticsProperties`](https://api.flutter.dev/flutter/semantics/SemanticsProperties/identifier.html) (introduced by https://github.com/flutter/flutter/pull/138331). It sets `resource-id` and `accessibilityIdentifier` for Android and iOS, then UiAutomator2/XCUITest drivers might also be able to interact with these elements without Appium Flutter Driver.
- `"appium:settings[disableIdLocatorAutocompletion]": true` or configuring `disableIdLocatorAutocompletion` via [Settings API](https://appium.io/docs/en/latest/guides/settings/) would be necessary to make `resource-id` idea work without any package name prefix like Android compose.
- e.g. https://github.com/flutter/flutter/issues/17988#issuecomment-1867097631

Expand Down Expand Up @@ -356,29 +355,32 @@ This is a command extension for Flutter Driver, utilizing the [CommandExtension-
Available commands:

- `dragAndDropWithCommandExtension` – performs a drag-and-drop action on the screen by specifying the start and end coordinates and the action duration.
- `getTextWithCommandExtension` - get text data from Text widget that contains TextSpan widgets.

### How to use

Copy the [extended_commands.dart](extended_commands.dart) file to the `lib` folder of your Flutter project.
Copy the sample dart files to the `lib` folder of your project. Please note that you don't need to copy all files, just copy the file matched with the command you need.
- dragAndDropWithCommandExtension: [drag_commands.dart](./example/dart/drag_commands.dart)
- getTextWithCommandExtension: [get_text_command.dart](./example/dart/get_text_command.dart)

The entry point must include the `List<CommandExtension>?` commands argument in either `main.dart` or `test_main.dart` to properly handle the command extension.


```dart
import 'extended_commands.dart';
import 'drag_commands.dart';
import 'get_text_command.dart';
void main() {
enableFlutterDriverExtension(
commands: [DragCommandExtension()]);
commands: [DragCommandExtension(), GetTextCommandExtension()]);
runApp(const MyApp());
}
```

#### Simple example using `dragAndDropWithCommandExtension` command in Python
#### Simple examples in Python

```python
# python
# Extended commands: flutter:dragAndDropWithCommandExtension
coord_item_1 = driver.execute_script("flutter:getCenter", item_1)
coord_item_2 = driver.execute_script("flutter:getCenter", item_2)
start_x = coord_item_1["dx"]
Expand All @@ -394,6 +396,38 @@ payload = {
}

driver.execute_script("flutter:dragAndDropWithCommandExtension", payload)

# Extended commands: flutter:getTextWithCommandExtension
text_finder = finder.by_value_key('amount')
get_text_payload = {
'findBy': text_finder,
}
result = driver.execute_script('flutter:getTextWithCommandExtension', payload)
print(result)
```

#### Simple examples in nodejs

```typescript
// Extended commands: flutter:dragAndDropWithCommandExtension
const payload = {
"startX": "100",
"startY": "100",
"endX": "100",
"endY": "600",
"duration": "15000"
}
const result = await driver.execute("flutter:dragAndDropWithCommandExtension", payload);
console.log(JSON.stringify(result));

// Extended commands: flutter:getTextWithCommandExtension
import {byValueKey} from "appium-flutter-finder";
const payload = {
'findBy': byValueKey('amount'),
};
const getTextResult = await driver.execute('flutter:getTextWithCommandExtension', payload);
console.log(JSON.stringify(getTextResult));

```

For debugging or testing in other programming languages, you can use the APK available in this [repository](https://github.com/Alpaca00/command-driven-list) or build an IPA.
Expand Down
5 changes: 5 additions & 0 deletions driver/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.11.0
- Adds `flutter:getTextWithCommandExtension` command. Please check the README about how to use the command properly.
- Update Appium UIAutomator2 driver dependency to 3.9.1
- Update Appium XCUITest driver dependency to 7.32.0

## 2.10.0
- Adds `flutter:dragAndDropWithCommandExtension` command. Please check the README about how to use the command properly.
- Update Appium UIAutomator2 driver dependency to 3.8.1
Expand Down
10 changes: 10 additions & 0 deletions driver/lib/commands/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export const execute = async function(
return await clickElement(this, args[0], args[1]);
case `dragAndDropWithCommandExtension`:
return await dragAndDropWithCommandExtension(this, args[0]);
case `getTextWithCommandExtension`:
return await getTextWithCommandExtension(this, args[0]);
default:
throw new Error(`Command not support: "${rawCommand}"`);
}
Expand Down Expand Up @@ -242,3 +244,11 @@ const dragAndDropWithCommandExtension = async (
};
return await self.socket!.executeSocketCommand(commandPayload);
};

const getTextWithCommandExtension = async (self: FlutterDriver, params: { findBy: string; }) => {
const payload = {
command: 'getTextWithCommandExtension',
findBy: params.findBy,
};
return await self.socket!.executeSocketCommand(payload);
};
Loading

0 comments on commit 15c22b0

Please sign in to comment.