| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library webdriver; | 5 library webdriver; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 WebDriverBase([ | 211 WebDriverBase([ |
| 212 this._host = 'localhost', | 212 this._host = 'localhost', |
| 213 this._port = 4444, | 213 this._port = 4444, |
| 214 this._path = '/wd/hub']) { | 214 this._path = '/wd/hub']) { |
| 215 _url = 'http://$_host:$_port$_path'; | 215 _url = 'http://$_host:$_port$_path'; |
| 216 } | 216 } |
| 217 | 217 |
| 218 void _failRequest(Completer completer, error, StackTrace stackTrace) { | 218 void _failRequest(Completer completer, error, [stackTrace]) { |
| 219 if (completer != null) { | 219 if (completer != null) { |
| 220 completer.completeError(new WebDriverError(-1, error), stackTrace); | 220 var trace = stackTrace != null ? stackTrace, getAttachedStackTrace(error); |
| 221 completer.completeError(new WebDriverError(-1, error), trace); |
| 221 } | 222 } |
| 222 } | 223 } |
| 223 | 224 |
| 224 /** | 225 /** |
| 225 * Execute a request to the WebDriver server. [http_method] should be | 226 * Execute a request to the WebDriver server. [http_method] should be |
| 226 * one of 'GET', 'POST', or 'DELETE'. [command] is the text to append | 227 * one of 'GET', 'POST', or 'DELETE'. [command] is the text to append |
| 227 * to the base URL path to get the full URL. [params] are the additional | 228 * to the base URL path to get the full URL. [params] are the additional |
| 228 * parameters. If a [List] or [Map] they will be posted as JSON parameters. | 229 * parameters. If a [List] or [Map] they will be posted as JSON parameters. |
| 229 * If a number or string, "/params" is appended to the URL. | 230 * If a number or string, "/params" is appended to the URL. |
| 230 */ | 231 */ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 var value = null; | 267 var value = null; |
| 267 // For some reason we get a bunch of NULs on the end | 268 // For some reason we get a bunch of NULs on the end |
| 268 // of the text and the json.parse blows up on these, so | 269 // of the text and the json.parse blows up on these, so |
| 269 // strip them with trim(). | 270 // strip them with trim(). |
| 270 // These NULs can be seen in the TCP packet, so it is not | 271 // These NULs can be seen in the TCP packet, so it is not |
| 271 // an issue with character encoding; it seems to be a bug | 272 // an issue with character encoding; it seems to be a bug |
| 272 // in WebDriver stack. | 273 // in WebDriver stack. |
| 273 results = new String.fromCharCodes(body).trim(); | 274 results = new String.fromCharCodes(body).trim(); |
| 274 if (!successCodes.contains(rsp.statusCode)) { | 275 if (!successCodes.contains(rsp.statusCode)) { |
| 275 _failRequest(completer, | 276 _failRequest(completer, |
| 276 'Unexpected response ${rsp.statusCode}; $results', null); | 277 'Unexpected response ${rsp.statusCode}; $results'); |
| 277 completer = null; | 278 completer = null; |
| 278 return; | 279 return; |
| 279 } | 280 } |
| 280 if (status == 0 && results.length > 0) { | 281 if (status == 0 && results.length > 0) { |
| 281 // 4xx responses send plain text; others send JSON. | 282 // 4xx responses send plain text; others send JSON. |
| 282 if (rsp.statusCode < 400) { | 283 if (rsp.statusCode < 400) { |
| 283 results = json.parse(results); | 284 results = json.parse(results); |
| 284 status = results['status']; | 285 status = results['status']; |
| 285 } | 286 } |
| 286 if (results is Map && (results as Map).containsKey('value')) { | 287 if (results is Map && (results as Map).containsKey('value')) { |
| 287 value = results['value']; | 288 value = results['value']; |
| 288 } | 289 } |
| 289 if (value is Map && value.containsKey('message')) { | 290 if (value is Map && value.containsKey('message')) { |
| 290 message = value['message']; | 291 message = value['message']; |
| 291 } | 292 } |
| 292 } | 293 } |
| 293 if (status == 0) { | 294 if (status == 0) { |
| 294 if (customHandler != null) { | 295 if (customHandler != null) { |
| 295 customHandler(rsp, value); | 296 customHandler(rsp, value); |
| 296 } else if (completer != null) { | 297 } else if (completer != null) { |
| 297 completer.complete(value); | 298 completer.complete(value); |
| 298 } | 299 } |
| 299 } | 300 } |
| 300 }, onError: (e) { | 301 }, onError: (error) { |
| 301 _failRequest(completer, e.error, e.stackTrace); | 302 _failRequest(completer, error); |
| 302 completer = null; | 303 completer = null; |
| 303 }); | 304 }); |
| 304 }) | 305 }) |
| 305 .catchError((e) { | 306 .catchError((error) { |
| 306 _failRequest(completer, e.error, e.stackTrace); | 307 _failRequest(completer, error); |
| 307 completer = null; | 308 completer = null; |
| 308 }); | 309 }); |
| 309 }) | 310 }) |
| 310 .catchError((e) { | 311 .catchError((error) { |
| 311 _failRequest(completer, e.error, e.stackTrace); | 312 _failRequest(completer, error); |
| 312 completer = null; | 313 completer = null; |
| 313 }); | 314 }); |
| 314 } catch (e, s) { | 315 } catch (e, s) { |
| 315 _failRequest(completer, e, s); | 316 _failRequest(completer, e, s); |
| 316 completer = null; | 317 completer = null; |
| 317 } | 318 } |
| 318 } | 319 } |
| 319 | 320 |
| 320 Future _get(String extraPath, | 321 Future _get(String extraPath, |
| 321 [Completer completer, Function customHandler]) { | 322 [Completer completer, Function customHandler]) { |
| (...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1441 * | 1442 * |
| 1442 * 'timestamp' (int) - The timestamp of the entry. | 1443 * 'timestamp' (int) - The timestamp of the entry. |
| 1443 * 'level' (String) - The log level of the entry, for example, "INFO". | 1444 * 'level' (String) - The log level of the entry, for example, "INFO". |
| 1444 * 'message' (String) - The log message. | 1445 * 'message' (String) - The log message. |
| 1445 * | 1446 * |
| 1446 * This works with Firefox but Chrome returns a 500 response due to a | 1447 * This works with Firefox but Chrome returns a 500 response due to a |
| 1447 * bad cast. | 1448 * bad cast. |
| 1448 */ | 1449 */ |
| 1449 Future<List<Map>> getLogs(String type) => _post('log', { 'type': type }); | 1450 Future<List<Map>> getLogs(String type) => _post('log', { 'type': type }); |
| 1450 } | 1451 } |
| OLD | NEW |