Commit b4e41ff7 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Add a devicelab task that generates sample app screenshots, etc (#10303)

parent 9452a344
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/tasks/sample_catalog_generator.dart';
Future<Null> main() async {
deviceOperatingSystem = DeviceOperatingSystem.android;
await task(samplePageCatalogGenerator);
}
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/tasks/sample_catalog_generator.dart';
Future<Null> main() async {
deviceOperatingSystem = DeviceOperatingSystem.ios;
await task(samplePageCatalogGenerator);
}
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import '../framework/adb.dart';
import '../framework/framework.dart';
import '../framework/ios.dart';
import '../framework/utils.dart';
Future<TaskResult> samplePageCatalogGenerator() async {
final Device device = await devices.workingDevice;
await device.unlock();
final String deviceId = device.deviceId;
final Directory catalogDirectory = dir('${flutterDirectory.path}/examples/catalog');
await inDirectory(catalogDirectory, () async {
await flutter('packages', options: <String>['get']);
if (deviceOperatingSystem == DeviceOperatingSystem.ios) {
await prepareProvisioningCertificates(catalogDirectory.path);
// This causes an Xcode project to be created.
await flutter('build', options: <String>['ios', '--profile']);
}
await dart(<String>['bin/sample_page.dart']);
await flutter('drive', options: <String>[
'test_driver/screenshot.dart',
'-d',
deviceId,
]);
});
return new TaskResult.success(null);
}
...@@ -171,6 +171,13 @@ tasks: ...@@ -171,6 +171,13 @@ tasks:
stage: devicelab stage: devicelab
required_agent_capabilities: ["has-android-device"] required_agent_capabilities: ["has-android-device"]
android_sample_catalog_generator:
description: >
Builds sample catalog markdown pages and Android screenshots
stage: devicelab
required_agent_capabilities: ["has-android-device"]
flaky: true
# iOS on-device tests # iOS on-device tests
channels_integration_test_ios: channels_integration_test_ios:
...@@ -240,6 +247,13 @@ tasks: ...@@ -240,6 +247,13 @@ tasks:
stage: devicelab_ios stage: devicelab_ios
required_agent_capabilities: ["has-ios-device"] required_agent_capabilities: ["has-ios-device"]
ios_sample_catalog_generator:
description: >
Builds sample catalog markdown pages and iOS screenshots
stage: devicelab_ios
required_agent_capabilities: ["has-ios-device"]
flaky: true
# Tests running on Windows host # Tests running on Windows host
channels_integration_test_win: channels_integration_test_win:
......
...@@ -135,6 +135,8 @@ class SampleGenerator { ...@@ -135,6 +135,8 @@ class SampleGenerator {
); );
commentValues[keyword.toLowerCase()] = value.trim(); commentValues[keyword.toLowerCase()] = value.trim();
} }
commentValues['name'] = sourceName;
commentValues['path'] = 'examples/catalog/${sourceFile.path}';
commentValues['source'] = sourceCode.trim(); commentValues['source'] = sourceCode.trim();
return true; return true;
...@@ -177,14 +179,12 @@ void generate() { ...@@ -177,14 +179,12 @@ void generate() {
screenshotDriverTemplate, screenshotDriverTemplate,
<String, String>{ <String, String>{
'paths': samples.map((SampleGenerator sample) { 'paths': samples.map((SampleGenerator sample) {
return "'${outputFile(sample.sourceName + '.png').path}'"; return "'${outputFile('\${prefix}' + sample.sourceName + '.png').path}'";
}).toList().join(',\n'), }).toList().join(',\n'),
}, },
); );
final List<String> flutterDriveArgs = <String>['drive', 'test_driver/screenshot.dart']; // To generate the screenshots: flutter drive test_driver/screenshot.dart
logMessage('Generating screenshots with: flutter ${flutterDriveArgs.join(" ")}');
Process.runSync('flutter', flutterDriveArgs);
} }
void main(List<String> args) { void main(List<String> args) {
......
@(title) ---
============= catalog: @(name)
title: "@(title)"
permalink: /catalog/@(name)/
---
@(summary) @(summary)
...@@ -8,6 +12,7 @@ ...@@ -8,6 +12,7 @@
See also: See also:
@(see also) @(see also)
``` ```dart
@(source) @(source)
``` ```
The source code is based on [@(path)](https://github.com/flutter/flutter/blob/master/@(path)).
...@@ -36,5 +36,6 @@ class SampleScreenshotsState extends State<SampleScreenshots> { ...@@ -36,5 +36,6 @@ class SampleScreenshotsState extends State<SampleScreenshots> {
void main() { void main() {
enableFlutterDriverExtension(); enableFlutterDriverExtension();
WidgetsApp.debugAllowBannerOverride = false; // No "slow mode" banner.
runApp(new SampleScreenshots()); runApp(new SampleScreenshots());
} }
...@@ -7,7 +7,7 @@ import 'package:flutter_driver/flutter_driver.dart'; ...@@ -7,7 +7,7 @@ import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
void main() { void main() {
group('sample screenshots', () async { group('sample screenshots', () {
FlutterDriver driver; FlutterDriver driver;
setUpAll(() async { setUpAll(() async {
...@@ -19,6 +19,7 @@ void main() { ...@@ -19,6 +19,7 @@ void main() {
}); });
test('take sample screenshots', () async { test('take sample screenshots', () async {
String prefix = Platform.isMacOS ? 'ios_' : "";
final List<String> paths = <String>[ final List<String> paths = <String>[
@(paths) @(paths)
]; ];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment