Search in sources :

Example 21 with WebDriverRequest

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

Example 22 with WebDriverRequest

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);
}
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

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