Merge pull request #50 from DrMarcII/master
Improved closing behavior, add support for connecting to existing sessions.
diff --git a/lib/html.dart b/lib/html.dart
index a983b1c..9ed8086 100644
--- a/lib/html.dart
+++ b/lib/html.dart
@@ -32,6 +32,16 @@
new UnmodifiableMapView(response['value']));
}
+Future<WebDriver> fromExistingSession(String sessionId, {Uri uri}) async {
+ if (uri == null) {
+ uri = defaultUri;
+ }
+
+ var commandProcessor = new _HtmlCommandProcessor();
+
+ return new WebDriver(commandProcessor, uri, sessionId, const {});
+}
+
class _HtmlCommandProcessor implements CommandProcessor {
Lock _lock = new Lock();
@@ -44,6 +54,8 @@
Future<Object> delete(Uri uri, {bool value: true}) =>
_request('DELETE', uri, null, value);
+ Future close() async {}
+
Future<Object> _request(
String method, Uri uri, dynamic params, bool value) async {
await _lock.acquire();
diff --git a/lib/io.dart b/lib/io.dart
index 0359124..ede6d68 100644
--- a/lib/io.dart
+++ b/lib/io.dart
@@ -38,6 +38,16 @@
new UnmodifiableMapView(response['value']));
}
+Future<WebDriver> fromExistingSession(String sessionId, {Uri uri}) async {
+ if (uri == null) {
+ uri = defaultUri;
+ }
+
+ var commandProcessor = new _IOCommandProcessor();
+
+ return new WebDriver(commandProcessor, uri, sessionId, const {});
+}
+
final ContentType _contentTypeJson =
new ContentType("application", "json", charset: "utf-8");
@@ -75,6 +85,10 @@
return await _processResponse(await request.close(), value);
}
+ Future close() async {
+ await client.close(force: true);
+ }
+
_processResponse(HttpClientResponse response, bool value) async {
var respBody = await UTF8.decodeStream(response);
_lock.release();
diff --git a/lib/src/command_processor.dart b/lib/src/command_processor.dart
index bbd7b07..53a804f 100644
--- a/lib/src/command_processor.dart
+++ b/lib/src/command_processor.dart
@@ -9,4 +9,6 @@
Future<Object> get(Uri uri, {bool value: true});
Future<Object> delete(Uri uri, {bool value: true});
+
+ Future close();
}
diff --git a/lib/src/web_driver.dart b/lib/src/web_driver.dart
index f72e087..edbfe49 100644
--- a/lib/src/web_driver.dart
+++ b/lib/src/web_driver.dart
@@ -63,6 +63,7 @@
/// Quit the browser.
Future quit() async {
await _commandProcessor.delete(uri.resolve('session/$id'));
+ await _commandProcessor.close();
}
/// Handles for all of the currently displayed tabs/windows.
diff --git a/pubspec.yaml b/pubspec.yaml
index ae60d97..45f3102 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: webdriver
-version: 0.10.0-pre.1
+version: 0.10.0-pre.2
author: Google Inc.
description: >
Provides WebDriver bindings for Dart. These use the WebDriver JSON interface,