Change captureScreenshot to return Stream<int>.
Add == && hashCode to exception classes.
diff --git a/lib/src/exception.dart b/lib/src/exception.dart
index 553a03e..9e5ca7d 100644
--- a/lib/src/exception.dart
+++ b/lib/src/exception.dart
@@ -89,7 +89,15 @@
const WebDriverException._(this.statusCode, this.message);
+ @override
String toString() => '$runtimeType ($statusCode): $message';
+
+ @override
+ bool operator ==(other) => other != null && other.runtimeType == this.runtimeType &&
+ other.statusCode == this.statusCode && other.message == this.message;
+
+ @override
+ int get hashCode => statusCode + message.hashCode;
}
class InvalidRequestException extends WebDriverException {
diff --git a/lib/src/web_driver.dart b/lib/src/web_driver.dart
index 173b8fc..fc64ed1 100644
--- a/lib/src/web_driver.dart
+++ b/lib/src/web_driver.dart
@@ -117,8 +117,10 @@
Mouse get mouse => new Mouse._(this);
/// Take a screenshot of the current page as PNG.
- Future<List<int>> captureScreenshot() => getRequest('screenshot')
- .then((screenshot) => CryptoUtils.base64StringToBytes(screenshot));
+ Stream<int> captureScreenshot() async* {
+ var encoded = await getRequest('screenshot');
+ yield* new Stream.fromIterable(CryptoUtils.base64StringToBytes(encoded));
+ }
/// Inject a snippet of JavaScript into the page for execution in the context
/// of the currently selected frame. The executed script is assumed to be
diff --git a/test/src/web_driver_test.dart b/test/src/web_driver_test.dart
index 7634055..ae28d9a 100644
--- a/test/src/web_driver_test.dart
+++ b/test/src/web_driver_test.dart
@@ -176,7 +176,7 @@
});
test('captureScreenshot', () async {
- var screenshot = await driver.captureScreenshot();
+ var screenshot = await driver.captureScreenshot().toList();
expect(screenshot, hasLength(isPositive));
expect(screenshot, everyElement(new isInstanceOf<int>()));
});