add smoke driver test; find by tooltip; retry predicate

This commit is contained in:
Yegor Jbanov
2016-02-28 23:47:30 -08:00
parent 6a1f47a532
commit 6d35481cfa
13 changed files with 265 additions and 86 deletions

View File

@@ -55,6 +55,20 @@ bool _addPackage(String directoryPath, List<String> dartFiles, Set<String> pubSp
}
}
Directory testDriverDirectory = new Directory(path.join(directoryPath, 'test_driver'));
if (testDriverDirectory.existsSync()) {
for (FileSystemEntity entry in testDriverDirectory.listSync()) {
if (entry is Directory) {
for (FileSystemEntity subentry in entry.listSync()) {
if (isDartTestFile(subentry))
dartFiles.add(subentry.path);
}
} else if (isDartTestFile(entry)) {
dartFiles.add(entry.path);
}
}
}
Directory benchmarkDirectory = new Directory(path.join(directoryPath, 'benchmark'));
if (benchmarkDirectory.existsSync()) {
for (FileSystemEntity entry in benchmarkDirectory.listSync()) {
@@ -76,6 +90,18 @@ bool _addPackage(String directoryPath, List<String> dartFiles, Set<String> pubSp
return false;
}
/// Adds all packages in [subPath], assuming a flat directory structure, i.e.
/// each direct child of [subPath] is a plain Dart package.
void _addFlatPackageList(String subPath, List<String> dartFiles, Set<String> pubSpecDirectories) {
Directory subdirectory = new Directory(path.join(ArtifactStore.flutterRoot, subPath));
if (subdirectory.existsSync()) {
for (FileSystemEntity entry in subdirectory.listSync()) {
if (entry is Directory)
_addPackage(entry.path, dartFiles, pubSpecDirectories);
}
}
}
class FileChanged { }
class AnalyzeCommand extends FlutterCommand {
@@ -146,24 +172,11 @@ class AnalyzeCommand extends FlutterCommand {
//dev/manual_tests/*/ as package
//dev/manual_tests/*/ as files
_addFlatPackageList('packages', dartFiles, pubSpecDirectories);
_addFlatPackageList('examples', dartFiles, pubSpecDirectories);
Directory subdirectory;
subdirectory = new Directory(path.join(ArtifactStore.flutterRoot, 'packages'));
if (subdirectory.existsSync()) {
for (FileSystemEntity entry in subdirectory.listSync()) {
if (entry is Directory)
_addPackage(entry.path, dartFiles, pubSpecDirectories);
}
}
subdirectory = new Directory(path.join(ArtifactStore.flutterRoot, 'examples'));
if (subdirectory.existsSync()) {
for (FileSystemEntity entry in subdirectory.listSync()) {
if (entry is Directory)
_addPackage(entry.path, dartFiles, pubSpecDirectories);
}
}
subdirectory = new Directory(path.join(ArtifactStore.flutterRoot, 'examples', 'layers'));
if (subdirectory.existsSync()) {
bool foundOne = false;
@@ -198,7 +211,7 @@ class AnalyzeCommand extends FlutterCommand {
}
dartFiles = dartFiles.map((String directory) => path.normalize(path.absolute(directory))).toSet().toList();
dartFiles = dartFiles.map((String directory) => path.normalize(path.absolute(directory))).toSet().toList();
dartFiles.sort();
// prepare a Dart file that references all the above Dart files
@@ -444,4 +457,3 @@ linter:
return 0;
}
}

View File

@@ -118,7 +118,7 @@ class DriveCommand extends RunCommandBase {
await appStopper(this);
} catch(error, stackTrace) {
// TODO(yjbanov): remove this guard when this bug is fixed: https://github.com/dart-lang/sdk/issues/25862
printStatus('Could not stop application: $error\n$stackTrace');
printTrace('Could not stop application: $error\n$stackTrace');
}
} else {
printStatus('Leaving the application running.');

View File

@@ -1,6 +1,14 @@
import 'package:flutter/material.dart';
{{#withDriverTest?}}
import 'package:flutter_driver/driver_extension.dart';
{{/withDriverTest?}}
void main() {
{{#withDriverTest?}}
// Starts the app with Flutter Driver extension enabled to allow Flutter Driver
// to test the app.
enableFlutterDriverExtension();
{{/withDriverTest?}}
runApp(
new MaterialApp(
title: 'Flutter Demo',

View File

@@ -1,9 +0,0 @@
// Starts the app with Flutter Driver extension enabled to allow Flutter Driver
// to test the app.
import 'package:{{projectName}}/main.dart' as app;
import 'package:flutter_driver/driver_extension.dart';
main() {
enableFlutterDriverExtension();
app.main();
}

View File

@@ -22,28 +22,20 @@ main() {
});
tearDownAll(() async {
if (driver != null) driver.close();
});
test('find the floating action button by value key', () async {
ObjectRef elem = await driver.findByValueKey('fab');
expect(elem, isNotNull);
expect(elem.objectReferenceKey, isNotNull);
if (driver != null)
driver.close();
});
test('tap on the floating action button; verify counter', () async {
// Find floating action button (fab) to tap on
ObjectRef fab = await driver.findByValueKey('fab');
ObjectRef fab = await driver.findByTooltipMessage('Increment');
expect(fab, isNotNull);
// Tap on the fab
await driver.tap(fab);
// Wait for text to change to the desired value
await driver.waitFor(() async {
ObjectRef counter = await driver.findByValueKey('counter');
return await driver.getText(counter);
}, contains("Button tapped 1 times."));
expect(await driver.findByText('Button tapped 1 time.'), isNotNull);
});
});
}