use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.
the class DockerSeleniumRemoteProxy method afterCommand.
@Override
public void afterCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) {
super.afterCommand(session, request, response);
LOGGER.debug(getId() + " lastCommand: " + request.getMethod() + " - " + request.getPathInfo() + " executed.");
if (request instanceof WebDriverRequest && "POST".equalsIgnoreCase(request.getMethod())) {
WebDriverRequest seleniumRequest = (WebDriverRequest) request;
if (RequestType.START_SESSION.equals(seleniumRequest.getRequestType())) {
String remoteName = "";
if (session.getSlot().getProxy() instanceof DockerSeleniumRemoteProxy) {
remoteName = ((DockerSeleniumRemoteProxy) session.getSlot().getProxy()).getRegistration().getContainerId();
}
ExternalSessionKey externalKey = Optional.ofNullable(session.getExternalKey()).orElse(new ExternalSessionKey("[No external key present]"));
LOGGER.info(String.format("Test session started with internal key %s and external key %s assigned to remote %s.", session.getInternalKey(), externalKey.getKey(), remoteName));
videoRecording(DockerSeleniumContainerAction.START_RECORDING);
}
}
}
use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.
the class BrowserStackRemoteProxyTest method credentialsAreAddedInSessionCreation.
@Test
public void credentialsAreAddedInSessionCreation() throws IOException {
// Capability which should result in a created session
Map<String, Object> requestedCapability = new HashMap<>();
requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.IE);
requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.WIN8);
// Getting a test session in the sauce labs node
TestSession testSession = browserStackProxy.getNewSession(requestedCapability);
Assert.assertNotNull(testSession);
// We need to mock all the needed objects to forward the session and see how in the beforeMethod
// the BrowserStack user and api key get added to the body request.
WebDriverRequest request = TestUtils.getMockedWebDriverRequestStartSession(BrowserType.IE, Platform.WIN8);
HttpServletResponse response = mock(HttpServletResponse.class);
ServletOutputStream stream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(stream);
testSession.setExternalKey(new ExternalSessionKey("BrowserStack Test"));
testSession.forward(request, response, true);
Environment env = new Environment();
// The body should now have the BrowserStack variables
String expectedBody = String.format("{\"desiredCapabilities\":{\"browserName\":\"internet explorer\",\"platformName\":" + "\"WIN8\",\"browserstack.user\":\"%s\",\"browserstack.key\":\"%s\"}}", env.getStringEnvVariable("BROWSER_STACK_USER", ""), env.getStringEnvVariable("BROWSER_STACK_KEY", ""));
verify(request).setBody(expectedBody);
}
Aggregations