Compare commits

...

2 Commits
dev ... appium

Author SHA1 Message Date
Calcitem 2f1ca5dbcf
test: Support Appium
And add a simple example in test.js.
2021-11-29 21:59:14 +08:00
Calcitem 282805fe8f
Rename environment monkey-test to test
Because we will add Appium test in the future.
2021-11-29 21:59:13 +08:00
15 changed files with 125 additions and 16 deletions

View File

@ -10,7 +10,7 @@ indent_size = 4
end_of_line = lf
insert_final_newline = true
[*.dart]
[*.{dart,js}]
indent_style = space
indent_size = 2
end_of_line = lf

View File

@ -7,6 +7,7 @@ andnetwork
APARTMENTTHREADED
APIENTRY
appbundle
appium
APSTUDIO
ARGB
argc

View File

@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Sanmill-monkey" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="additionalArgs" value="--dart-define monkey_test=true" />
<option name="filePath" value="$PROJECT_DIR$/src/ui/flutter_app/lib/main.dart" />
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Sanmill-test" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="additionalArgs" value="--dart-define test=true" />
<option name="filePath" value="$PROJECT_DIR$/src/ui/flutter_app/lib/main.dart" />
<method v="2" />
</configuration>
</component>

4
.vscode/launch.json vendored
View File

@ -30,14 +30,14 @@
]
},
{
"name": "Sanmill-monkey",
"name": "Sanmill-test",
"type": "dart",
"request": "launch",
"cwd": "src/ui/flutter_app",
"program": "lib/main.dart",
"args": [
"--dart-define",
"monkey_test=true"
"test=true"
]
},
{

View File

@ -2,6 +2,7 @@
"cSpell.words": [
"ALIGNAS",
"appbundle",
"Appium",
"APSTUDIO",
"ARGB",
"autobuild",
@ -126,6 +127,8 @@
"VERSIONINFO",
"VNNI",
"vsync",
"wdio",
"webdriverio",
"winbase",
"winres",
"winver",

View File

@ -73,7 +73,7 @@ Run `./flutter-init.sh` , copy `src/ui/flutter_app/android/key.properties.exampl
We use compile-time environment configs to enable specific parts of the code:
* `monkey_test` to prepare the app for monkey tests. (References to external sites are going to be disabled.)
* `test` to prepare the app for Monkey and Appium testing. (References to external sites are going to be disabled.)
* `dev_mode` to show the developer mode without needing to enable it first.
* `catcher` to control the use of catcher. (This is on by default and needs to be disabled when required.)

View File

@ -24,6 +24,7 @@ import 'package:double_back_to_close_app/double_back_to_close_app.dart';
import 'package:feedback/feedback.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_driver/driver_extension.dart';
import 'package:hive_flutter/hive_flutter.dart' show Box;
import 'package:path_provider/path_provider.dart';
import 'package:sanmill/generated/intl/l10n.dart';
@ -43,7 +44,11 @@ part 'package:sanmill/services/init_system_ui.dart';
Future<void> main() async {
debugPrint('Environment [catcher]: ${EnvironmentConfig.catcher}');
debugPrint('Environment [dev_mode]: ${EnvironmentConfig.devMode}');
debugPrint('Environment [monkey_test]: ${EnvironmentConfig.monkeyTest}');
debugPrint('Environment [test]: ${EnvironmentConfig.test}');
if (EnvironmentConfig.test) {
enableFlutterDriverExtension();
}
await LocalDatabaseService.initStorage();

View File

@ -993,6 +993,7 @@ class _GamePageState extends State<GamePage>
),
actions: <Widget>[
TextButton(
key: const Key('infoDialogOkButton'),
child:
Text(S.of(context).ok, style: AppTheme.moveHistoryTextStyle),
onPressed: () => Navigator.pop(context),
@ -1425,24 +1426,28 @@ class _GamePageState extends State<GamePage>
List<Widget> get toolbar {
final gameButton = ToolbarItem.icon(
key: const Key('gameButton'),
onPressed: onGameButtonPressed,
icon: const Icon(FluentIcons.table_simple_24_regular),
label: Text(S.of(context).game),
);
final optionsButton = ToolbarItem.icon(
key: const Key('optionsButton'),
onPressed: onOptionButtonPressed,
icon: const Icon(FluentIcons.settings_24_regular),
label: Text(S.of(context).options),
);
final moveButton = ToolbarItem.icon(
key: const Key('moveButton'),
onPressed: onMoveButtonPressed,
icon: const Icon(FluentIcons.calendar_agenda_24_regular),
label: Text(S.of(context).move_number(0)),
);
final infoButton = ToolbarItem.icon(
key: const Key('infoButton'),
onPressed: onInfoButtonPressed,
icon: const Icon(FluentIcons.book_information_24_regular),
label: Text(S.of(context).info),

View File

@ -22,13 +22,13 @@
class EnvironmentConfig {
const EnvironmentConfig._();
/// gets weather we build for a monkey test
static const monkeyTest = bool.fromEnvironment('monkey_test');
/// Gets whether we build for Monkey/Appium testing
static const test = bool.fromEnvironment('test');
/// gets weather we build for devMode
/// Gets whether we build for devMode
static const devMode = bool.fromEnvironment('dev_mode');
/// gets weather we want catcher to be enabled
/// Gets whether we want catcher to be enabled
/// defaults to true
static const catcher = bool.fromEnvironment('catcher', defaultValue: true);
}

View File

@ -45,6 +45,9 @@ dependencies:
dev_dependencies:
build_runner: ^2.1.5
copy_with_extension_gen: ^2.0.3
flutter_driver:
sdk: flutter
flutter_gen_runner: ^4.1.2
flutter_test:
sdk: flutter
@ -55,6 +58,7 @@ dev_dependencies:
lint: ^1.7.2
msix: ^2.6.2
source_gen: ^1.1.1
test: any
flutter_gen:
output: lib/generated/assets/

1
tests/appium/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/package-lock.json

49
tests/appium/Readme.md Normal file
View File

@ -0,0 +1,49 @@
# How to Test
## Environment configuration
### Install Node.js
Download and install [Node.js](https://nodejs.org).
### Install the dependencies
```shell
npm install -g appium
npm install -g appium-flutter-driver
npm install -g appium-flutter-finder
npm install -g cjs
npm install -g wd
npm install -g webdriverio
```
## Test
### Run Appium server
```shell
appium --base-path /
```
### Build debug apk
```shell
cd src/ui/flutter_app
flutter build apk --debug -v
```
### Start testing
```shell
cd tests/appium
npm start
```
### Known issues
You need to modify app's path in the test.js.
## Reference
[Getting Started - Appium](http://appium.io/docs/en/about-appium/getting-started)
[GitHub - appium-flutter-driver](https://github.com/appium-userland/appium-flutter-driver)

20
tests/appium/package.json Normal file
View File

@ -0,0 +1,20 @@
{
"dependencies": {
"appium-flutter-finder": "^0.1.0",
"cjs": "^0.0.11",
"webdriverio": "^7.16.10"
},
"name": "appium",
"description": "https://nodejs.org/en/",
"version": "1.0.0",
"main": "test.js",
"scripts": {
"start": "node test.js",
"ios": "APPIUM_OS=ios npm start",
"android": "APPIUM_OS=android npm start",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Calcitem <calcitem@outlook.com>",
"license": "GPLv3"
}

21
tests/appium/test.js Normal file
View File

@ -0,0 +1,21 @@
const wdio = require('webdriverio');
const assert = require('assert');
const find = require('appium-flutter-finder');
const { compileFunction } = require('vm');
const opts = {
port: 4723,
capabilities: {
deviceName: "PIXEL 5",
platformName: "Android",
platformVersion: "12",
app: "D:\\repos\\Sanmill\\src\\ui\\flutter_app\\build\\app\\outputs\\flutter-apk\\app-debug.apk",
automationName: "Flutter"
}
};
(async () => {
const driver = await wdio.remote(opts);
await driver.elementClick(find.byValueKey('infoButton'));
await driver.elementClick(find.byValueKey('infoDialogOkButton'));
})();