// check if the session is in the process of stopping
for (ServerSideSession session : sessions) {
if (session.getSessionId().equals(opaqueKey)) {
if (session.getSessionState() == ServerSideSession.SessionState.stopped) {
throw new WebDriverException(session.getStopCause().name());
} else {
return session;
}
}
}
// if the session isn't there anymore, try to give a helpful message on why it stopped
ServerSideSession.StopCause cause = reasonByOpaqueKey.get(opaqueKey);
if (cause != null) {
throw new WebDriverException(cause.name());
}
throw new WebDriverException("Cannot find session " + opaqueKey + " on the server.");
}