Skip to content

Commit

Permalink
Testing driver helper methods & platform auto platform detection
Browse files Browse the repository at this point in the history
  • Loading branch information
hmziqrs committed Jul 22, 2020
1 parent ae98c28 commit e4cbd29
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 24 deletions.
1 change: 0 additions & 1 deletion lib/Navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import './configs/Theme.dart' as theme;
import 'package:flutter_uis/io/io.dart';

import 'package:flutter_uis/AppLocalizations.dart';
import 'Dummy.dart';
import 'Providers/AppProvider.dart';

import 'screens/Home/Home.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/Widgets/Screen/widgets/ScreenSettingsModalBody.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final Map<String, Map<String, String>> map = {
"emoji": Emojis.flagChina,
},
"ar": {
"label": "صينى",
"label": "عربى",
"trans": ScreenWidgetMessages.smArabic,
"emoji": Emojis.flagSaudiArabia,
},
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/Home/Home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class _HomeScreenState extends State<HomeScreen> {
(item) => Container(
width: double.infinity,
child: OutlineButton(
key: Key(item["key"]),
textColor: theme.primary,
borderSide: BorderSide(
width: 1.5,
Expand Down Expand Up @@ -146,9 +147,9 @@ class _HomeScreenState extends State<HomeScreen> {
),
mount: this.webPopUpMounted,
opacity: this.webPopUpOpacity,
onEnd: () => setState(() => (this.webPopUpMounted = false)),
onPrimary: () => Navigator.of(context).pushNamed("download"),
onSecondary: () => setState(() => (this.webPopUpOpacity = 0)),
onEnd: () => setState(() => (this.webPopUpMounted = false)),
),
HomeAlertModal(
title: App.translate(
Expand Down
5 changes: 5 additions & 0 deletions lib/screens/Home/TestKeys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ const String scope = "HomeScreen";

abstract class HomeScreenTestKeys {
static final String modalContinueBtn = "$scope/modalContinueBtn";
static final String uiListBtn = '$scope/uiListBtn';
static final String aboutBtn = '$scope/aboutBtn';
static final String aboutDeveloperBtn = '$scope/aboutDeveloperBtn';
static final String downloadBtn = '$scope/downloadBtn';
static final String settingsBtn = '$scope/settingsBtn';
}
6 changes: 6 additions & 0 deletions lib/screens/Home/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,35 @@ import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';

import 'messages/keys.dart';
import 'TestKeys.dart';

final list = [
{
"key": HomeScreenTestKeys.uiListBtn,
"label": HomeScreenMessages.uiList,
"path": 'uiList',
"icon": MaterialCommunityIcons.compass_outline,
},
{
"key": HomeScreenTestKeys.aboutBtn,
"label": HomeScreenMessages.about,
"path": "about",
"icon": Icons.info_outline,
},
{
"key": HomeScreenTestKeys.aboutDeveloperBtn,
"label": HomeScreenMessages.aboutDeveloper,
"path": "aboutDeveloper",
"icon": Icons.info_outline,
},
{
"key": HomeScreenTestKeys.downloadBtn,
"label": HomeScreenMessages.download,
"path": "download",
"icon": MaterialCommunityIcons.cloud_download_outline,
},
{
"key": HomeScreenTestKeys.settingsBtn,
"label": HomeScreenMessages.settings,
"path": "settings",
"icon": MaterialCommunityIcons.settings_outline,
Expand Down
1 change: 0 additions & 1 deletion lib/screens/Home/widgets/HomeAlertModal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter_uis/configs/AppDimensions.dart';

import 'package:flutter_uis/configs/Theme.dart' as theme;
import 'package:flutter_uis/screens/Home/TestKeys.dart';
import 'package:flutter_uis/screens/Home/messages/keys.dart';

class HomeAlertModal extends StatelessWidget {
HomeAlertModal({
Expand Down
10 changes: 5 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ dependencies:
color: ^2.1.1

# Highly experimental plugins
window_size:
git:
url: git://github.com/google/flutter-desktop-embedding.git
path: plugins/window_size
ref: 9e9b68b67c2a2c0b82eed2224f709aff2ccbab7c
# window_size:
# git:
# url: git://github.com/google/flutter-desktop-embedding.git
# path: plugins/window_size
# ref: 9e9b68b67c2a2c0b82eed2224f709aff2ccbab7c

dev_dependencies:
glob: 1.2.0
Expand Down
9 changes: 9 additions & 0 deletions test_driver/actions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:flutter_driver/flutter_driver.dart';

abstract class Actions {
static FlutterDriver driver;

static Future<void> tap(String key) async {
await driver.tap(find.byValueKey(key));
}
}
23 changes: 19 additions & 4 deletions test_driver/app.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import 'package:flutter_driver/driver_extension.dart';
import 'package:flutter_uis/io/io.dart';
import 'package:flutter_uis/main.dart' as app;

void main() {
// This line enables the extension.
enableFlutterDriverExtension();
enableFlutterDriverExtension(handler: (data) async {
if (data == "platform") {
if (Platform.isLinux) {
return "linux";
} else if (Platform.isAndroid) {
return "android";
} else if (Platform.isIOS) {
return "ios";
} else if (Platform.isWindows) {
return "windows";
} else if (Platform.isMacOS) {
return "macos";
} else {
return "web";
}
}
return "enableFlutterDriverExtension";
});

// Call the `main()` function of the app, or call `runApp` with
// any widget you are interested in testing.
app.main();
}
32 changes: 21 additions & 11 deletions test_driver/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,40 @@ import 'package:flutter_driver/flutter_driver.dart';
import 'package:flutter_uis/screens/Home/TestKeys.dart';
import 'package:test/test.dart';

import 'screenshot.dart';
import 'actions.dart';
import 'utils.dart';

void main() async {
group('Counter App', () {
final titleTextFinder = find.byValueKey('title');

FlutterDriver driver;

// Connect to the Flutter driver before running any tests.
setUpAll(() async {
driver = await FlutterDriver.connect();

final platform = await driver.requestData("platform");

Actions.driver = driver;
Screenshot.driver = driver;

Screenshot.platform = platform;
Utils.init(platform);

await driver.clearTimeline();
});

// Close the connection to the driver after the tests have completed.
tearDownAll(() async {
if (driver != null) {
driver.close();
}
driver?.close();
});

test('starts at 0', () async {
// Use the `driver.getText` method to verify the counter starts at 0.
driver.runUnsynchronized(() async {
expect(await driver.getText(titleTextFinder), "Welcome");
await driver.tap(find.byValueKey(HomeScreenTestKeys.modalContinueBtn));
test('Home Screen', () async {
await driver.runUnsynchronized(() async {
if (Utils.isDesktop || Utils.isWeb) {
await Screenshot.screenshot("Home-Screen-Modal");
await Actions.tap(HomeScreenTestKeys.modalContinueBtn);
}
await Screenshot.screenshot("Home-Screen");
});
});
});
Expand Down
23 changes: 23 additions & 0 deletions test_driver/screenshot.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter_driver/flutter_driver.dart';

abstract class Screenshot {
static String platform;
static FlutterDriver driver;

static Future<void> screenshot(String label) async {
switch (platform) {
case "linux":
await screenshotLinux(label);
break;
default:
}
}

static Future<void> screenshotLinux(
String label,
) async {
try {
print("screenName $label");
} catch (e) {}
}
}
16 changes: 16 additions & 0 deletions test_driver/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter_driver/flutter_driver.dart';

abstract class Utils {
static String platform;

static bool isMobile;
static bool isDesktop;
static bool isWeb;

static init(String newPlatform) {
platform = newPlatform;
isMobile = ["android", "ios"].contains(platform);
isDesktop = ["linux", "windows", "macos"].contains(platform);
isWeb = !isMobile && !isDesktop;
}
}

0 comments on commit e4cbd29

Please sign in to comment.