Search in sources :

Example 1 with JMXHelper

use of org.openqa.selenium.remote.server.jmx.JMXHelper in project zalenium by zalando.

the class DockerSeleniumRemoteProxyTest method videoRecordingIsStartedAndStopped.

@Test
public void videoRecordingIsStartedAndStopped() 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.setContainerClient(containerClient);
        dsProxy.getNewSession(getCapabilitySupportedByDockerSelenium());
        CommonProxyUtilities commonProxyUtilities = TestUtils.mockCommonProxyUtilitiesForDashboardTesting(temporaryFolder);
        TestUtils.ensureRequiredInputFilesExist(temporaryFolder);
        Dashboard.setCommonProxyUtilities(commonProxyUtilities);
        // Creating a spy proxy to verify the invoked methods
        DockerSeleniumRemoteProxy spyProxy = spy(proxy);
        // 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 video recording started
        String containerId = spyProxy.getContainerId();
        verify(spyProxy, times(1)).videoRecording(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.START_RECORDING);
        verify(spyProxy, times(1)).processContainerAction(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.START_RECORDING, containerId);
        // 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());
        verify(spyProxy, timeout(40000)).videoRecording(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.STOP_RECORDING);
        verify(spyProxy, timeout(40000)).processContainerAction(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.STOP_RECORDING, containerId);
        verify(spyProxy, timeout(40000)).copyVideos(containerId);
    } finally {
        ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:30000\"");
        new JMXHelper().unregister(objectName);
        Dashboard.restoreCommonProxyUtilities();
    }
}
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) 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 2 with JMXHelper

use of org.openqa.selenium.remote.server.jmx.JMXHelper in project zalenium by zalando.

the class DockerSeleniumRemoteProxyTest method tearDown.

@After
public void tearDown() throws MalformedObjectNameException {
    ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:40000\"");
    new JMXHelper().unregister(objectName);
    ContainerFactory.setContainerClientGenerator(originalDockerContainerClient);
    ContainerFactory.setIsKubernetes(originalIsKubernetesValue);
    ContainerFactory.setKubernetesContainerClient(originalKubernetesContainerClient);
    proxy.restoreContainerClient();
}
Also used : JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) ObjectName(javax.management.ObjectName) After(org.junit.After)

Example 3 with JMXHelper

use of org.openqa.selenium.remote.server.jmx.JMXHelper 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 4 with JMXHelper

use of org.openqa.selenium.remote.server.jmx.JMXHelper in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxyTest method variablesGrabTheConfiguredEnvironmentVariables.

@Test
public void variablesGrabTheConfiguredEnvironmentVariables() throws MalformedObjectNameException {
    // Mock the environment class that serves as proxy to retrieve env variables
    Environment environment = mock(Environment.class, withSettings().useConstructor());
    int amountOfDesiredContainers = 7;
    int amountOfMaxContainers = 8;
    int screenWidth = 1440;
    int screenHeight = 810;
    String seleniumNodeParams = "-debug";
    TimeZone timeZone = TimeZone.getTimeZone("America/Montreal");
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_DESIRED_CONTAINERS)).thenReturn(String.valueOf(amountOfDesiredContainers));
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_MAX_DOCKER_SELENIUM_CONTAINERS)).thenReturn(String.valueOf(amountOfMaxContainers));
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_SCREEN_HEIGHT)).thenReturn(String.valueOf(screenHeight));
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_SCREEN_WIDTH)).thenReturn(String.valueOf(screenWidth));
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_TZ)).thenReturn(timeZone.getID());
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.SELENIUM_NODE_PARAMS)).thenReturn(seleniumNodeParams);
    when(environment.getIntEnvVariable(any(String.class), any(Integer.class))).thenCallRealMethod();
    when(environment.getStringEnvVariable(any(String.class), any(String.class))).thenCallRealMethod();
    DockerSeleniumStarterRemoteProxy.setEnv(environment);
    try {
        ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:30000\"");
        new JMXHelper().unregister(objectName);
    } finally {
        DockerSeleniumStarterRemoteProxy.getNewInstance(request, registry);
    }
    Assert.assertEquals(amountOfDesiredContainers, DockerSeleniumStarterRemoteProxy.getDesiredContainersOnStartup());
    Assert.assertEquals(amountOfMaxContainers, DockerSeleniumStarterRemoteProxy.getMaxDockerSeleniumContainers());
    Assert.assertEquals(screenHeight, DockerSeleniumStarterRemoteProxy.getConfiguredScreenSize().getHeight());
    Assert.assertEquals(screenWidth, DockerSeleniumStarterRemoteProxy.getConfiguredScreenSize().getWidth());
    Assert.assertEquals(timeZone.getID(), DockerSeleniumStarterRemoteProxy.getConfiguredTimeZone().getID());
    Assert.assertEquals(seleniumNodeParams, DockerSeleniumStarterRemoteProxy.getSeleniumNodeParameters());
}
Also used : TimeZone(java.util.TimeZone) JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) Environment(de.zalando.ep.zalenium.util.Environment) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 5 with JMXHelper

use of org.openqa.selenium.remote.server.jmx.JMXHelper in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxyTest method amountOfCreatedContainersIsTheConfiguredOne.

@Test
public void amountOfCreatedContainersIsTheConfiguredOne() throws MalformedObjectNameException {
    // Mock the environment class that serves as proxy to retrieve env variables
    Environment environment = mock(Environment.class, withSettings().useConstructor());
    int amountOfDesiredContainers = 7;
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_DESIRED_CONTAINERS)).thenReturn(String.valueOf(amountOfDesiredContainers));
    when(environment.getIntEnvVariable(any(String.class), any(Integer.class))).thenCallRealMethod();
    DockerSeleniumStarterRemoteProxy.setEnv(environment);
    DockerSeleniumStarterRemoteProxy.setSleepIntervalMultiplier(0);
    try {
        ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:30000\"");
        new JMXHelper().unregister(objectName);
    } finally {
        DockerSeleniumStarterRemoteProxy.getNewInstance(request, registry);
    }
    registry.add(spyProxy);
    verify(spyProxy, timeout(5000).times(amountOfDesiredContainers)).startDockerSeleniumContainer(timeZone, screenSize, true);
    Assert.assertEquals(amountOfDesiredContainers, DockerSeleniumStarterRemoteProxy.getDesiredContainersOnStartup());
}
Also used : JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) Environment(de.zalando.ep.zalenium.util.Environment) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

ObjectName (javax.management.ObjectName)22 JMXHelper (org.openqa.selenium.remote.server.jmx.JMXHelper)22 RegistrationRequest (org.openqa.grid.common.RegistrationRequest)10 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 MalformedObjectNameException (javax.management.MalformedObjectNameException)9 GridHubConfiguration (org.openqa.grid.internal.utils.configuration.GridHubConfiguration)9 Hub (org.openqa.grid.web.Hub)9 After (org.junit.After)8 Before (org.junit.Before)8 CommonProxyUtilities (de.zalando.ep.zalenium.util.CommonProxyUtilities)6 Test (org.junit.Test)6 Environment (de.zalando.ep.zalenium.util.Environment)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 DockerSeleniumRemoteProxy (de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy)3 DockerContainerMock (de.zalando.ep.zalenium.util.DockerContainerMock)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ExternalSessionKey (org.openqa.grid.internal.ExternalSessionKey)2 TestSession (org.openqa.grid.internal.TestSession)2 WebDriverRequest (org.openqa.grid.web.servlet.handler.WebDriverRequest)2 JsonElement (com.google.gson.JsonElement)1