Search in sources :

Example 36 with TestSession

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

the class DockerSeleniumRemoteProxyTest method testIsMarkedAsPassedAndFailedWithCookie.

@Test
public void testIsMarkedAsPassedAndFailedWithCookie() {
    // Supported desired capability for the test session
    Map<String, Object> requestedCapability = getCapabilitySupportedByDockerSelenium();
    // Start polling thread
    proxy.startPolling();
    // Get a test session
    TestSession newSession = proxy.getNewSession(requestedCapability);
    Assert.assertNotNull(newSession);
    // The node should be busy since there is a session in it
    Assert.assertTrue(proxy.isBusy());
    // We release the session, the node should be free
    WebDriverRequest request = mock(WebDriverRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    when(request.getMethod()).thenReturn("POST");
    when(request.getRequestType()).thenReturn(RequestType.REGULAR);
    when(request.getPathInfo()).thenReturn("/cookie");
    when(request.getBody()).thenReturn("{\"cookie\": {\"name\": \"zaleniumTestPassed\", \"value\": true}}");
    proxy.beforeCommand(newSession, request, response);
    Assert.assertEquals(TestInformation.TestStatus.SUCCESS, proxy.getTestInformation().getTestStatus());
    when(request.getBody()).thenReturn("{\"cookie\": {\"name\": \"zaleniumTestPassed\", \"value\": false}}");
    proxy.beforeCommand(newSession, request, response);
    Assert.assertEquals(TestInformation.TestStatus.FAILED, proxy.getTestInformation().getTestStatus());
}
Also used : TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Example 37 with TestSession

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

the class DockerSeleniumRemoteProxyTest method nodeShutsDownWhenTestIsIdle.

@Test
public void nodeShutsDownWhenTestIsIdle() {
    // Supported desired capability for the test session
    Map<String, Object> requestedCapability = getCapabilitySupportedByDockerSelenium();
    requestedCapability.put("idleTimeout", 1L);
    DockerSeleniumRemoteProxy spyProxy = spy(proxy);
    // Start pulling thread
    spyProxy.startPolling();
    // Get a test session
    TestSession newSession = spyProxy.getNewSession(requestedCapability);
    Assert.assertNotNull(newSession);
    // Start the session
    WebDriverRequest webDriverRequest = mock(WebDriverRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    when(webDriverRequest.getMethod()).thenReturn("POST");
    when(webDriverRequest.getRequestType()).thenReturn(RequestType.START_SESSION);
    when(webDriverRequest.getPathInfo()).thenReturn("/something");
    spyProxy.beforeCommand(newSession, webDriverRequest, response);
    // The node should be busy since there is a session in it
    Assert.assertTrue(spyProxy.isBusy());
    // The node should tear down after the maximum idle time is elapsed
    Assert.assertTrue(spyProxy.isBusy());
    Callable<Boolean> callable = () -> registry.getProxyById(spyProxy.getId()) == null;
    await().pollInterval(Duration.FIVE_HUNDRED_MILLISECONDS).atMost(Duration.FIVE_SECONDS).until(callable);
}
Also used : TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Example 38 with TestSession

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

the class DockerSeleniumStarterRemoteProxyTest method containerIsStartedWhenScreenResolutionIsProvided.

@Test
public void containerIsStartedWhenScreenResolutionIsProvided() {
    // Supported desired capability for the test session
    Dimension customScreenSize = new Dimension(1280, 760);
    Map<String, Object> supportedCapability = new HashMap<>();
    supportedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
    supportedCapability.put(CapabilityType.PLATFORM_NAME, Platform.ANY);
    String screenResolution = String.format("%sx%s", customScreenSize.getWidth(), customScreenSize.getHeight());
    supportedCapability.put("screenResolution", screenResolution);
    TestSession testSession = spyProxy.getNewSession(supportedCapability);
    Assert.assertNull(testSession);
    verify(spyProxy, timeout(1000).times(1)).startDockerSeleniumContainer(timeZone, customScreenSize);
}
Also used : HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) Dimension(org.openqa.selenium.Dimension) Test(org.junit.Test)

Example 39 with TestSession

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

the class DockerSeleniumStarterRemoteProxyTest method noContainerIsStartedWhenBrowserCapabilityIsAbsent.

@Test
public void noContainerIsStartedWhenBrowserCapabilityIsAbsent() {
    // Browser is absent
    Map<String, Object> nonSupportedCapability = new HashMap<>();
    nonSupportedCapability.put(CapabilityType.PLATFORM_NAME, Platform.LINUX);
    TestSession testSession = spyProxy.getNewSession(nonSupportedCapability);
    Assert.assertNull(testSession);
    verify(spyProxy, never()).startDockerSeleniumContainer(timeZone, screenSize);
    verify(spyProxy, never()).startDockerSeleniumContainer(timeZone, screenSize);
}
Also used : HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) Test(org.junit.Test)

Example 40 with TestSession

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

the class DockerSeleniumStarterRemoteProxyTest method containerIsStartedWhenChromeCapabilitiesAreSupported.

@Test
public void containerIsStartedWhenChromeCapabilitiesAreSupported() {
    // Supported desired capability for the test session
    Map<String, Object> supportedCapability = new HashMap<>();
    supportedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
    supportedCapability.put(CapabilityType.PLATFORM_NAME, Platform.LINUX);
    TestSession testSession = spyProxy.getNewSession(supportedCapability);
    Assert.assertNull(testSession);
    verify(spyProxy, timeout(1000).times(1)).startDockerSeleniumContainer(timeZone, screenSize);
}
Also used : HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) 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