use of org.openqa.grid.internal.ExternalSessionKey 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.internal.ExternalSessionKey in project zalenium by zalando.
the class ZaleniumRegistry method terminate.
/**
* Ends this test session for the hub, releasing the resources in the hub / registry. It does not
* release anything on the remote. The resources are released in a separate thread, so the call
* returns immediately. It allows release with long duration not to block the test while the hub is
* releasing the resource.
*
* @param session The session to terminate
* @param reason the reason for termination
*/
public void terminate(final TestSession session, final SessionTerminationReason reason) {
// Thread safety reviewed
String remoteName = "";
if (session.getSlot().getProxy() instanceof DockerSeleniumRemoteProxy) {
remoteName = ((DockerSeleniumRemoteProxy) session.getSlot().getProxy()).getRegistration().getContainerId();
}
String internalKey = Optional.ofNullable(session.getInternalKey()).orElse("No internal key");
ExternalSessionKey externalKey = Optional.ofNullable(session.getExternalKey()).orElse(new ExternalSessionKey("No external key was assigned"));
new Thread(() -> _release(session.getSlot(), reason), "Terminate Test Session int id: [" + internalKey + "] ext id: [" + externalKey + "] container: [" + remoteName + "]").start();
}
use of org.openqa.grid.internal.ExternalSessionKey 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