55 lines
1.6 KiB
Dart
Raw Normal View History

2022-04-28 23:23:38 +02:00
import 'dart:async';
import 'dart:typed_data';
2022-04-28 23:23:38 +02:00
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void takeScreenshot() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
test('take screenshot', () async {
2022-10-14 02:28:23 +02:00
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
2022-04-28 23:23:38 +02:00
final Completer<void> pageLoaded = Completer<void>();
var headlessWebView = new HeadlessInAppWebView(
2022-10-11 16:19:36 +02:00
initialUrlRequest: URLRequest(url: TEST_URL_1),
2022-04-28 23:23:38 +02:00
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) async {
if (!pageLoaded.isCompleted) {
pageLoaded.complete();
}
2022-04-28 23:23:38 +02:00
});
await headlessWebView.run();
expect(headlessWebView.isRunning(), true);
2022-10-11 16:19:36 +02:00
final InAppWebViewController controller = await controllerCompleter.future;
2022-04-28 23:23:38 +02:00
await pageLoaded.future;
final String? url = (await controller.getUrl())?.toString();
expect(url, TEST_URL_1.toString());
final Size? size = await headlessWebView.getSize();
expect(size, isNotNull);
final Uint8List? screenshot = await controller.takeScreenshot();
expect(screenshot, isNotNull);
await headlessWebView.dispose();
expect(headlessWebView.isRunning(), false);
}, skip: shouldSkip);
}