Search in sources :

Example 6 with TestSession

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

the class DockerSeleniumRemoteProxyTest method videoRecordingIsDisabled.

@Test
public void videoRecordingIsDisabled() throws MalformedObjectNameException, IOException {
    try {
        // Create a docker-selenium container
        RegistrationRequest request = TestUtils.getRegistrationRequestForTesting(30000, DockerSeleniumStarterRemoteProxy.class.getCanonicalName());
        DockerSeleniumStarterRemoteProxy dsProxy = new DockerSeleniumStarterRemoteProxy(request, registry);
        DockerSeleniumStarterRemoteProxy.setMaxDockerSeleniumContainers(1);
        DockerSeleniumStarterRemoteProxy.setConfiguredScreenSize(DockerSeleniumStarterRemoteProxy.DEFAULT_SCREEN_SIZE);
        DockerSeleniumStarterRemoteProxy.setConfiguredTimeZone(DockerSeleniumStarterRemoteProxy.DEFAULT_TZ.getID());
        DockerSeleniumStarterRemoteProxy.setContainerClient(containerClient);
        dsProxy.getNewSession(getCapabilitySupportedByDockerSelenium());
        // Mocking the environment variable to return false for video recording enabled
        Environment environment = mock(Environment.class);
        when(environment.getEnvVariable(DockerSeleniumRemoteProxy.ZALENIUM_VIDEO_RECORDING_ENABLED)).thenReturn("false");
        when(environment.getIntEnvVariable(DockerSeleniumRemoteProxy.ZALENIUM_MAX_TEST_SESSIONS, 1)).thenReturn(1);
        // Creating a spy proxy to verify the invoked methods
        CommonProxyUtilities commonProxyUtilities = TestUtils.mockCommonProxyUtilitiesForDashboardTesting(temporaryFolder);
        TestUtils.ensureRequiredInputFilesExist(temporaryFolder);
        Dashboard.setCommonProxyUtilities(commonProxyUtilities);
        DockerSeleniumRemoteProxy spyProxy = spy(proxy);
        DockerSeleniumRemoteProxy.setEnv(environment);
        DockerSeleniumRemoteProxy.readEnvVars();
        // Start pulling thread
        spyProxy.startPolling();
        // Get a test session
        TestSession newSession = spyProxy.getNewSession(getCapabilitySupportedByDockerSelenium());
        newSession.setExternalKey(new ExternalSessionKey("DockerSeleniumRemoteProxy Test"));
        Assert.assertNotNull(newSession);
        // We start the session, in order to start recording
        WebDriverRequest webDriverRequest = mock(WebDriverRequest.class);
        HttpServletResponse response = mock(HttpServletResponse.class);
        when(webDriverRequest.getMethod()).thenReturn("POST");
        when(webDriverRequest.getRequestType()).thenReturn(RequestType.START_SESSION);
        spyProxy.afterCommand(newSession, webDriverRequest, response);
        // Assert no video recording was started, videoRecording is invoked but processContainerAction should not
        verify(spyProxy, times(1)).videoRecording(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.START_RECORDING);
        verify(spyProxy, never()).processContainerAction(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.START_RECORDING, "");
        // We release the sessions, the node should be free
        webDriverRequest = mock(WebDriverRequest.class);
        response = mock(HttpServletResponse.class);
        when(webDriverRequest.getMethod()).thenReturn("DELETE");
        when(webDriverRequest.getRequestType()).thenReturn(RequestType.STOP_SESSION);
        newSession.getSlot().doFinishRelease();
        spyProxy.afterCommand(newSession, webDriverRequest, response);
        spyProxy.afterSession(newSession);
        Assert.assertFalse(spyProxy.isBusy());
        // Now we assert that videoRecording was invoked but processContainerAction not, neither copyVideos
        verify(spyProxy, timeout(40000)).videoRecording(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.STOP_RECORDING);
        verify(spyProxy, never()).processContainerAction(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.STOP_RECORDING, "");
        verify(spyProxy, never()).copyVideos("");
    } finally {
        DockerSeleniumRemoteProxy.restoreEnvironment();
        Dashboard.restoreCommonProxyUtilities();
        ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:30000\"");
        new JMXHelper().unregister(objectName);
    }
}
Also used : ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) TestSession(org.openqa.grid.internal.TestSession) Environment(de.zalando.ep.zalenium.util.Environment) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) RegistrationRequest(org.openqa.grid.common.RegistrationRequest) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 7 with TestSession

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

the class DockerSeleniumRemoteProxyTest method pollingThreadTearsDownNodeAfterTestIsCompleted.

@Test
public void pollingThreadTearsDownNodeAfterTestIsCompleted() throws IOException {
    try {
        CommonProxyUtilities commonProxyUtilities = TestUtils.mockCommonProxyUtilitiesForDashboardTesting(temporaryFolder);
        TestUtils.ensureRequiredInputFilesExist(temporaryFolder);
        Dashboard.setCommonProxyUtilities(commonProxyUtilities);
        // 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("DELETE");
        when(request.getRequestType()).thenReturn(RequestType.STOP_SESSION);
        newSession.getSlot().doFinishRelease();
        proxy.afterCommand(newSession, request, response);
        proxy.afterSession(newSession);
        // After running one test, the node shouldn't be busy and also down
        Assert.assertFalse(proxy.isBusy());
        Callable<Boolean> callable = () -> registry.getProxyById(proxy.getId()) == null;
        await().pollInterval(Duration.FIVE_HUNDRED_MILLISECONDS).atMost(Duration.TWO_SECONDS).until(callable);
    } finally {
        Dashboard.restoreCommonProxyUtilities();
    }
}
Also used : CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Example 8 with TestSession

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

the class DockerSeleniumStarterRemoteProxyTest method containerIsStartedWhenCustomTimeZoneIsProvided.

@Test
public void containerIsStartedWhenCustomTimeZoneIsProvided() {
    // Supported desired capability for the test session
    TimeZone timeZone = TimeZone.getTimeZone("America/Montreal");
    Map<String, Object> supportedCapability = new HashMap<>();
    supportedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
    supportedCapability.put(CapabilityType.PLATFORM_NAME, Platform.ANY);
    supportedCapability.put("tz", timeZone.getID());
    TestSession testSession = spyProxy.getNewSession(supportedCapability);
    Assert.assertNull(testSession);
    verify(spyProxy, timeout(1000).times(1)).startDockerSeleniumContainer(timeZone, screenSize);
}
Also used : TimeZone(java.util.TimeZone) HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) Test(org.junit.Test)

Example 9 with TestSession

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

the class DockerSeleniumStarterRemoteProxyTest method containerIsStartedWhenFirefoxCapabilitiesAreSupported.

@Test
public void containerIsStartedWhenFirefoxCapabilitiesAreSupported() {
    // Supported desired capability for the test session
    Map<String, Object> supportedCapability = new HashMap<>();
    supportedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
    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)

Example 10 with TestSession

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

the class DockerSeleniumStarterRemoteProxyTest method containerIsStartedWhenCustomScreenResolutionIsProvided.

@Test
public void containerIsStartedWhenCustomScreenResolutionIsProvided() {
    // Supported desired capability for the test session
    Dimension customScreenSize = new Dimension(1500, 1000);
    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("screen-resolution", 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)

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