Flutter_driver nnbd (#74856)
This commit is contained in:
@@ -14,10 +14,10 @@ class DriverError extends Error {
|
||||
final String message;
|
||||
|
||||
/// The error object that was caught and wrapped by this error object, if any.
|
||||
final dynamic originalError;
|
||||
final Object? originalError;
|
||||
|
||||
/// The stack trace that was caught and wrapped by this error object, if any.
|
||||
final dynamic originalStackTrace;
|
||||
final Object? originalStackTrace;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
/// Convenience methods for Flutter application driving on Fuchsia. Can
|
||||
/// be run on either a host machine (making a remote connection to a Fuchsia
|
||||
/// device), or on the target Fuchsia machine.
|
||||
@@ -40,13 +38,13 @@ class _DummySshCommandRunner implements SshCommandRunner {
|
||||
}
|
||||
|
||||
@override
|
||||
String get sshConfigPath => null;
|
||||
String get sshConfigPath => '';
|
||||
|
||||
@override
|
||||
String get address => InternetAddress.loopbackIPv4.address;
|
||||
|
||||
@override
|
||||
String get interface => null;
|
||||
String get interface => '';
|
||||
|
||||
@override
|
||||
Future<List<String>> run(String command) async {
|
||||
@@ -72,8 +70,8 @@ class _DummySshCommandRunner implements SshCommandRunner {
|
||||
Future<PortForwarder> _dummyPortForwardingFunction(
|
||||
String address,
|
||||
int remotePort, [
|
||||
String interface = '',
|
||||
String configFile,
|
||||
String? interface,
|
||||
String? configFile,
|
||||
]) async {
|
||||
return _DummyPortForwarder(remotePort, remotePort);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
import 'package:file/file.dart';
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
@@ -95,14 +93,14 @@ abstract class FlutterDriver {
|
||||
/// for the VM.
|
||||
@visibleForTesting
|
||||
factory FlutterDriver.connectedTo({
|
||||
FlutterWebConnection webConnection,
|
||||
vms.VmService serviceClient,
|
||||
vms.Isolate appIsolate,
|
||||
FlutterWebConnection? webConnection,
|
||||
vms.VmService? serviceClient,
|
||||
vms.Isolate? appIsolate,
|
||||
}) {
|
||||
if (webConnection != null) {
|
||||
return WebFlutterDriver.connectedTo(webConnection);
|
||||
}
|
||||
return VMServiceFlutterDriver.connectedTo(serviceClient, appIsolate);
|
||||
return VMServiceFlutterDriver.connectedTo(serviceClient!, appIsolate!);
|
||||
}
|
||||
|
||||
/// Connects to a Flutter application.
|
||||
@@ -140,13 +138,13 @@ abstract class FlutterDriver {
|
||||
/// fail (completing with an error). A timeout can be applied by the caller
|
||||
/// using [Future.timeout] if necessary.
|
||||
static Future<FlutterDriver> connect({
|
||||
String dartVmServiceUrl,
|
||||
String? dartVmServiceUrl,
|
||||
bool printCommunication = false,
|
||||
bool logCommunicationToFile = true,
|
||||
int isolateNumber,
|
||||
Pattern fuchsiaModuleTarget,
|
||||
Duration timeout,
|
||||
Map<String, dynamic> headers,
|
||||
int? isolateNumber,
|
||||
Pattern? fuchsiaModuleTarget,
|
||||
Duration? timeout,
|
||||
Map<String, dynamic>? headers,
|
||||
}) async {
|
||||
if (Platform.environment['FLUTTER_WEB_TEST'] != null) {
|
||||
return WebFlutterDriver.connectWeb(hostUrl: dartVmServiceUrl, timeout: timeout);
|
||||
@@ -185,22 +183,22 @@ abstract class FlutterDriver {
|
||||
Future<Map<String, dynamic>> sendCommand(Command command) async => throw UnimplementedError();
|
||||
|
||||
/// Checks the status of the Flutter Driver extension.
|
||||
Future<Health> checkHealth({ Duration timeout }) async {
|
||||
Future<Health> checkHealth({ Duration? timeout }) async {
|
||||
return Health.fromJson(await sendCommand(GetHealth(timeout: timeout)));
|
||||
}
|
||||
|
||||
/// Returns a dump of the render tree.
|
||||
Future<RenderTree> getRenderTree({ Duration timeout }) async {
|
||||
Future<RenderTree> getRenderTree({ Duration? timeout }) async {
|
||||
return RenderTree.fromJson(await sendCommand(GetRenderTree(timeout: timeout)));
|
||||
}
|
||||
|
||||
/// Returns a dump of the layer tree.
|
||||
Future<LayerTree> getLayerTree({ Duration timeout }) async {
|
||||
Future<LayerTree> getLayerTree({ Duration? timeout }) async {
|
||||
return LayerTree.fromJson(await sendCommand(GetLayerTree(timeout: timeout)));
|
||||
}
|
||||
|
||||
/// Taps at the center of the widget located by [finder].
|
||||
Future<void> tap(SerializableFinder finder, { Duration timeout }) async {
|
||||
Future<void> tap(SerializableFinder finder, { Duration? timeout }) async {
|
||||
await sendCommand(Tap(finder, timeout: timeout));
|
||||
}
|
||||
|
||||
@@ -213,17 +211,17 @@ abstract class FlutterDriver {
|
||||
///
|
||||
/// * [FlutterDriver.runUnsynchronized], which will execute an action
|
||||
/// with frame sync disabled even while frames are pending.
|
||||
Future<void> waitFor(SerializableFinder finder, { Duration timeout }) async {
|
||||
Future<void> waitFor(SerializableFinder finder, { Duration? timeout }) async {
|
||||
await sendCommand(WaitFor(finder, timeout: timeout));
|
||||
}
|
||||
|
||||
/// Waits until [finder] can no longer locate the target.
|
||||
Future<void> waitForAbsent(SerializableFinder finder, { Duration timeout }) async {
|
||||
Future<void> waitForAbsent(SerializableFinder finder, { Duration? timeout }) async {
|
||||
await sendCommand(WaitForAbsent(finder, timeout: timeout));
|
||||
}
|
||||
|
||||
/// Waits until the given [waitCondition] is satisfied.
|
||||
Future<void> waitForCondition(SerializableWaitCondition waitCondition, {Duration timeout}) async {
|
||||
Future<void> waitForCondition(SerializableWaitCondition waitCondition, {Duration? timeout}) async {
|
||||
await sendCommand(WaitForCondition(waitCondition, timeout: timeout));
|
||||
}
|
||||
|
||||
@@ -231,7 +229,7 @@ abstract class FlutterDriver {
|
||||
///
|
||||
/// Use this method when you need to wait for the moment when the application
|
||||
/// becomes "stable", for example, prior to taking a [screenshot].
|
||||
Future<void> waitUntilNoTransientCallbacks({ Duration timeout }) async {
|
||||
Future<void> waitUntilNoTransientCallbacks({ Duration? timeout }) async {
|
||||
await sendCommand(WaitForCondition(const NoTransientCallbacks(), timeout: timeout));
|
||||
}
|
||||
|
||||
@@ -246,7 +244,7 @@ abstract class FlutterDriver {
|
||||
await sendCommand(const WaitForCondition(FirstFrameRasterized()));
|
||||
}
|
||||
|
||||
Future<DriverOffset> _getOffset(SerializableFinder finder, OffsetType type, { Duration timeout }) async {
|
||||
Future<DriverOffset> _getOffset(SerializableFinder finder, OffsetType type, { Duration? timeout }) async {
|
||||
final GetOffset command = GetOffset(finder, type, timeout: timeout);
|
||||
final GetOffsetResult result = GetOffsetResult.fromJson(await sendCommand(command));
|
||||
return DriverOffset(result.dx, result.dy);
|
||||
@@ -256,7 +254,7 @@ abstract class FlutterDriver {
|
||||
///
|
||||
/// The offset is expressed in logical pixels and can be translated to
|
||||
/// device pixels via [dart:ui.FlutterView.devicePixelRatio].
|
||||
Future<DriverOffset> getTopLeft(SerializableFinder finder, { Duration timeout }) async {
|
||||
Future<DriverOffset> getTopLeft(SerializableFinder finder, { Duration? timeout }) async {
|
||||
return _getOffset(finder, OffsetType.topLeft, timeout: timeout);
|
||||
}
|
||||
|
||||
@@ -264,7 +262,7 @@ abstract class FlutterDriver {
|
||||
///
|
||||
/// The offset is expressed in logical pixels and can be translated to
|
||||
/// device pixels via [dart:ui.FlutterView.devicePixelRatio].
|
||||
Future<DriverOffset> getTopRight(SerializableFinder finder, { Duration timeout }) async {
|
||||
Future<DriverOffset> getTopRight(SerializableFinder finder, { Duration? timeout }) async {
|
||||
return _getOffset(finder, OffsetType.topRight, timeout: timeout);
|
||||
}
|
||||
|
||||
@@ -272,7 +270,7 @@ abstract class FlutterDriver {
|
||||
///
|
||||
/// The offset is expressed in logical pixels and can be translated to
|
||||
/// device pixels via [dart:ui.FlutterView.devicePixelRatio].
|
||||
Future<DriverOffset> getBottomLeft(SerializableFinder finder, { Duration timeout }) async {
|
||||
Future<DriverOffset> getBottomLeft(SerializableFinder finder, { Duration? timeout }) async {
|
||||
return _getOffset(finder, OffsetType.bottomLeft, timeout: timeout);
|
||||
}
|
||||
|
||||
@@ -280,7 +278,7 @@ abstract class FlutterDriver {
|
||||
///
|
||||
/// The offset is expressed in logical pixels and can be translated to
|
||||
/// device pixels via [dart:ui.FlutterView.devicePixelRatio].
|
||||
Future<DriverOffset> getBottomRight(SerializableFinder finder, { Duration timeout }) async {
|
||||
Future<DriverOffset> getBottomRight(SerializableFinder finder, { Duration? timeout }) async {
|
||||
return _getOffset(finder, OffsetType.bottomRight, timeout: timeout);
|
||||
}
|
||||
|
||||
@@ -288,7 +286,7 @@ abstract class FlutterDriver {
|
||||
///
|
||||
/// The offset is expressed in logical pixels and can be translated to
|
||||
/// device pixels via [dart:ui.FlutterView.devicePixelRatio].
|
||||
Future<DriverOffset> getCenter(SerializableFinder finder, { Duration timeout }) async {
|
||||
Future<DriverOffset> getCenter(SerializableFinder finder, { Duration? timeout }) async {
|
||||
return _getOffset(finder, OffsetType.center, timeout: timeout);
|
||||
}
|
||||
|
||||
@@ -317,7 +315,7 @@ abstract class FlutterDriver {
|
||||
SerializableFinder finder, {
|
||||
int subtreeDepth = 0,
|
||||
bool includeProperties = true,
|
||||
Duration timeout,
|
||||
Duration? timeout,
|
||||
}) async {
|
||||
return sendCommand(GetDiagnosticsTree(
|
||||
finder,
|
||||
@@ -325,7 +323,7 @@ abstract class FlutterDriver {
|
||||
subtreeDepth: subtreeDepth,
|
||||
includeProperties: includeProperties,
|
||||
timeout: timeout,
|
||||
));
|
||||
)) as Map<String, Object>;
|
||||
}
|
||||
|
||||
/// Returns a JSON map of the [DiagnosticsNode] that is associated with the
|
||||
@@ -350,7 +348,7 @@ abstract class FlutterDriver {
|
||||
SerializableFinder finder, {
|
||||
int subtreeDepth = 0,
|
||||
bool includeProperties = true,
|
||||
Duration timeout,
|
||||
Duration? timeout,
|
||||
}) async {
|
||||
return sendCommand(GetDiagnosticsTree(
|
||||
finder,
|
||||
@@ -358,7 +356,7 @@ abstract class FlutterDriver {
|
||||
subtreeDepth: subtreeDepth,
|
||||
includeProperties: includeProperties,
|
||||
timeout: timeout,
|
||||
));
|
||||
)) as Map<String, Object>;
|
||||
}
|
||||
|
||||
/// Tell the driver to perform a scrolling action.
|
||||
@@ -374,7 +372,7 @@ abstract class FlutterDriver {
|
||||
///
|
||||
/// The move events are generated at a given [frequency] in Hz (or events per
|
||||
/// second). It defaults to 60Hz.
|
||||
Future<void> scroll(SerializableFinder finder, double dx, double dy, Duration duration, { int frequency = 60, Duration timeout }) async {
|
||||
Future<void> scroll(SerializableFinder finder, double dx, double dy, Duration duration, { int frequency = 60, Duration? timeout }) async {
|
||||
await sendCommand(Scroll(finder, dx, dy, duration, frequency, timeout: timeout));
|
||||
}
|
||||
|
||||
@@ -385,7 +383,7 @@ abstract class FlutterDriver {
|
||||
/// that lazily creates its children, like [ListView] or [CustomScrollView],
|
||||
/// then this method may fail because [finder] doesn't actually exist.
|
||||
/// The [scrollUntilVisible] method can be used in this case.
|
||||
Future<void> scrollIntoView(SerializableFinder finder, { double alignment = 0.0, Duration timeout }) async {
|
||||
Future<void> scrollIntoView(SerializableFinder finder, { double alignment = 0.0, Duration? timeout }) async {
|
||||
await sendCommand(ScrollIntoView(finder, alignment: alignment, timeout: timeout));
|
||||
}
|
||||
|
||||
@@ -417,7 +415,7 @@ abstract class FlutterDriver {
|
||||
double alignment = 0.0,
|
||||
double dxScroll = 0.0,
|
||||
double dyScroll = 0.0,
|
||||
Duration timeout,
|
||||
Duration? timeout,
|
||||
}) async {
|
||||
assert(scrollable != null);
|
||||
assert(item != null);
|
||||
@@ -442,7 +440,7 @@ abstract class FlutterDriver {
|
||||
}
|
||||
|
||||
/// Returns the text in the `Text` widget located by [finder].
|
||||
Future<String> getText(SerializableFinder finder, { Duration timeout }) async {
|
||||
Future<String> getText(SerializableFinder finder, { Duration? timeout }) async {
|
||||
return GetTextResult.fromJson(await sendCommand(GetText(finder, timeout: timeout))).text;
|
||||
}
|
||||
|
||||
@@ -478,7 +476,7 @@ abstract class FlutterDriver {
|
||||
/// await driver.waitFor(find.text('World!')); // verify new text appears
|
||||
/// });
|
||||
/// ```
|
||||
Future<void> enterText(String text, { Duration timeout }) async {
|
||||
Future<void> enterText(String text, { Duration? timeout }) async {
|
||||
await sendCommand(EnterText(text, timeout: timeout));
|
||||
}
|
||||
|
||||
@@ -495,7 +493,7 @@ abstract class FlutterDriver {
|
||||
/// When enabled, the operating system's configured keyboard will not be
|
||||
/// invoked when the widget is focused, as the [SystemChannels.textInput]
|
||||
/// channel will be mocked out.
|
||||
Future<void> setTextEntryEmulation({ @required bool enabled, Duration timeout }) async {
|
||||
Future<void> setTextEntryEmulation({ required bool enabled, Duration? timeout }) async {
|
||||
assert(enabled != null);
|
||||
await sendCommand(SetTextEntryEmulation(enabled, timeout: timeout));
|
||||
}
|
||||
@@ -506,7 +504,7 @@ abstract class FlutterDriver {
|
||||
/// It's expected that the application has registered a [DataHandler]
|
||||
/// callback in [enableFlutterDriverExtension] that can successfully handle
|
||||
/// these requests.
|
||||
Future<String> requestData(String message, { Duration timeout }) async {
|
||||
Future<String> requestData(String message, { Duration? timeout }) async {
|
||||
return RequestDataResult.fromJson(await sendCommand(RequestData(message, timeout: timeout))).message;
|
||||
}
|
||||
|
||||
@@ -514,7 +512,7 @@ abstract class FlutterDriver {
|
||||
///
|
||||
/// Returns true when the call actually changed the state from on to off or
|
||||
/// vice versa.
|
||||
Future<bool> setSemantics(bool enabled, { Duration timeout }) async {
|
||||
Future<bool> setSemantics(bool enabled, { Duration? timeout }) async {
|
||||
final SetSemanticsResult result = SetSemanticsResult.fromJson(await sendCommand(SetSemantics(enabled, timeout: timeout)));
|
||||
return result.changedState;
|
||||
}
|
||||
@@ -527,7 +525,7 @@ abstract class FlutterDriver {
|
||||
///
|
||||
/// Semantics must be enabled to use this method, either using a platform
|
||||
/// specific shell command or [setSemantics].
|
||||
Future<int> getSemanticsId(SerializableFinder finder, { Duration timeout }) async {
|
||||
Future<int> getSemanticsId(SerializableFinder finder, { Duration? timeout }) async {
|
||||
final Map<String, dynamic> jsonResponse = await sendCommand(GetSemanticsId(finder, timeout: timeout));
|
||||
final GetSemanticsIdResult result = GetSemanticsIdResult.fromJson(jsonResponse);
|
||||
return result.id;
|
||||
@@ -693,7 +691,7 @@ abstract class FlutterDriver {
|
||||
/// With frame sync disabled, it's the responsibility of the test author to
|
||||
/// ensure that no action is performed while the app is undergoing a
|
||||
/// transition to avoid flakiness.
|
||||
Future<T> runUnsynchronized<T>(Future<T> action(), { Duration timeout }) async {
|
||||
Future<T> runUnsynchronized<T>(Future<T> action(), { Duration? timeout }) async {
|
||||
await sendCommand(SetFrameSync(false, timeout: timeout));
|
||||
T result;
|
||||
try {
|
||||
@@ -750,8 +748,8 @@ class CommonFinders {
|
||||
/// If `firstMatchOnly` is true then only the first ancestor matching
|
||||
/// `matching` will be returned. Defaults to false.
|
||||
SerializableFinder ancestor({
|
||||
@required SerializableFinder of,
|
||||
@required SerializableFinder matching,
|
||||
required SerializableFinder of,
|
||||
required SerializableFinder matching,
|
||||
bool matchRoot = false,
|
||||
bool firstMatchOnly = false,
|
||||
}) => Ancestor(of: of, matching: matching, matchRoot: matchRoot, firstMatchOnly: firstMatchOnly);
|
||||
@@ -765,8 +763,8 @@ class CommonFinders {
|
||||
/// If `firstMatchOnly` is true then only the first descendant matching
|
||||
/// `matching` will be returned. Defaults to false.
|
||||
SerializableFinder descendant({
|
||||
@required SerializableFinder of,
|
||||
@required SerializableFinder matching,
|
||||
required SerializableFinder of,
|
||||
required SerializableFinder matching,
|
||||
bool matchRoot = false,
|
||||
bool firstMatchOnly = false,
|
||||
}) => Descendant(of: of, matching: matching, matchRoot: matchRoot, firstMatchOnly: firstMatchOnly);
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
/// Returns the [p]-th percentile element from the [doubles].
|
||||
/// `List<doubles>` will be sorted.
|
||||
double findPercentile(List<double> doubles, double p) {
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'percentile_utils.dart';
|
||||
import 'timeline.dart';
|
||||
|
||||
@@ -63,7 +61,7 @@ class ProfilingSummarizer {
|
||||
assert(kProfilingEvents.contains(event.name));
|
||||
final ProfileType type = _getProfileType(event.name);
|
||||
eventsByType[type] ??= <TimelineEvent>[];
|
||||
eventsByType[type].add(event);
|
||||
eventsByType[type]!.add(event);
|
||||
}
|
||||
return ProfilingSummarizer._(eventsByType);
|
||||
}
|
||||
@@ -96,7 +94,7 @@ class ProfilingSummarizer {
|
||||
/// Returns true if there are events in the timeline corresponding to [profileType].
|
||||
bool hasProfilingInfo(ProfileType profileType) {
|
||||
if (eventByType.containsKey(profileType)) {
|
||||
return eventByType[profileType].isNotEmpty;
|
||||
return eventByType[profileType]!.isNotEmpty;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -104,7 +102,7 @@ class ProfilingSummarizer {
|
||||
|
||||
/// Computes the average of the `profileType` over the recorded events.
|
||||
double computeAverage(ProfileType profileType) {
|
||||
final List<TimelineEvent> events = eventByType[profileType];
|
||||
final List<TimelineEvent> events = eventByType[profileType]!;
|
||||
assert(events.isNotEmpty);
|
||||
final double total = events
|
||||
.map((TimelineEvent e) => _getProfileValue(profileType, e))
|
||||
@@ -114,7 +112,7 @@ class ProfilingSummarizer {
|
||||
|
||||
/// The [percentile]-th percentile `profileType` over the recorded events.
|
||||
double computePercentile(ProfileType profileType, double percentile) {
|
||||
final List<TimelineEvent> events = eventByType[profileType];
|
||||
final List<TimelineEvent> events = eventByType[profileType]!;
|
||||
assert(events.isNotEmpty);
|
||||
final List<double> doubles = events
|
||||
.map((TimelineEvent e) => _getProfileValue(profileType, e))
|
||||
@@ -122,7 +120,7 @@ class ProfilingSummarizer {
|
||||
return findPercentile(doubles, percentile);
|
||||
}
|
||||
|
||||
static ProfileType _getProfileType(String eventName) {
|
||||
static ProfileType _getProfileType(String? eventName) {
|
||||
switch (eventName) {
|
||||
case _kCpuProfile:
|
||||
return ProfileType.CPU;
|
||||
@@ -147,13 +145,11 @@ class ProfilingSummarizer {
|
||||
_getArgValue('owned_shared_memory_usage', e);
|
||||
return dirtyMem + ownedSharedMem;
|
||||
}
|
||||
|
||||
throw Exception('Invalid $profileType.');
|
||||
}
|
||||
|
||||
double _getArgValue(String argKey, TimelineEvent e) {
|
||||
assert(e.arguments.containsKey(argKey));
|
||||
final dynamic argVal = e.arguments[argKey];
|
||||
assert(e.arguments!.containsKey(argKey));
|
||||
final dynamic argVal = e.arguments![argKey];
|
||||
assert(argVal is String);
|
||||
return double.parse(argVal as String);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'percentile_utils.dart';
|
||||
import 'timeline.dart';
|
||||
|
||||
@@ -68,8 +66,8 @@ class SceneDisplayLagSummarizer {
|
||||
|
||||
double _getVsyncTransitionsMissed(TimelineEvent e) {
|
||||
assert(e.name == kSceneDisplayLagEvent);
|
||||
assert(e.arguments.containsKey(_kVsyncTransitionsMissed));
|
||||
final dynamic transitionsMissed = e.arguments[_kVsyncTransitionsMissed];
|
||||
assert(e.arguments!.containsKey(_kVsyncTransitionsMissed));
|
||||
final dynamic transitionsMissed = e.arguments![_kVsyncTransitionsMissed];
|
||||
assert(transitionsMissed is String);
|
||||
return double.parse(transitionsMissed as String);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
/// Timeline data recorded by the Flutter runtime.
|
||||
class Timeline {
|
||||
/// Creates a timeline given JSON-encoded timeline data.
|
||||
@@ -25,27 +23,29 @@ class Timeline {
|
||||
///
|
||||
/// This is parsed from "traceEvents" data within [json] and sorted by
|
||||
/// timestamp. Anything without a valid timestamp is put in the beginning.
|
||||
final List<TimelineEvent> events;
|
||||
///
|
||||
/// This will be null if there are are no "traceEvents" in the [json].
|
||||
final List<TimelineEvent>? events;
|
||||
}
|
||||
|
||||
/// A single timeline event.
|
||||
class TimelineEvent {
|
||||
/// Creates a timeline event given JSON-encoded event data.
|
||||
TimelineEvent(this.json)
|
||||
: name = json['name'] as String,
|
||||
category = json['cat'] as String,
|
||||
phase = json['ph'] as String,
|
||||
processId = json['pid'] as int,
|
||||
threadId = json['tid'] as int,
|
||||
: name = json['name'] as String?,
|
||||
category = json['cat'] as String?,
|
||||
phase = json['ph'] as String?,
|
||||
processId = json['pid'] as int?,
|
||||
threadId = json['tid'] as int?,
|
||||
duration = json['dur'] != null
|
||||
? Duration(microseconds: json['dur'] as int)
|
||||
: null,
|
||||
threadDuration = json['tdur'] != null
|
||||
? Duration(microseconds: json['tdur'] as int)
|
||||
: null,
|
||||
timestampMicros = json['ts'] as int,
|
||||
threadTimestampMicros = json['tts'] as int,
|
||||
arguments = json['args'] as Map<String, dynamic>;
|
||||
timestampMicros = json['ts'] as int?,
|
||||
threadTimestampMicros = json['tts'] as int?,
|
||||
arguments = json['args'] as Map<String, dynamic>?;
|
||||
|
||||
/// The original event JSON.
|
||||
final Map<String, dynamic> json;
|
||||
@@ -53,28 +53,28 @@ class TimelineEvent {
|
||||
/// The name of the event.
|
||||
///
|
||||
/// Corresponds to the "name" field in the JSON event.
|
||||
final String name;
|
||||
final String? name;
|
||||
|
||||
/// Event category. Events with different names may share the same category.
|
||||
///
|
||||
/// Corresponds to the "cat" field in the JSON event.
|
||||
final String category;
|
||||
final String? category;
|
||||
|
||||
/// For a given long lasting event, denotes the phase of the event, such as
|
||||
/// "B" for "event began", and "E" for "event ended".
|
||||
///
|
||||
/// Corresponds to the "ph" field in the JSON event.
|
||||
final String phase;
|
||||
final String? phase;
|
||||
|
||||
/// ID of process that emitted the event.
|
||||
///
|
||||
/// Corresponds to the "pid" field in the JSON event.
|
||||
final int processId;
|
||||
final int? processId;
|
||||
|
||||
/// ID of thread that issues the event.
|
||||
///
|
||||
/// Corresponds to the "tid" field in the JSON event.
|
||||
final int threadId;
|
||||
final int? threadId;
|
||||
|
||||
/// The duration of the event.
|
||||
///
|
||||
@@ -82,7 +82,7 @@ class TimelineEvent {
|
||||
/// pair of begin/end events.
|
||||
///
|
||||
/// Corresponds to the "dur" field in the JSON event.
|
||||
final Duration duration;
|
||||
final Duration? duration;
|
||||
|
||||
/// The thread duration of the event.
|
||||
///
|
||||
@@ -90,32 +90,31 @@ class TimelineEvent {
|
||||
/// pair of begin/end events.
|
||||
///
|
||||
/// Corresponds to the "tdur" field in the JSON event.
|
||||
final Duration threadDuration;
|
||||
final Duration? threadDuration;
|
||||
|
||||
/// Time passed since tracing was enabled, in microseconds.
|
||||
///
|
||||
/// Corresponds to the "ts" field in the JSON event.
|
||||
final int timestampMicros;
|
||||
final int? timestampMicros;
|
||||
|
||||
/// Thread clock time, in microseconds.
|
||||
///
|
||||
/// Corresponds to the "tts" field in the JSON event.
|
||||
final int threadTimestampMicros;
|
||||
final int? threadTimestampMicros;
|
||||
|
||||
/// Arbitrary data attached to the event.
|
||||
///
|
||||
/// Corresponds to the "args" field in the JSON event.
|
||||
final Map<String, dynamic> arguments;
|
||||
final Map<String, dynamic>? arguments;
|
||||
}
|
||||
|
||||
List<TimelineEvent> _parseEvents(Map<String, dynamic> json) {
|
||||
final List<dynamic> jsonEvents = json['traceEvents'] as List<dynamic>;
|
||||
List<TimelineEvent>? _parseEvents(Map<String, dynamic> json) {
|
||||
final List<dynamic>? jsonEvents = json['traceEvents'] as List<dynamic>?;
|
||||
|
||||
if (jsonEvents == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO(vegorov): use instance method version of castFrom when it is available.
|
||||
final List<TimelineEvent> timelineEvents =
|
||||
Iterable.castFrom<dynamic, Map<String, dynamic>>(jsonEvents)
|
||||
.map<TimelineEvent>(
|
||||
@@ -123,8 +122,8 @@ List<TimelineEvent> _parseEvents(Map<String, dynamic> json) {
|
||||
.toList();
|
||||
|
||||
timelineEvents.sort((TimelineEvent e1, TimelineEvent e2) {
|
||||
final int ts1 = e1.timestampMicros;
|
||||
final int ts2 = e2.timestampMicros;
|
||||
final int? ts1 = e1.timestampMicros;
|
||||
final int? ts2 = e2.timestampMicros;
|
||||
if (ts1 == null) {
|
||||
if (ts2 == null) {
|
||||
return 0;
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'dart:convert' show json, JsonEncoder;
|
||||
import 'dart:math' as math;
|
||||
|
||||
@@ -197,7 +195,7 @@ class TimelineSummary {
|
||||
/// * [Timeline.fromJson], which explains detail about the timeline data.
|
||||
Future<void> writeTimelineToFile(
|
||||
String traceName, {
|
||||
String destinationDirectory,
|
||||
String? destinationDirectory,
|
||||
bool pretty = false,
|
||||
}) async {
|
||||
destinationDirectory ??= testOutputsDirectory;
|
||||
@@ -209,7 +207,7 @@ class TimelineSummary {
|
||||
/// Writes [summaryJson] to a file.
|
||||
Future<void> writeSummaryToFile(
|
||||
String traceName, {
|
||||
String destinationDirectory,
|
||||
String? destinationDirectory,
|
||||
bool pretty = false,
|
||||
}) async {
|
||||
destinationDirectory ??= testOutputsDirectory;
|
||||
@@ -225,13 +223,13 @@ class TimelineSummary {
|
||||
}
|
||||
|
||||
List<TimelineEvent> _extractNamedEvents(String name) {
|
||||
return _timeline.events
|
||||
return _timeline.events!
|
||||
.where((TimelineEvent event) => event.name == name)
|
||||
.toList();
|
||||
}
|
||||
|
||||
List<TimelineEvent> _extractEventsWithNames(Set<String> names) {
|
||||
return _timeline.events
|
||||
return _timeline.events!
|
||||
.where((TimelineEvent event) => names.contains(event.name))
|
||||
.toList();
|
||||
}
|
||||
@@ -244,7 +242,7 @@ class TimelineSummary {
|
||||
final List<TimelineEvent> events = _extractNamedEvents(name);
|
||||
|
||||
// Timeline does not guarantee that the first event is the "begin" event.
|
||||
TimelineEvent begin;
|
||||
TimelineEvent? begin;
|
||||
for (final TimelineEvent event in events) {
|
||||
if (event.phase == 'B') {
|
||||
begin = event;
|
||||
@@ -273,7 +271,7 @@ class TimelineSummary {
|
||||
return _extractDurations(
|
||||
name,
|
||||
(TimelineEvent beginEvent, TimelineEvent endEvent) {
|
||||
return Duration(microseconds: endEvent.timestampMicros - beginEvent.timestampMicros);
|
||||
return Duration(microseconds: endEvent.timestampMicros! - beginEvent.timestampMicros!);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -282,7 +280,7 @@ class TimelineSummary {
|
||||
final List<Duration> result = _extractDurations(
|
||||
name,
|
||||
(TimelineEvent beginEvent, TimelineEvent endEvent) {
|
||||
return Duration(microseconds: beginEvent.timestampMicros);
|
||||
return Duration(microseconds: beginEvent.timestampMicros!);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -2,15 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:file/file.dart' as f;
|
||||
import 'package:fuchsia_remote_debug_protocol/fuchsia_remote_debug_protocol.dart' as fuchsia;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:vm_service/vm_service.dart' as vms;
|
||||
import 'package:webdriver/async_io.dart' as async_io;
|
||||
@@ -41,12 +38,12 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
///
|
||||
/// See [FlutterDriver.connect] for more documentation.
|
||||
static Future<FlutterDriver> connect({
|
||||
String dartVmServiceUrl,
|
||||
String? dartVmServiceUrl,
|
||||
bool printCommunication = false,
|
||||
bool logCommunicationToFile = true,
|
||||
int isolateNumber,
|
||||
Pattern fuchsiaModuleTarget,
|
||||
Map<String, dynamic> headers,
|
||||
int? isolateNumber,
|
||||
Pattern? fuchsiaModuleTarget,
|
||||
Map<String, dynamic>? headers,
|
||||
}) async {
|
||||
// If running on a Fuchsia device, connect to the first isolate whose name
|
||||
// matches FUCHSIA_MODULE_TARGET.
|
||||
@@ -93,32 +90,32 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
_log('Connecting to Flutter application at $dartVmServiceUrl');
|
||||
final vms.VmService client = await vmServiceConnectFunction(dartVmServiceUrl, headers);
|
||||
|
||||
Future<vms.IsolateRef> _waitForRootIsolate() async {
|
||||
Future<vms.IsolateRef?> _waitForRootIsolate() async {
|
||||
bool _checkIsolate(vms.IsolateRef ref) => ref.number == isolateNumber.toString();
|
||||
while (true) {
|
||||
final vms.VM vm = await client.getVM();
|
||||
if (vm.isolates.isEmpty || (isolateNumber != null && !vm.isolates.any(_checkIsolate))) {
|
||||
if (vm.isolates!.isEmpty || (isolateNumber != null && !vm.isolates!.any(_checkIsolate))) {
|
||||
await Future<void>.delayed(_kPauseBetweenReconnectAttempts);
|
||||
continue;
|
||||
}
|
||||
return isolateNumber == null
|
||||
? vm.isolates.first
|
||||
: vm.isolates.firstWhere(_checkIsolate);
|
||||
? vm.isolates!.first
|
||||
: vm.isolates!.firstWhere(_checkIsolate);
|
||||
}
|
||||
}
|
||||
|
||||
final vms.IsolateRef isolateRef = await _warnIfSlow<vms.IsolateRef>(
|
||||
final vms.IsolateRef isolateRef = (await _warnIfSlow<vms.IsolateRef?>(
|
||||
future: _waitForRootIsolate(),
|
||||
timeout: kUnusuallyLongTimeout,
|
||||
message: isolateNumber == null
|
||||
? 'The root isolate is taking an unuusally long time to start.'
|
||||
: 'Isolate $isolateNumber is taking an unusually long time to start.',
|
||||
);
|
||||
))!;
|
||||
_log('Isolate found with number: ${isolateRef.number}');
|
||||
vms.Isolate isolate = await client.getIsolate(isolateRef.id);
|
||||
vms.Isolate isolate = await client.getIsolate(isolateRef.id!);
|
||||
|
||||
if (isolate.pauseEvent.kind == vms.EventKind.kNone) {
|
||||
isolate = await client.getIsolate(isolateRef.id);
|
||||
if (isolate.pauseEvent!.kind == vms.EventKind.kNone) {
|
||||
isolate = await client.getIsolate(isolateRef.id!);
|
||||
}
|
||||
|
||||
final VMServiceFlutterDriver driver = VMServiceFlutterDriver.connectedTo(
|
||||
@@ -143,7 +140,7 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
_log('Failed to set pause_isolates_on_start=false, proceeding. Error: $e');
|
||||
}
|
||||
|
||||
return client.resume(isolate.id).catchError((dynamic e) {
|
||||
return client.resume(isolate.id!).catchError((Object e) {
|
||||
const int vmMustBePausedCode = 101;
|
||||
if (e is vms.RPCError && e.code == vmMustBePausedCode) {
|
||||
// No biggie; something else must have resumed the isolate
|
||||
@@ -167,9 +164,9 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
await client.streamListen(vms.EventStreams.kIsolate);
|
||||
|
||||
final Future<void> extensionAlreadyAdded = client
|
||||
.getIsolate(isolateRef.id)
|
||||
.getIsolate(isolateRef.id!)
|
||||
.then((vms.Isolate isolate) async {
|
||||
if (isolate.extensionRPCs.contains(_flutterExtensionMethodName)) {
|
||||
if (isolate.extensionRPCs!.contains(_flutterExtensionMethodName)) {
|
||||
return;
|
||||
}
|
||||
// Never complete. Rely on the stream listener to find the service
|
||||
@@ -178,7 +175,7 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
});
|
||||
|
||||
final Completer<void> extensionAdded = Completer<void>();
|
||||
StreamSubscription<vms.Event> isolateAddedSubscription;
|
||||
late StreamSubscription<vms.Event> isolateAddedSubscription;
|
||||
|
||||
isolateAddedSubscription = client.onIsolateEvent.listen(
|
||||
(vms.Event data) {
|
||||
@@ -200,19 +197,19 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
}
|
||||
|
||||
// Attempt to resume isolate if it was paused
|
||||
if (isolate.pauseEvent.kind == vms.EventKind.kPauseStart) {
|
||||
if (isolate.pauseEvent!.kind == vms.EventKind.kPauseStart) {
|
||||
_log('Isolate is paused at start.');
|
||||
|
||||
await resumeLeniently();
|
||||
} else if (isolate.pauseEvent.kind == vms.EventKind.kPauseExit ||
|
||||
isolate.pauseEvent.kind == vms.EventKind.kPauseBreakpoint ||
|
||||
isolate.pauseEvent.kind == vms.EventKind.kPauseException ||
|
||||
isolate.pauseEvent.kind == vms.EventKind.kPauseInterrupted) {
|
||||
} else if (isolate.pauseEvent!.kind == vms.EventKind.kPauseExit ||
|
||||
isolate.pauseEvent!.kind == vms.EventKind.kPauseBreakpoint ||
|
||||
isolate.pauseEvent!.kind == vms.EventKind.kPauseException ||
|
||||
isolate.pauseEvent!.kind == vms.EventKind.kPauseInterrupted) {
|
||||
// If the isolate is paused for any other reason, assume the extension is
|
||||
// already there.
|
||||
_log('Isolate is paused mid-flight.');
|
||||
await resumeLeniently();
|
||||
} else if (isolate.pauseEvent.kind == vms.EventKind.kResume) {
|
||||
} else if (isolate.pauseEvent!.kind == vms.EventKind.kResume) {
|
||||
_log('Isolate is not paused. Assuming application is ready.');
|
||||
} else {
|
||||
_log(
|
||||
@@ -306,7 +303,7 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> sendCommand(Command command) async {
|
||||
Map<String, dynamic> response;
|
||||
late Map<String, dynamic> response;
|
||||
try {
|
||||
final Map<String, String> serialized = command.serialize();
|
||||
_logCommunication('>>> $serialized');
|
||||
@@ -314,12 +311,12 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
_flutterExtensionMethodName,
|
||||
isolateId: _appIsolate.id,
|
||||
args: serialized,
|
||||
).then<Map<String, dynamic>>((vms.Response value) => value.json);
|
||||
response = await _warnIfSlow<Map<String, dynamic>>(
|
||||
).then<Map<String, dynamic>>((vms.Response value) => value.json!);
|
||||
response = (await _warnIfSlow<Map<String, dynamic>>(
|
||||
future: future,
|
||||
timeout: command.timeout ?? kUnusuallyLongTimeout,
|
||||
message: '${command.kind} message is taking a long time to complete...',
|
||||
);
|
||||
))!;
|
||||
_logCommunication('<<< $response');
|
||||
} catch (error, stackTrace) {
|
||||
throw DriverError(
|
||||
@@ -328,7 +325,7 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
stackTrace,
|
||||
);
|
||||
}
|
||||
if (response['isError'] as bool)
|
||||
if ((response['isError'] as bool?) == true)
|
||||
throw DriverError('Error in Flutter application: ${response['response']}');
|
||||
return response['response'] as Map<String, dynamic>;
|
||||
}
|
||||
@@ -348,14 +345,14 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
await Future<void>.delayed(const Duration(seconds: 2));
|
||||
|
||||
final vms.Response result = await _serviceClient.callMethod('_flutter.screenshot');
|
||||
return base64.decode(result.json['screenshot'] as String);
|
||||
return base64.decode(result.json!['screenshot'] as String);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Map<String, dynamic>>> getVmFlags() async {
|
||||
final vms.FlagList result = await _serviceClient.getFlagList();
|
||||
return result != null
|
||||
? result.flags.map((vms.Flag flag) => flag.toJson()).toList()
|
||||
return result.flags != null
|
||||
? result.flags!.map((vms.Flag flag) => flag.toJson()).toList()
|
||||
: const <Map<String, dynamic>>[];
|
||||
}
|
||||
|
||||
@@ -390,8 +387,8 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
@override
|
||||
Future<Timeline> stopTracingAndDownloadTimeline({
|
||||
Duration timeout = kUnusuallyLongTimeout,
|
||||
int startTime,
|
||||
int endTime,
|
||||
int? startTime,
|
||||
int? endTime,
|
||||
}) async {
|
||||
assert(timeout != null);
|
||||
assert((startTime == null && endTime == null) ||
|
||||
@@ -405,12 +402,12 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
);
|
||||
if (startTime == null) {
|
||||
final vms.Timeline timeline = await _serviceClient.getVMTimeline();
|
||||
return Timeline.fromJson(timeline.json);
|
||||
return Timeline.fromJson(timeline.json!);
|
||||
}
|
||||
const int kSecondInMicros = 1000000;
|
||||
int currentStart = startTime;
|
||||
int currentEnd = startTime + kSecondInMicros; // 1 second of timeline
|
||||
final List<Map<String, Object>> chunks = <Map<String, Object>>[];
|
||||
final List<Map<String, Object?>?> chunks = <Map<String, Object>?>[];
|
||||
do {
|
||||
final vms.Timeline chunk = await _serviceClient.getVMTimeline(
|
||||
timeOriginMicros: currentStart,
|
||||
@@ -421,11 +418,11 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
chunks.add(chunk.json);
|
||||
currentStart = currentEnd;
|
||||
currentEnd += kSecondInMicros;
|
||||
} while (currentStart < endTime);
|
||||
} while (currentStart < endTime!);
|
||||
return Timeline.fromJson(<String, Object>{
|
||||
'traceEvents': <Object> [
|
||||
for (Map<String, Object> chunk in chunks)
|
||||
...chunk['traceEvents'] as List<Object>,
|
||||
for (Map<String, Object?>? chunk in chunks)
|
||||
...chunk!['traceEvents']! as List<Object>,
|
||||
],
|
||||
});
|
||||
} catch (error, stackTrace) {
|
||||
@@ -502,7 +499,7 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<T> runUnsynchronized<T>(Future<T> action(), { Duration timeout }) async {
|
||||
Future<T> runUnsynchronized<T>(Future<T> action(), { Duration? timeout }) async {
|
||||
await sendCommand(SetFrameSync(false, timeout: timeout));
|
||||
T result;
|
||||
try {
|
||||
@@ -560,10 +557,10 @@ String _getWebSocketUrl(String url) {
|
||||
|
||||
/// Waits for a real Dart VM service to become available, then connects using
|
||||
/// the [VMServiceClient].
|
||||
Future<vms.VmService> _waitAndConnect(String url, Map<String, dynamic> headers) async {
|
||||
Future<vms.VmService> _waitAndConnect(String url, Map<String, dynamic>? headers) async {
|
||||
final String webSocketUrl = _getWebSocketUrl(url);
|
||||
int attempts = 0;
|
||||
WebSocket socket;
|
||||
late WebSocket socket;
|
||||
while (true) {
|
||||
try {
|
||||
socket = await WebSocket.connect(webSocketUrl, headers: headers);
|
||||
@@ -585,7 +582,7 @@ Future<vms.VmService> _waitAndConnect(String url, Map<String, dynamic> headers)
|
||||
await service.getVersion();
|
||||
return service;
|
||||
} catch (e) {
|
||||
await socket?.close();
|
||||
await socket.close();
|
||||
if (attempts > 5) {
|
||||
_log('It is taking an unusually long time to connect to the VM...');
|
||||
}
|
||||
@@ -623,10 +620,11 @@ List<String> _timelineStreamsToString(List<TimelineStream> streams) {
|
||||
void _log(String message) {
|
||||
driverLog('VMServiceFlutterDriver', message);
|
||||
}
|
||||
Future<T> _warnIfSlow<T>({
|
||||
@required Future<T> future,
|
||||
@required Duration timeout,
|
||||
@required String message,
|
||||
|
||||
Future<T?> _warnIfSlow<T>({
|
||||
required Future<T?> future,
|
||||
required Duration timeout,
|
||||
required String message,
|
||||
}) {
|
||||
assert(future != null);
|
||||
assert(timeout != null);
|
||||
@@ -637,10 +635,10 @@ Future<T> _warnIfSlow<T>({
|
||||
return null;
|
||||
})
|
||||
// Don't duplicate errors if [future] completes with an error.
|
||||
.catchError((dynamic e) => null);
|
||||
.catchError((Object e, StackTrace s) => null);
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
/// A function that connects to a Dart VM service given the `url` and `headers`.
|
||||
typedef VMServiceConnectFunction = Future<vms.VmService> Function(String url, Map<String, dynamic> headers);
|
||||
typedef VMServiceConnectFunction = Future<vms.VmService> Function(String url, Map<String, dynamic>? headers);
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
@@ -53,7 +51,7 @@ class WebFlutterDriver extends FlutterDriver {
|
||||
/// DRIVER_SESSION_CAPABILITIES and ANDROID_CHROME_ON_EMULATOR for
|
||||
/// configurations.
|
||||
static Future<FlutterDriver> connectWeb(
|
||||
{String hostUrl, Duration timeout}) async {
|
||||
{String? hostUrl, Duration? timeout}) async {
|
||||
hostUrl ??= Platform.environment['VM_SERVICE_URL'];
|
||||
final Map<String, dynamic> settings = <String, dynamic>{
|
||||
'support-timeline-action': Platform.environment['SUPPORT_TIMELINE_ACTION'] == 'true',
|
||||
@@ -64,7 +62,7 @@ class WebFlutterDriver extends FlutterDriver {
|
||||
'session-capabilities': Platform.environment['DRIVER_SESSION_CAPABILITIES'],
|
||||
};
|
||||
final FlutterWebConnection connection = await FlutterWebConnection.connect
|
||||
(hostUrl, settings, timeout: timeout);
|
||||
(hostUrl!, settings, timeout: timeout);
|
||||
return WebFlutterDriver.connectedTo(connection);
|
||||
}
|
||||
|
||||
@@ -90,7 +88,7 @@ class WebFlutterDriver extends FlutterDriver {
|
||||
final Map<String, String> serialized = command.serialize();
|
||||
try {
|
||||
final dynamic data = await _connection.sendCommand("window.\$flutterDriver('${jsonEncode(serialized)}')", command.timeout);
|
||||
response = data != null ? json.decode(data as String) as Map<String, dynamic> : <String, dynamic>{};
|
||||
response = data != null ? (json.decode(data as String) as Map<String, dynamic>?)! : <String, dynamic>{};
|
||||
} catch (error, stackTrace) {
|
||||
throw DriverError("Failed to respond to $command due to remote error\n : \$flutterDriver('${jsonEncode(serialized)}')",
|
||||
error,
|
||||
@@ -132,7 +130,7 @@ class WebFlutterDriver extends FlutterDriver {
|
||||
final List<Map<String, dynamic>> events = <Map<String, dynamic>>[];
|
||||
for (final async_io.LogEntry entry in await _connection.logs.toList()) {
|
||||
if (_startTime.isBefore(entry.timestamp)) {
|
||||
final Map<String, dynamic> data = jsonDecode(entry.message)['message'] as Map<String, dynamic>;
|
||||
final Map<String, dynamic> data = jsonDecode(entry.message!)['message'] as Map<String, dynamic>;
|
||||
if (data['method'] == 'Tracing.dataCollected') {
|
||||
// 'ts' data collected from Chrome is in double format, conversion needed
|
||||
try {
|
||||
@@ -142,7 +140,7 @@ class WebFlutterDriver extends FlutterDriver {
|
||||
// data is corrupted, skip
|
||||
continue;
|
||||
}
|
||||
events.add(data['params'] as Map<String, dynamic>);
|
||||
events.add(data['params']! as Map<String, dynamic>);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,7 +201,7 @@ class FlutterWebConnection {
|
||||
static Future<FlutterWebConnection> connect(
|
||||
String url,
|
||||
Map<String, dynamic> settings,
|
||||
{Duration timeout}) async {
|
||||
{Duration? timeout}) async {
|
||||
final String sessionId = settings['session-id'].toString();
|
||||
final Uri sessionUri = Uri.parse(settings['session-uri'].toString());
|
||||
final async_io.WebDriver driver = async_io.WebDriver(
|
||||
@@ -226,7 +224,7 @@ class FlutterWebConnection {
|
||||
}
|
||||
|
||||
/// Sends command via WebDriver to Flutter web application.
|
||||
Future<dynamic> sendCommand(String script, Duration duration) async {
|
||||
Future<dynamic> sendCommand(String script, Duration? duration) async {
|
||||
dynamic result;
|
||||
try {
|
||||
await _driver.execute(script, <void>[]);
|
||||
@@ -265,7 +263,7 @@ class FlutterWebConnection {
|
||||
}
|
||||
|
||||
/// Waits until extension is installed.
|
||||
Future<void> waitUntilExtensionInstalled(async_io.WebDriver driver, Duration timeout) async {
|
||||
Future<void> waitUntilExtensionInstalled(async_io.WebDriver driver, Duration? timeout) async {
|
||||
await waitFor<void>(() =>
|
||||
driver.execute(r'return typeof(window.$flutterDriver)', <String>[]),
|
||||
matcher: 'function',
|
||||
|
||||
Reference in New Issue
Block a user