Search in sources :

Example 46 with TestSession

use of org.openqa.grid.internal.TestSession in project zalenium by zalando.

the class TestingBotRemoteProxyTest method testInformationIsRetrievedWhenStoppingSession.

@Test
public void testInformationIsRetrievedWhenStoppingSession() {
    // Capability which should result in a created session
    Map<String, Object> requestedCapability = new HashMap<>();
    requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
    requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.MAC);
    // Getting a test session in the TestingBot node
    TestingBotRemoteProxy spyProxy = spy(testingBotProxy);
    TestSession testSession = spyProxy.getNewSession(requestedCapability);
    Assert.assertNotNull(testSession);
    String mockSeleniumSessionId = "2cf5d115-ca6f-4bc4-bc06-a4fca00836ce";
    testSession.setExternalKey(new ExternalSessionKey(mockSeleniumSessionId));
    // We release the session, the node should be free
    WebDriverRequest request = mock(WebDriverRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    when(request.getMethod()).thenReturn("DELETE");
    when(request.getRequestType()).thenReturn(RequestType.STOP_SESSION);
    testSession.getSlot().doFinishRelease();
    spyProxy.afterCommand(testSession, request, response);
    verify(spyProxy, timeout(1000 * 5)).getTestInformation(mockSeleniumSessionId);
    TestInformation testInformation = spyProxy.getTestInformation(mockSeleniumSessionId);
    Assert.assertEquals("loadZalandoPageAndCheckTitle", testInformation.getTestName());
    Assert.assertThat(testInformation.getFileName(), CoreMatchers.containsString("testingbot_loadZalandoPageAndCheckTitle_Safari9_CAPITAN"));
    Assert.assertEquals("Safari9 9, CAPITAN", testInformation.getBrowserAndPlatform());
    Assert.assertEquals("https://s3-eu-west-1.amazonaws.com/eurectestingbot/2cf5d115-ca6f-4bc4-bc06-a4fca00836ce.mp4", testInformation.getVideoUrl());
}
Also used : TestInformation(de.zalando.ep.zalenium.dashboard.TestInformation) ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonObject(com.google.gson.JsonObject) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Example 47 with TestSession

use of org.openqa.grid.internal.TestSession in project zalenium by zalando.

the class TestingBotRemoteProxyTest method requestIsNotModifiedInOtherRequestTypes.

@Test
public void requestIsNotModifiedInOtherRequestTypes() 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 TestingBot node
    TestSession testSession = testingBotProxy.getNewSession(requestedCapability);
    Assert.assertNotNull(testSession);
    // We need to mock all the needed objects to forward the session and see how in the beforeMethod
    // the TestingBot user and api key get added to the body request.
    WebDriverRequest request = mock(WebDriverRequest.class);
    when(request.getRequestURI()).thenReturn("session");
    when(request.getServletPath()).thenReturn("session");
    when(request.getContextPath()).thenReturn("");
    when(request.getMethod()).thenReturn("POST");
    when(request.getRequestType()).thenReturn(RequestType.REGULAR);
    JsonObject jsonObject = new JsonObject();
    JsonObject desiredCapabilities = new JsonObject();
    desiredCapabilities.addProperty(CapabilityType.BROWSER_NAME, BrowserType.IE);
    desiredCapabilities.addProperty(CapabilityType.PLATFORM_NAME, Platform.WIN8.name());
    jsonObject.add("desiredCapabilities", desiredCapabilities);
    when(request.getBody()).thenReturn(jsonObject.toString());
    Enumeration<String> strings = Collections.emptyEnumeration();
    when(request.getHeaderNames()).thenReturn(strings);
    HttpServletResponse response = mock(HttpServletResponse.class);
    ServletOutputStream stream = mock(ServletOutputStream.class);
    when(response.getOutputStream()).thenReturn(stream);
    testSession.forward(request, response, true);
    // The body should not be affected and not contain the TestingBot variables
    Assert.assertThat(request.getBody(), CoreMatchers.containsString(jsonObject.toString()));
    Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("key")));
    Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("secret")));
    when(request.getMethod()).thenReturn("GET");
    testSession.forward(request, response, true);
    Assert.assertThat(request.getBody(), CoreMatchers.containsString(jsonObject.toString()));
    Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("key")));
    Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("secret")));
}
Also used : HashMap(java.util.HashMap) ServletOutputStream(javax.servlet.ServletOutputStream) TestSession(org.openqa.grid.internal.TestSession) JsonObject(com.google.gson.JsonObject) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonObject(com.google.gson.JsonObject) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Example 48 with TestSession

use of org.openqa.grid.internal.TestSession in project zalenium by zalando.

the class ZaleniumRegistry method takeRequestHandler.

private boolean takeRequestHandler(RequestHandler handler) {
    final TestSession session = proxies.getNewSession(handler.getRequest().getDesiredCapabilities());
    final boolean sessionCreated = session != null;
    if (sessionCreated) {
        String remoteName = "";
        if (session.getSlot().getProxy() instanceof DockerSeleniumRemoteProxy) {
            remoteName = ((DockerSeleniumRemoteProxy) session.getSlot().getProxy()).getRegistration().getContainerId();
        }
        long timeToAssignProxy = System.currentTimeMillis() - handler.getRequest().getCreationTime();
        LOG.info(String.format("Test session with internal key %s assigned to remote (%s) after %s seconds (%s ms).", session.getInternalKey(), remoteName, timeToAssignProxy / 1000, timeToAssignProxy));
        activeTestSessions.add(session);
        handler.bindSession(session);
    }
    return sessionCreated;
}
Also used : DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy) TestSession(org.openqa.grid.internal.TestSession)

Example 49 with TestSession

use of org.openqa.grid.internal.TestSession 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

TestSession (org.openqa.grid.internal.TestSession)49 Test (org.junit.Test)43 HashMap (java.util.HashMap)32 HttpServletResponse (javax.servlet.http.HttpServletResponse)17 WebDriverRequest (org.openqa.grid.web.servlet.handler.WebDriverRequest)17 ExternalSessionKey (org.openqa.grid.internal.ExternalSessionKey)11 JsonObject (com.google.gson.JsonObject)9 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 Mockito.anyString (org.mockito.Mockito.anyString)4 Dimension (org.openqa.selenium.Dimension)4 RegistrationRequest (org.openqa.grid.common.RegistrationRequest)3 JsonElement (com.google.gson.JsonElement)2 DockerSeleniumRemoteProxy (de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy)2 ProcessedCapabilities (de.zalando.ep.zalenium.util.ProcessedCapabilities)2 TimeZone (java.util.TimeZone)2 ObjectName (javax.management.ObjectName)2 JMXHelper (org.openqa.selenium.remote.server.jmx.JMXHelper)2