Search in sources :

Example 1 with ExternalSessionKey

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

use of org.openqa.grid.internal.ExternalSessionKey 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 3 with ExternalSessionKey

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

the class SauceLabsRemoteProxyTest method testEventIsInvoked.

@Test
public void testEventIsInvoked() throws IOException {
    try {
        // Capability which should result in a created session
        Map<String, Object> requestedCapability = new HashMap<>();
        requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.SAFARI);
        requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.MAC);
        // Getting a test session in the sauce labs node
        TestSession testSession = sauceLabsProxy.getNewSession(requestedCapability);
        Assert.assertNotNull(testSession);
        // We release the sessions and invoke the afterCommand with a mocked object
        Environment env = mock(Environment.class);
        when(env.getBooleanEnvVariable("ZALENIUM_SEND_ANONYMOUS_USAGE_INFO", false)).thenReturn(true);
        when(env.getStringEnvVariable("ZALENIUM_GA_API_VERSION", "")).thenReturn("1");
        when(env.getStringEnvVariable("ZALENIUM_GA_TRACKING_ID", "")).thenReturn("UA-88441352");
        when(env.getStringEnvVariable("ZALENIUM_GA_ENDPOINT", "")).thenReturn("https://www.google-analytics.com/collect");
        when(env.getStringEnvVariable("ZALENIUM_GA_ANONYMOUS_CLIENT_ID", "")).thenReturn("RANDOM_STRING");
        HttpClient client = mock(HttpClient.class);
        HttpResponse httpResponse = mock(HttpResponse.class);
        when(client.execute(any(HttpPost.class))).thenReturn(httpResponse);
        GoogleAnalyticsApi ga = new GoogleAnalyticsApi();
        GoogleAnalyticsApi gaSpy = spy(ga);
        gaSpy.setEnv(env);
        gaSpy.setHttpClient(client);
        SauceLabsRemoteProxy.setGa(gaSpy);
        WebDriverRequest webDriverRequest = mock(WebDriverRequest.class);
        HttpServletResponse response = mock(HttpServletResponse.class);
        when(webDriverRequest.getMethod()).thenReturn("DELETE");
        when(webDriverRequest.getRequestType()).thenReturn(RequestType.STOP_SESSION);
        testSession.getSlot().doFinishRelease();
        testSession.setExternalKey(new ExternalSessionKey("testKey"));
        sauceLabsProxy.afterCommand(testSession, webDriverRequest, response);
        verify(gaSpy, times(1)).testEvent(anyString(), anyString(), anyLong());
    } finally {
        SauceLabsRemoteProxy.restoreGa();
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) GoogleAnalyticsApi(de.zalando.ep.zalenium.util.GoogleAnalyticsApi) ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) HashMap(java.util.HashMap) HttpResponse(org.apache.http.HttpResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) TestSession(org.openqa.grid.internal.TestSession) HttpClient(org.apache.http.client.HttpClient) Environment(de.zalando.ep.zalenium.util.Environment) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Example 4 with ExternalSessionKey

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

the class TestingBotRemoteProxyTest method dashboardFilesGetCopied.

@Test
public void dashboardFilesGetCopied() {
    try {
        // 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);
        CommonProxyUtilities proxyUtilities = TestUtils.mockCommonProxyUtilitiesForDashboardTesting(temporaryFolder);
        Dashboard.setCommonProxyUtilities(proxyUtilities);
        TestInformation testInformation = spyProxy.getTestInformation(mockSeleniumSessionId);
        Dashboard.updateDashboard(testInformation);
        File videosFolder = new File(temporaryFolder.getRoot().getAbsolutePath(), "videos");
        Assert.assertTrue(videosFolder.isDirectory());
        File amountOfRunTests = new File(videosFolder, "executedTestsInfo.json");
        Assert.assertTrue(amountOfRunTests.exists());
        File dashboard = new File(videosFolder, "dashboard.html");
        Assert.assertTrue(dashboard.exists());
        Assert.assertTrue(dashboard.isFile());
        File testList = new File(videosFolder, "list.html");
        Assert.assertTrue(testList.exists());
        Assert.assertTrue(testList.isFile());
        File cssFolder = new File(videosFolder, "css");
        Assert.assertTrue(cssFolder.exists());
        Assert.assertTrue(cssFolder.isDirectory());
        File jsFolder = new File(videosFolder, "js");
        Assert.assertTrue(jsFolder.exists());
        Assert.assertTrue(jsFolder.isDirectory());
    } finally {
        Dashboard.restoreCommonProxyUtilities();
    }
}
Also used : TestInformation(de.zalando.ep.zalenium.dashboard.TestInformation) ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) 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) File(java.io.File) Test(org.junit.Test)

Example 5 with ExternalSessionKey

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

the class ZaleniumRegistryTest method sessionIsProcessed.

@Test
public void sessionIsProcessed() {
    Map<String, Object> requestedCapability = new HashMap<>();
    requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
    requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.LINUX);
    GridRegistry registry = ZaleniumRegistry.newInstance(new Hub(new GridHubConfiguration()));
    RegistrationRequest req = TestUtils.getRegistrationRequestForTesting(40000, DockerSeleniumRemoteProxy.class.getCanonicalName());
    req.getConfiguration().capabilities.clear();
    req.getConfiguration().capabilities.addAll(TestUtils.getDockerSeleniumCapabilitiesForTesting());
    DockerSeleniumRemoteProxy p1 = new DockerSeleniumRemoteProxy(req, registry);
    try {
        registry.add(p1);
        RequestHandler newSessionRequest = TestUtils.createNewSessionHandler(registry, requestedCapability);
        newSessionRequest.process();
        TestSession session = newSessionRequest.getSession();
        session.setExternalKey(new ExternalSessionKey(UUID.randomUUID().toString()));
        registry.terminate(session, SessionTerminationReason.CLIENT_STOPPED_SESSION);
        Callable<Boolean> callable = () -> registry.getActiveSessions().size() == 0;
        await().pollInterval(Duration.FIVE_HUNDRED_MILLISECONDS).atMost(Duration.TWO_SECONDS).until(callable);
    } finally {
        registry.stop();
    }
}
Also used : ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) HashMap(java.util.HashMap) DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy) RegistrationRequest(org.openqa.grid.common.RegistrationRequest) GridRegistry(org.openqa.grid.internal.GridRegistry) Hub(org.openqa.grid.web.Hub) RequestHandler(org.openqa.grid.web.servlet.handler.RequestHandler) TestSession(org.openqa.grid.internal.TestSession) GridHubConfiguration(org.openqa.grid.internal.utils.configuration.GridHubConfiguration) Test(org.junit.Test)

Aggregations

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