fromExistingSession function
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),
(response) => handler.session.parseInfoResponse(response, sessionId));
}
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);
}