public void afterCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) { session.put("lastCommand", request.getMethod() + " - " + request.getPathInfo() + " executed."); // throw an exception if we got back a HTTP 404 // ignore if we were trying to DELETE a session if ((response.getStatus() == HttpServletResponse.SC_NOT_FOUND) && (!isWebDriverCommand(request, HttpMethod.DELETE, String.format("/session/%s", session.getExternalKey())))) { throw new GridException("Sauce Labs session no longer exists. It may have timed out."); } }
public void afterCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) { session.put("lastCommand", request.getMethod() + " - " + request.getPathInfo() + " executed."); // throw an exception if we got back a HTTP 404 // ignore if we were trying to DELETE a session if ((response.getStatus() == HttpServletResponse.SC_NOT_FOUND) && (!isWebDriverCommand(request, HttpMethod.DELETE, String.format("/session/%s", session.getExternalKey())))) { throw new GridException("Sauce Labs session no longer exists. It may have timed out."); } }
public void beforeCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> requestedCapabilities = session.getRequestedCapabilities(); // give up if sauce labs is down ... // this should fail faster vs. returning the session to hub by doing this check in #getNewSession // (DefaultRemoteProxy's behavior) if (down) { throw new GridException("Sauce Labs is currently down."); } if (session.get("authenticated-session") == null) { // error the session when there is no sauce user name and/or access key if (isMissingRequiredCapabilities(requestedCapabilities)) { throw new GridException("Sauce Labs credentials were not specified."); } final String username = (String) requestedCapabilities.get(SauceLabsCapability.USERNAME_CAPABILITY); final String accessKey = (String) requestedCapabilities.get(SauceLabsCapability.ACCESS_KEY_CAPABILITY); if (!sauceApi.isAuthenticated(username, accessKey)) { // TODO isAuthenticated will return false when Sauce labs is down even if the credentials are valid. throw new GridException("Sauce Labs credentials are invalid."); } // make a note that this session is already authenticated session.put("authenticated-session", true); } session.put("lastCommand", request.getMethod() + " - " + request.getPathInfo() + " executing ..."); }
public void beforeCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> requestedCapabilities = session.getRequestedCapabilities(); // give up if sauce labs is down ... // this should fail faster vs. returning the session to hub by doing this check in #getNewSession // (DefaultRemoteProxy's behavior) if (down) { throw new GridException("Sauce Labs is currently down."); } if (session.get("authenticated-session") == null) { // error the session when there is no sauce user name and/or access key if (isMissingRequiredCapabilities(requestedCapabilities)) { throw new GridException("Sauce Labs credentials were not specified."); } final String username = (String) requestedCapabilities.get(SauceLabsCapability.USERNAME_CAPABILITY); final String accessKey = (String) requestedCapabilities.get(SauceLabsCapability.ACCESS_KEY_CAPABILITY); if (!sauceApi.isAuthenticated(username, accessKey)) { // TODO isAuthenticated will return false when Sauce labs is down even if the credentials are valid. throw new GridException("Sauce Labs credentials are invalid."); } // make a note that this session is already authenticated session.put("authenticated-session", true); } session.put("lastCommand", request.getMethod() + " - " + request.getPathInfo() + " executing ..."); }