fromExistingSession function Null safety

WebDriver fromExistingSession (
  1. String sessionId,
  2. SyncRequestClient createRequestClient(
    1. Uri prefix
    ),
  3. {Uri uri,
  4. WebDriverSpec spec: WebDriverSpec.Auto,
  5. Map<String, dynamic> capabilities}
)

Creates a sync WebDriver from existing session.

This is intended for internal use! Please use fromExistingSession from sync_io.dart.

Implementation

WebDriver fromExistingSession(String sessionId,
    SyncRequestClient Function(Uri prefix) createRequestClient,
    {Uri uri,
    WebDriverSpec spec = WebDriverSpec.Auto,
    Map<String, dynamic> capabilities}) {
  uri ??= defaultUri;

  var session = SessionInfo(sessionId, spec, capabilities);

  // Update session info if not all is provided.
  if (spec == WebDriverSpec.Auto || capabilities == null) {
    // This client's prefix at root, it has no session prefix in it.
    final client = createRequestClient(uri);

    final handler = getHandler(spec);

    session = client.send(handler.session.buildInfoRequest(sessionId),
        handler.session.parseInfoResponse);
  }

  if (session.spec != WebDriverSpec.JsonWire &&
      session.spec != WebDriverSpec.W3c) {
    throw 'Unexpected spec: ${session.spec}';
  }

  return WebDriver(uri, session.id, UnmodifiableMapView(session.capabilities),
      createRequestClient(uri.resolve('session/${session.id}/')), session.spec);
}