send<T> method

Future<T> send<T>(
  1. WebDriverRequest request,
  2. T process(
    1. WebDriverResponse
    )
)
inherited

Implementation

Future<T> send<T>(
    WebDriverRequest request, T Function(WebDriverResponse) process) async {
  if (request.method == null) {
    return process(WebDriverResponse(200, null, request.body));
  }

  final startTime = DateTime.now();
  var trace = Chain.current();
  trace = trace.foldFrames((f) => f.library.startsWith('package:webdriver/'),
      terse: true);

  Object? exception;
  T? response;
  try {
    return response = process(await sendRaw(request));
  } catch (e) {
    exception = e;
    rethrow;
  } finally {
    final event = WebDriverCommandEvent(
        method: request.method!.name,
        endPoint: resolve(request.uri!).toString(),
        params: request.body,
        startTime: startTime,
        endTime: DateTime.now(),
        exception: exception,
        result: response,
        stackTrace: trace);
    for (final listener in _commandListeners) {
      await listener(event);
    }
  }
}