Search in sources :

Example 11 with ExternalSessionKey

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);
        }
    }
}
Also used : ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest)

Example 12 with ExternalSessionKey

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();
}
Also used : ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy)

Example 13 with ExternalSessionKey

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);
}
Also used : ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) HashMap(java.util.HashMap) ServletOutputStream(javax.servlet.ServletOutputStream) TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) Environment(de.zalando.ep.zalenium.util.Environment) JsonObject(com.google.gson.JsonObject) Mockito.anyString(org.mockito.Mockito.anyString) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Aggregations

ExternalSessionKey (org.openqa.grid.internal.ExternalSessionKey)13 Test (org.junit.Test)11 TestSession (org.openqa.grid.internal.TestSession)11 WebDriverRequest (org.openqa.grid.web.servlet.handler.WebDriverRequest)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)10 HashMap (java.util.HashMap)9 JsonObject (com.google.gson.JsonObject)5 CommonProxyUtilities (de.zalando.ep.zalenium.util.CommonProxyUtilities)5 TestInformation (de.zalando.ep.zalenium.dashboard.TestInformation)4 Environment (de.zalando.ep.zalenium.util.Environment)4 ServletOutputStream (javax.servlet.ServletOutputStream)3 Mockito.anyString (org.mockito.Mockito.anyString)3 RegistrationRequest (org.openqa.grid.common.RegistrationRequest)3 JsonElement (com.google.gson.JsonElement)2 DockerSeleniumRemoteProxy (de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy)2 ObjectName (javax.management.ObjectName)2 JMXHelper (org.openqa.selenium.remote.server.jmx.JMXHelper)2 GoogleAnalyticsApi (de.zalando.ep.zalenium.util.GoogleAnalyticsApi)1 File (java.io.File)1 HttpResponse (org.apache.http.HttpResponse)1