diff --git a/.gitignore b/.gitignore index a21e75f61b57fe7b754abaef009e8362eaeec37c..d6ac23904c95e641104b602e532ac53afdb16c07 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,4 @@ yarn.lock !**/ios/**/default.pbxuser !**/ios/**/default.perspectivev3 !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages +/ohos/node_test_server/node_modules diff --git a/ohos/automated_testing_demo/.gitignore b/ohos/automated_testing_demo/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..24476c5d1eb55824c76d8b01a3965f94abad1ef8 --- /dev/null +++ b/ohos/automated_testing_demo/.gitignore @@ -0,0 +1,44 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/ohos/automated_testing_demo/.metadata b/ohos/automated_testing_demo/.metadata new file mode 100644 index 0000000000000000000000000000000000000000..dfddd4eb51bc85f35afa725ffe77e9222920818d --- /dev/null +++ b/ohos/automated_testing_demo/.metadata @@ -0,0 +1,43 @@ +# +# Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled. + +version: + revision: 45b6224fc89525c9436526e82d0e8d9fb31b4e38 + channel: dev + +project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 45b6224fc89525c9436526e82d0e8d9fb31b4e38 + base_revision: 45b6224fc89525c9436526e82d0e8d9fb31b4e38 + - platform: ohos + create_revision: 45b6224fc89525c9436526e82d0e8d9fb31b4e38 + base_revision: 45b6224fc89525c9436526e82d0e8d9fb31b4e38 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/ohos/automated_testing_demo/README.md b/ohos/automated_testing_demo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..44903cca6a472d00f8c1e5176fd2816a5a518381 --- /dev/null +++ b/ohos/automated_testing_demo/README.md @@ -0,0 +1,16 @@ +# automated_testing_demo + +A new Flutter project. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/ohos/automated_testing_demo/analysis_options.yaml b/ohos/automated_testing_demo/analysis_options.yaml new file mode 100644 index 0000000000000000000000000000000000000000..61b6c4de17c96863d24279f06b85e01b6ebbdb34 --- /dev/null +++ b/ohos/automated_testing_demo/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/ohos/automated_testing_demo/integration_test/key_input_test.dart b/ohos/automated_testing_demo/integration_test/key_input_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..6beeb1c02ea53938ec0238a644dc8ea211d671be --- /dev/null +++ b/ohos/automated_testing_demo/integration_test/key_input_test.dart @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter/services.dart'; + +void main() { + testWidgets('Test keyboard input in a TextField', + (WidgetTester tester) async { + // 准备测试 + await tester.pumpWidget(MaterialApp(home: MyTextField())); + + // 找到文本字段 + Finder textFieldFinder = find.byType(TextField); + expect(textFieldFinder, findsOneWidget); + + // 输入文本 + await tester.enterText(textFieldFinder, 'Hello, World!'); + await tester.pump(); // 刷新界面以便测试者可以看到变化 + + // 验证文本是否已经输入 + expect(find.text('Hello, World!'), findsOneWidget); + }); +} + +class MyTextField extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: TextField(), + ), + ); + } +} diff --git a/ohos/automated_testing_demo/integration_test/path_provider_test.dart b/ohos/automated_testing_demo/integration_test/path_provider_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..b40b4d20fc4cd25d194aae289ad6441eda422967 --- /dev/null +++ b/ohos/automated_testing_demo/integration_test/path_provider_test.dart @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import 'dart:io'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('getTemporaryDirectory', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + final String? result = await provider.getTemporaryPath(); + _verifySampleFile(result, 'temporaryDirectory'); + }); + + testWidgets('getApplicationDocumentsDirectory', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + final String? result = await provider.getApplicationDocumentsPath(); + _verifySampleFile(result, 'applicationDocuments'); + }); + + testWidgets('getApplicationSupportDirectory', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + final String? result = await provider.getApplicationSupportPath(); + _verifySampleFile(result, 'applicationSupport'); + }); + + testWidgets('getApplicationCacheDirectory', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + final String? result = await provider.getApplicationCachePath(); + _verifySampleFile(result, 'applicationSupport'); + }); + + testWidgets('getLibraryDirectory', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + expect(() => provider.getLibraryPath(), + throwsA(isInstanceOf())); + }); + + testWidgets('getExternalStorageDirectory', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + final String? result = await provider.getExternalStoragePath(); + _verifySampleFile(result, 'externalStorage'); + }); + + testWidgets('getDownloadsPathDirectory', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + final String? result = await provider.getDownloadsPath(); + _verifySampleFile(result, 'externalStorage'); + }); + + testWidgets('getExternalCacheDirectories', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + final List? directories = await provider.getExternalCachePaths(); + expect(directories, isNotNull); + for (final String result in directories!) { + _verifySampleFile(result, 'externalCache'); + } + }); + + final List allDirs = [ + null, + StorageDirectory.music, + StorageDirectory.podcasts, + StorageDirectory.ringtones, + StorageDirectory.alarms, + StorageDirectory.notifications, + StorageDirectory.pictures, + StorageDirectory.movies, + ]; + + for (final StorageDirectory? type in allDirs) { + testWidgets('getExternalStorageDirectories (type: $type)', + (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + + final List? directories = + await provider.getExternalStoragePaths(type: type); + expect(directories, isNotNull); + expect(directories, isNotEmpty); + for (final String result in directories!) { + _verifySampleFile(result, '$type'); + } + }); + } +} + +/// Verify a file called [name] in [directoryPath] by recreating it with test +/// contents when necessary. +void _verifySampleFile(String? directoryPath, String name) { + expect(directoryPath, isNotNull); + if (directoryPath == null) { + return; + } + final Directory directory = Directory(directoryPath); + final File file = File('${directory.path}${Platform.pathSeparator}$name'); + + if (file.existsSync()) { + file.deleteSync(); + expect(file.existsSync(), isFalse); + } + + file.writeAsStringSync('Hello world!'); + expect(file.readAsStringSync(), 'Hello world!'); + expect(directory.listSync(), isNotEmpty); + file.deleteSync(); +} diff --git a/ohos/automated_testing_demo/integration_test/sqflite_test.dart b/ohos/automated_testing_demo/integration_test/sqflite_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..3748318fc0f001c6ea0700dc501748687ba399a5 --- /dev/null +++ b/ohos/automated_testing_demo/integration_test/sqflite_test.dart @@ -0,0 +1,119 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import 'dart:io'; +import 'dart:io' as io; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart' hide test; +import 'package:path/path.dart'; +import 'package:sqflite/sqflite.dart'; +import 'package:test/test.dart' show test; +import 'dart:math'; + +void main() { + WidgetsFlutterBinding.ensureInitialized(); + Database? _database; + final String _tableName = "users"; + test('open-data', () async { + var _dbName = "${Random().nextInt(36000)}.db"; + try { + _database = await openDatabase(_dbName); + final path = await getDatabasesPath(); + print("====open-data-success:$path"); + } catch (error) { + print('====open-data-error' + error.toString()); + } + }); + + test('create', () async { + if (_database != null) { + try { + await _database!.execute( + "CREATE TABLE $_tableName(id INTEGER PRIMARY KEY, name TEXT, age INTEGER)"); + print('====create-success'); + } catch (error) { + print('====create-error:' + error.toString()); + } + } + }); + test('insert-data', () async { + if (_database != null) { + try { + final id = + await _database!.insert(_tableName, {'name': 'John', 'age': 25}); + print("====insert-data-success:id=$id"); + } catch (error) { + print("====insert-data-error:id=" + error.toString()); + } + } + }); + test('check-data', () async { + if (_database != null) { + final maps = await _database!.query(_tableName); + print('====check-data-success:' + + maps.map((map) => map.toString()).join("\n").toString()); + } + }); + test('update', () async { + if (_database != null) { + try { + final changeRows = await _database!.update( + _tableName, {'name': 'Jack', 'age': 25}, + where: 'id = ?', whereArgs: [2]); + print("====update-success:$changeRows"); + } catch (error) { + print("====update-error:" + error.toString()); + } + } + }); + test('update-raw', () async { + if (_database != null) { + try { + final changeRows = await _database!.rawUpdate( + 'UPDATE $_tableName SET name = ?, age = ? WHERE id = ?', + ['Jack', 25, 1]); + print("====update-raw-success:$changeRows"); + } catch (error) { + print("====update-raw-error:" + error.toString()); + } + } + }); + test('update-raw-1', () async { + if (_database != null) { + try { + final changeRows = await _database!.rawUpdate( + 'UPDATE OR ROLLBACK $_tableName Set name = ?, age = ? WHERE name = ?', + ['Marco', 25, "Jack"]); + print("====update-raw-1-success:$changeRows"); + } catch (error) { + print("====update-raw-1-error:" + error.toString()); + } + } + }); + + test('delete-raw', () async { + if (_database != null) { + try { + int count = await _database! + .rawDelete("DELETE FROM $_tableName WHERE id = ?", [2]); + print("====delete-raw-success:$count"); + } catch (e) { + print("====delete-raw-error:" + e.toString()); + } + } + }); +} diff --git a/ohos/automated_testing_demo/lib/main.dart b/ohos/automated_testing_demo/lib/main.dart new file mode 100644 index 0000000000000000000000000000000000000000..226a7c8087f73c47f2103d40eb0b72f1a63afe52 --- /dev/null +++ b/ohos/automated_testing_demo/lib/main.dart @@ -0,0 +1,129 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import 'package:flutter/material.dart'; + +void main() { + runApp(const MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + + // This widget is the root of your application. + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Demo', + theme: ThemeData( + // This is the theme of your application. + // + // Try running your application with "flutter run". You'll see the + // application has a blue toolbar. Then, without quitting the app, try + // changing the primarySwatch below to Colors.green and then invoke + // "hot reload" (press "r" in the console where you ran "flutter run", + // or simply save your changes to "hot reload" in a Flutter IDE). + // Notice that the counter didn't reset back to zero; the application + // is not restarted. + primarySwatch: Colors.blue, + ), + home: const MyHomePage(title: 'Flutter Demo Home Page'), + ); + } +} + +class MyHomePage extends StatefulWidget { + const MyHomePage({super.key, required this.title}); + + // This widget is the home page of your application. It is stateful, meaning + // that it has a State object (defined below) that contains fields that affect + // how it looks. + + // This class is the configuration for the state. It holds the values (in this + // case the title) provided by the parent (in this case the App widget) and + // used by the build method of the State. Fields in a Widget subclass are + // always marked "final". + + final String title; + + @override + State createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + int _counter = 0; + + void _incrementCounter() { + setState(() { + // This call to setState tells the Flutter framework that something has + // changed in this State, which causes it to rerun the build method below + // so that the display can reflect the updated values. If we changed + // _counter without calling setState(), then the build method would not be + // called again, and so nothing would appear to happen. + _counter++; + }); + } + + @override + Widget build(BuildContext context) { + // This method is rerun every time setState is called, for instance as done + // by the _incrementCounter method above. + // + // The Flutter framework has been optimized to make rerunning build methods + // fast, so that you can just rebuild anything that needs updating rather + // than having to individually change instances of widgets. + return Scaffold( + appBar: AppBar( + // Here we take the value from the MyHomePage object that was created by + // the App.build method, and use it to set our appbar title. + title: Text(widget.title), + ), + body: Center( + // Center is a layout widget. It takes a single child and positions it + // in the middle of the parent. + child: Column( + // Column is also a layout widget. It takes a list of children and + // arranges them vertically. By default, it sizes itself to fit its + // children horizontally, and tries to be as tall as its parent. + // + // Invoke "debug painting" (press "p" in the console, choose the + // "Toggle Debug Paint" action from the Flutter Inspector in Android + // Studio, or the "Toggle Debug Paint" command in Visual Studio Code) + // to see the wireframe for each widget. + // + // Column has various properties to control how it sizes itself and + // how it positions its children. Here we use mainAxisAlignment to + // center the children vertically; the main axis here is the vertical + // axis because Columns are vertical (the cross axis would be + // horizontal). + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + 'You have pushed the button this many times:', + ), + Text( + '$_counter', + style: Theme.of(context).textTheme.headlineMedium, + ), + ], + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), + ), // This trailing comma makes auto-formatting nicer for build methods. + ); + } +} diff --git a/ohos/automated_testing_demo/ohos/.gitignore b/ohos/automated_testing_demo/ohos/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6ca13b3170eec5dd5ac5ad7f1c4dd0118845f473 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/.gitignore @@ -0,0 +1,19 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +*.har +**/BuildProfile.ets +**/oh-package-lock.json5 + +**/src/main/resources/rawfile/flutter_assets/ +**/libs/arm64-v8a/libapp.so +**/libs/arm64-v8a/libflutter.so +**/libs/arm64-v8a/libvmservice_snapshot.so diff --git a/ohos/automated_testing_demo/ohos/AppScope/app.json5 b/ohos/automated_testing_demo/ohos/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cd095e05b0af9794ecd7fd00a98f735dd7378792 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.automated_testing_demo", + "vendor": "example", + "versionCode": 1, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/AppScope/resources/base/element/string.json b/ohos/automated_testing_demo/ohos/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b9684802b8175573a5a4828caecb217166a590a6 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "automated_testing_demo" + } + ] +} diff --git a/ohos/automated_testing_demo/ohos/AppScope/resources/base/media/app_icon.png b/ohos/automated_testing_demo/ohos/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ohos/automated_testing_demo/ohos/AppScope/resources/base/media/app_icon.png differ diff --git a/ohos/automated_testing_demo/ohos/build-profile.json5 b/ohos/automated_testing_demo/ohos/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..561a36478a9ac94d1de7a86b64a9daa64a333a5c --- /dev/null +++ b/ohos/automated_testing_demo/ohos/build-profile.json5 @@ -0,0 +1,41 @@ +{ + "app": { + "signingConfigs": [ + { + "name": "default", + "type": "HarmonyOS", + "material": { + "certpath": "C:\\Users\\Administrator\\.ohos\\config\\default_ohos_40hhdj5Jg8RlmmtplzoMiaZKM5CxvELfwpQ5nEFpH0A=.cer", + "storePassword": "0000001A82C4B99BCBC7D8A4318245EA01B80F89364FE2958C9AF49E831D110F67B16493571145BD2BAD", + "keyAlias": "debugKey", + "keyPassword": "0000001AF2C7BE6AED3B46BA858F3B3A35C89D45802254C5BE282E15236B43C15CCFA52231926E03177F", + "profile": "C:\\Users\\Administrator\\.ohos\\config\\default_ohos_40hhdj5Jg8RlmmtplzoMiaZKM5CxvELfwpQ5nEFpH0A=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:\\Users\\Administrator\\.ohos\\config\\default_ohos_40hhdj5Jg8RlmmtplzoMiaZKM5CxvELfwpQ5nEFpH0A=.p12" + } + } + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/.gitignore b/ohos/automated_testing_demo/ohos/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..2795a1c5b1fe53659dd1b71d90ba0592eaf7e043 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/.gitignore @@ -0,0 +1,7 @@ + +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/build-profile.json5 b/ohos/automated_testing_demo/ohos/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..633d360fbc91a3186a23b66ab71b27e5618944cb --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/build-profile.json5 @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "HarmonyOS" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/hvigorfile.ts b/ohos/automated_testing_demo/ohos/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..894fc15c6b793f085e6c8506e43d719af658e8ff --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/hvigorfile.ts @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/ohos/automated_testing_demo/ohos/entry/oh-package.json5 b/ohos/automated_testing_demo/ohos/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a443273ff60e9cf3e7cdd4563674472cfa40170c --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/oh-package.json5 @@ -0,0 +1,13 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "integration_test": "file:../har/integration_test.har", + "sqflite_helper": "file:../har/sqflite_helper.har", + "path_provider_ohos": "file:../har/path_provider_ohos.har" + } +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/main/ets/entryability/EntryAbility.ets b/ohos/automated_testing_demo/ohos/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8bc48be8773196f34cccb15cf517f87f5c6b94d2 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { FlutterAbility, FlutterEngine } from '@ohos/flutter_ohos'; +import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant'; + +export default class EntryAbility extends FlutterAbility { + configureFlutterEngine(flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + GeneratedPluginRegistrant.registerWith(flutterEngine) + } +} diff --git a/ohos/automated_testing_demo/ohos/entry/src/main/ets/pages/Index.ets b/ohos/automated_testing_demo/ohos/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1125f9fdd95f4310a182c1c9e3680f37f73686c9 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import common from '@ohos.app.ability.common'; +import { FlutterPage } from '@ohos/flutter_ohos' + +let storage = LocalStorage.getShared() +const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS' + +@Entry(storage) +@Component +struct Index { + private context = getContext(this) as common.UIAbilityContext + @LocalStorageLink('viewId') viewId: string = ""; + + build() { + Column() { + FlutterPage({ viewId: this.viewId }) + } + } + + onBackPress(): boolean { + this.context.eventHub.emit(EVENT_BACK_PRESS) + return true + } +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets b/ohos/automated_testing_demo/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets new file mode 100644 index 0000000000000000000000000000000000000000..f5ed54120b5a3eb23a08c60aaf17fb495496f314 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import { FlutterEngine, Log } from '@ohos/flutter_ohos'; +import IntegrationTestPlugin from 'integration_test'; +import PathProviderPlugin from 'path_provider_ohos'; +import SqfliteHelperPlugin from 'sqflite_helper'; + +/** + * Generated file. Do not edit. + * This file is generated by the Flutter tool based on the + * plugins that support the Ohos platform. + */ + +const TAG = "GeneratedPluginRegistrant"; + +export class GeneratedPluginRegistrant { + + static registerWith(flutterEngine: FlutterEngine) { + try { + flutterEngine.getPlugins()?.add(new IntegrationTestPlugin()); + flutterEngine.getPlugins()?.add(new PathProviderPlugin()); + flutterEngine.getPlugins()?.add(new SqfliteHelperPlugin()); + } catch (e) { + Log.e( + TAG, + "Tried to register plugins with FlutterEngine (" + + flutterEngine + + ") failed."); + Log.e(TAG, "Received exception while registering", e); + } + } +} diff --git a/ohos/automated_testing_demo/ohos/entry/src/main/module.json5 b/ohos/automated_testing_demo/ohos/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7bbf78b18f39991b1404061c7437538c7d532bb7 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/main/module.json5 @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + {"name" : "ohos.permission.INTERNET"}, + ] + } +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/main/resources/base/element/color.json b/ohos/automated_testing_demo/ohos/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/main/resources/base/element/string.json b/ohos/automated_testing_demo/ohos/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3ceb2477c50bef6fc35abbc480870ec70439e12a --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "automated_testing_demo" + } + ] +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/main/resources/base/media/icon.png b/ohos/automated_testing_demo/ohos/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ohos/automated_testing_demo/ohos/entry/src/main/resources/base/media/icon.png differ diff --git a/ohos/automated_testing_demo/ohos/entry/src/main/resources/base/profile/main_pages.json b/ohos/automated_testing_demo/ohos/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ohos/automated_testing_demo/ohos/entry/src/main/resources/en_US/element/string.json b/ohos/automated_testing_demo/ohos/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3ceb2477c50bef6fc35abbc480870ec70439e12a --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "automated_testing_demo" + } + ] +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/main/resources/zh_CN/element/string.json b/ohos/automated_testing_demo/ohos/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..98013f5f18db51841024a09323da410bfcd3b298 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "automated_testing_demo" + } + ] +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/test/Ability.test.ets b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..25d4c71ff3cd584f5d64f6f8c0ac864928c234c4 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +export default function abilityTest() { + describe('ActsAbilityTest', function () { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(function () { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(function () { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(function () { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(function () { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain',0, function () { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc' + let b = 'b' + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b) + expect(a).assertEqual(a) + }) + }) +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/test/List.test.ets b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f4140030e65d20df6af30a6bf51e464dea8f8aa6 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ca645e6013cfce8e7dbb728313cb8840c4da660 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import hilog from '@ohos.hilog'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import window from '@ohos.window'; + +export default class TestAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..cef0447cd2f137ef82d223ead2e156808878ab90 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..1def08f2e9dcbfa3454a07b7a3b82b173bb90d02 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/ohosTest/module.json5 b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fab77ce2e0c61e3ad010bab5b27ccbd15f9a8c96 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/module.json5 @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/ohos/automated_testing_demo/ohos/entry/src/ohosTest/resources/base/element/color.json b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/ohosTest/resources/base/element/string.json b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/entry/src/ohosTest/resources/base/media/icon.png b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/ohos/automated_testing_demo/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b7e7343cacb32ce982a45e76daad86e435e054fe --- /dev/null +++ b/ohos/automated_testing_demo/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/ohos/automated_testing_demo/ohos/hvigor/hvigor-config.json5 b/ohos/automated_testing_demo/ohos/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..541ba35711b75986f9295410ee38fdb8f2572878 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/hvigor/hvigor-config.json5 @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "modelVersion": "5.0.0", + "dependencies": { + } +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/hvigorfile.ts b/ohos/automated_testing_demo/ohos/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..8f2d2aafe6d6a3a71a9944ebd0c91fbc308ac9d1 --- /dev/null +++ b/ohos/automated_testing_demo/ohos/hvigorfile.ts @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/ohos/oh-package.json5 b/ohos/automated_testing_demo/ohos/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..53878723ef0d3fa114a83c296cf05ef3ae5aa83e --- /dev/null +++ b/ohos/automated_testing_demo/ohos/oh-package.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.0.0", + "name": "automated_testing_demo", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "@ohos/flutter_ohos": "file:./har/flutter.har" + }, + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "overrides": { + "@ohos/flutter_ohos": "file:./har/flutter.har", + "sqflite_helper": "file:./har/sqflite_helper.har", + "integration_test": "file:./har/integration_test.har", + "@ohos/flutter_module": "file:./entry", + "path_provider_ohos": "file:./har/path_provider_ohos.har" + } +} \ No newline at end of file diff --git a/ohos/automated_testing_demo/pubspec.yaml b/ohos/automated_testing_demo/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..291999e902bc517c9760a7ed5958eba5ff965396 --- /dev/null +++ b/ohos/automated_testing_demo/pubspec.yaml @@ -0,0 +1,119 @@ +name: automated_testing_demo +description: A new Flutter project. +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# In Android, build-name is used as versionName while build-number used as versionCode. +# Read more about Android versioning at https://developer.android.com/studio/publish/versioning +# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. +# Read more about iOS versioning at +# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +# In Windows, build-name is used as the major, minor, and patch parts +# of the product and file versions while build-number is used as the build suffix. +version: 1.0.0+1 + +environment: + sdk: '>=2.19.6 <3.0.0' + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + path: any + collection: any + flutter: + sdk: flutter + path_provider_android: ^2.1.0 + path_provider_foundation: ^2.3.0 + path_provider_linux: ^2.2.0 + path_provider_platform_interface: ^2.1.0 + path_provider_ohos: + git: + url: "https://gitee.com/openharmony-sig/flutter_packages.git" + path: "packages/path_provider/path_provider_ohos" + sqflite: + sqflite_common: + synchronized: + matcher: + meta: + vm_service_lib: + sqflite_helper: + # When depending on this package from a real application you should use: + # sqflite_helper: ^x.y.z + # See https://dart.dev/tools/pub/dependencies#version-constraints + # The example app is bundled with the plugin so we use a path dependency on + # the parent directory to use the current plugin's version. + # path: /Users/liaochengjin/Documents/lzb/sqflite_helper/ + git: + url: https://gitee.com/simplelove520/sqflite_helper.git + path: + + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.2 + +dev_dependencies: + integration_test: + sdk: flutter + flutter_test: + sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^2.0.0 + test: + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/custom-fonts/#from-packages diff --git a/ohos/automated_testing_demo/test/widget_test.dart b/ohos/automated_testing_demo/test/widget_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..c259f1b7b95f038698f422211280d48ef5168eef --- /dev/null +++ b/ohos/automated_testing_demo/test/widget_test.dart @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:automated_testing_demo/main.dart'; + +void main() { + testWidgets('Counter increments smoke test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + // Verify that our counter starts at 0. + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + + // Tap the '+' icon and trigger a frame. + await tester.tap(find.byIcon(Icons.add)); + await tester.pump(); + + // Verify that our counter has incremented. + expect(find.text('0'), findsNothing); + expect(find.text('1'), findsOneWidget); + }); +} diff --git a/ohos/node_test_server/bats/createxlsx.bat b/ohos/node_test_server/bats/createxlsx.bat new file mode 100644 index 0000000000000000000000000000000000000000..453c4ffe87462c26351ef9bc117afd0bec6fbaa8 --- /dev/null +++ b/ohos/node_test_server/bats/createxlsx.bat @@ -0,0 +1,13 @@ +@REM Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +@REM Licensed under the Apache License, Version 2.0 (the "License"); +@REM you may not use this file except in compliance with the License. +@REM You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, software +@REM distributed under the License is distributed on an "AS IS" BASIS, +@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@REM See the License for the specific language governing permissions and +@REM limitations under the License. +cd ../ & npm start \ No newline at end of file diff --git a/ohos/node_test_server/bats/keyChannelTest.bat b/ohos/node_test_server/bats/keyChannelTest.bat new file mode 100644 index 0000000000000000000000000000000000000000..902bfaee65504b87201d4a215f9bace2b4edf746 --- /dev/null +++ b/ohos/node_test_server/bats/keyChannelTest.bat @@ -0,0 +1,13 @@ +@REM Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +@REM Licensed under the Apache License, Version 2.0 (the "License"); +@REM you may not use this file except in compliance with the License. +@REM You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, software +@REM distributed under the License is distributed on an "AS IS" BASIS, +@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@REM See the License for the specific language governing permissions and +@REM limitations under the License. +cd ..\..\automated_testing_demo && flutter test .\integration_test\key_input_test.dart --machine > ..\node_test_server\logs\key_input_test.txt \ No newline at end of file diff --git a/ohos/node_test_server/bats/pathProvideTest.bat b/ohos/node_test_server/bats/pathProvideTest.bat new file mode 100644 index 0000000000000000000000000000000000000000..63922d6c7d97f166bdeda8267d6fafbcb4b06fbb --- /dev/null +++ b/ohos/node_test_server/bats/pathProvideTest.bat @@ -0,0 +1,13 @@ +@REM Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +@REM Licensed under the Apache License, Version 2.0 (the "License"); +@REM you may not use this file except in compliance with the License. +@REM You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, software +@REM distributed under the License is distributed on an "AS IS" BASIS, +@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@REM See the License for the specific language governing permissions and +@REM limitations under the License. +cd ..\..\automated_testing_demo && flutter test .\integration_test\path_provider_test.dart --machine > ..\node_test_server\logs\path_provider_test.txt \ No newline at end of file diff --git a/ohos/node_test_server/bats/sqfliteTest.bat b/ohos/node_test_server/bats/sqfliteTest.bat new file mode 100644 index 0000000000000000000000000000000000000000..4be87865f44508c19a46bbb5c3acba5db351099b --- /dev/null +++ b/ohos/node_test_server/bats/sqfliteTest.bat @@ -0,0 +1,14 @@ +@REM Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +@REM Licensed under the Apache License, Version 2.0 (the "License"); +@REM you may not use this file except in compliance with the License. +@REM You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, software +@REM distributed under the License is distributed on an "AS IS" BASIS, +@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@REM See the License for the specific language governing permissions and +@REM limitations under the License. + +cd ..\..\automated_testing_demo && flutter test .\integration_test\sqflite_test.dart --machine > ..\node_test_server\logs\sqflite_test.txt \ No newline at end of file diff --git a/ohos/node_test_server/bats/update.bat b/ohos/node_test_server/bats/update.bat new file mode 100644 index 0000000000000000000000000000000000000000..0b40ae62279d93fd8945053138eacc6060d3f7c8 --- /dev/null +++ b/ohos/node_test_server/bats/update.bat @@ -0,0 +1,15 @@ +@REM Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +@REM Licensed under the Apache License, Version 2.0 (the "License"); +@REM you may not use this file except in compliance with the License. +@REM You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, software +@REM distributed under the License is distributed on an "AS IS" BASIS, +@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@REM See the License for the specific language governing permissions and +@REM limitations under the License. + +for /f "delims=" %i in ('where flutter') do @cd /d "%~dpi" && git pull +timeout /t 10 \ No newline at end of file diff --git a/ohos/node_test_server/index.bat b/ohos/node_test_server/index.bat new file mode 100644 index 0000000000000000000000000000000000000000..34036ffbb137c9af7c07bb567f6a3627d5af515b --- /dev/null +++ b/ohos/node_test_server/index.bat @@ -0,0 +1,29 @@ +@REM Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +@REM Licensed under the Apache License, Version 2.0 (the "License"); +@REM you may not use this file except in compliance with the License. +@REM You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, software +@REM distributed under the License is distributed on an "AS IS" BASIS, +@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@REM See the License for the specific language governing permissions and +@REM limitations under the License. +@echo off +chcp 65001 +cd ./bats +echo 测试sqflite库 +start sqfliteTest.bat +timeout /t 130 + +echo 测试pathProvide库 +start pathProvideTest.bat +timeout /t 130 + +echo 测试keyChannel库 +start keyChannelTest.bat +timeout /t 130 + +echo 生成表格 +start createxlsx.bat diff --git a/ohos/node_test_server/index.js b/ohos/node_test_server/index.js new file mode 100644 index 0000000000000000000000000000000000000000..54d1e9b6ffd76654a6ea10c8dfa98c87f29006a9 --- /dev/null +++ b/ohos/node_test_server/index.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +process.stdout.setEncoding('utf-8'); +const Excel = require('exceljs'); + +const fs = require('fs'); +const path = require('path'); +const fileUrl = './logs'; +const files = fs.readdirSync(fileUrl); + +var time = new Date(); +var dirName = (time.getMonth() + 1) + '' + time.getDate() +try { + if (!fs.existsSync(path.resolve(__dirname, dirName))) { + fs.mkdirSync(path.resolve(__dirname, dirName), { recursive: true }); + } else { + } +} catch (err) { + console.error(err); +} +const workbook = new Excel.Workbook(); +files.forEach(async item => { + var fileStr = fs.readFileSync(fileUrl + '/' + item, 'utf8'); + const result = fomateTxt(fileStr) + const sheet = workbook.addWorksheet(item); + sheet.columns = [ + { header: '测试项', key: 'testName', width: 20 }, + { header: '结果', key: 'result', width: 10 }, + { header: '打印值', key: 'message', width: 50 }, + { header: '路径', key: 'testUrl', width: 50 }, + ]; + result.forEach(item => { + sheet.addRow(item) + }) + // 通过流发送文件 +}) + +workbook.xlsx.writeFile(dirName + '/' + time.getHours() + '-' + time.getMinutes() + '.xlsx'); + +function fomateTxt(data) { + let result = []; + let resultMap = new Map(); + data.split('\n').forEach(item => { + if (/^\{.*\}$/.test(item)) { + const itemJson = JSON.parse(item); + if (itemJson.type === 'testStart') { + resultMap.set(itemJson.test.id, { ...itemJson, messageList: [] }); + } + if (itemJson.testID) { + const newItem = resultMap.get(itemJson.testID); + if (itemJson.type === 'testDone') { + newItem.result = itemJson.result; + } else if (itemJson.type === 'print') { + newItem.messageList.push(itemJson.message); + } + resultMap.set(itemJson.testID, newItem) + } + } + }) + for (let [key, mapValue] of resultMap) { + mapValue.testName = mapValue.test.name + mapValue.testUrl = mapValue.test.url + mapValue.message = mapValue.messageList.join('\n'); + result.push(mapValue); + } + return result; +} \ No newline at end of file diff --git a/ohos/node_test_server/package.json b/ohos/node_test_server/package.json new file mode 100644 index 0000000000000000000000000000000000000000..bb3f0c476e070af95d9a48f5e18da0c8405d0d36 --- /dev/null +++ b/ohos/node_test_server/package.json @@ -0,0 +1,19 @@ +{ + "name": "nodeserver", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "start": "node ./index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "exceljs": "^4.4.0", + "express": "^4.21.1", + "iconv-lite": "^0.6.3", + "xlsx": "^0.18.5" + } +}