Search in sources :

Example 1 with DockerSeleniumRemoteProxy

use of de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy in project zalenium by zalando.

the class ZaleniumRegistryTest method proxyIsAdded.

@Test
public void proxyIsAdded() throws Exception {
    GridRegistry registry = ZaleniumRegistry.newInstance(new Hub(new GridHubConfiguration()));
    DockerSeleniumRemoteProxy p1 = TestUtils.getNewBasicRemoteProxy("app1", "http://machine1:4444/", registry);
    DockerSeleniumRemoteProxy p2 = TestUtils.getNewBasicRemoteProxy("app1", "http://machine2:4444/", registry);
    DockerSeleniumRemoteProxy p3 = TestUtils.getNewBasicRemoteProxy("app1", "http://machine3:4444/", registry);
    DockerSeleniumRemoteProxy p4 = TestUtils.getNewBasicRemoteProxy("app1", "http://machine4:4444/", registry);
    try {
        registry.add(p1);
        registry.add(p2);
        registry.add(p3);
        registry.add(p4);
        assertTrue(registry.getAllProxies().size() == 4);
    } finally {
        registry.stop();
    }
}
Also used : Hub(org.openqa.grid.web.Hub) DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy) GridHubConfiguration(org.openqa.grid.internal.utils.configuration.GridHubConfiguration) GridRegistry(org.openqa.grid.internal.GridRegistry) Test(org.junit.Test)

Example 2 with DockerSeleniumRemoteProxy

use of de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy 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)

Example 3 with DockerSeleniumRemoteProxy

use of de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy in project zalenium by zalando.

the class LivePreviewServlet method process.

@SuppressWarnings("WeakerAccess")
protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String refresh = "1200";
    String testBuild = "";
    try {
        refresh = Optional.ofNullable(request.getParameter("refresh")).orElse(refresh);
        testBuild = Optional.ofNullable(request.getParameter("build")).orElse(testBuild);
    } catch (Exception e) {
        LOGGER.debug(e.toString(), e);
    }
    List<String> nodes = new ArrayList<>();
    for (RemoteProxy proxy : getRegistry().getAllProxies()) {
        if (proxy instanceof DockerSeleniumRemoteProxy) {
            DockerSeleniumRemoteProxy dockerSeleniumRemoteProxy = (DockerSeleniumRemoteProxy) proxy;
            HtmlRenderer renderer = new LiveNodeHtmlRenderer(dockerSeleniumRemoteProxy);
            // Render the nodes that are part of an specified test build
            if (testBuild.isEmpty() || testBuild.equalsIgnoreCase(dockerSeleniumRemoteProxy.getTestBuild())) {
                nodes.add(renderer.renderSummary());
            }
        }
    }
    int size = nodes.size();
    int rightColumnSize = size / 2;
    int leftColumnSize = size - rightColumnSize;
    StringBuilder leftColumnNodes = new StringBuilder();
    for (int i = 0; i < leftColumnSize; i++) {
        leftColumnNodes.append(nodes.get(i));
    }
    StringBuilder rightColumnNodes = new StringBuilder();
    for (int i = leftColumnSize; i < nodes.size(); i++) {
        rightColumnNodes.append(nodes.get(i));
    }
    Map<String, String> livePreviewValues = new HashMap<>();
    livePreviewValues.put("{{refreshInterval}}", refresh);
    livePreviewValues.put("{{leftColumnNodes}}", leftColumnNodes.toString());
    livePreviewValues.put("{{rightColumnNodes}}", rightColumnNodes.toString());
    String templateFile = "html_templates/live_preview_servlet.html";
    TemplateRenderer templateRenderer = new TemplateRenderer(templateFile);
    String renderTemplate = templateRenderer.renderTemplate(livePreviewValues);
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    response.setStatus(200);
    try (InputStream in = new ByteArrayInputStream(renderTemplate.getBytes("UTF-8"))) {
        ByteStreams.copy(in, response.getOutputStream());
    } finally {
        response.getOutputStream().close();
    }
}
Also used : DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy) RemoteProxy(org.openqa.grid.internal.RemoteProxy) DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) LiveNodeHtmlRenderer(de.zalando.ep.zalenium.servlet.renderer.LiveNodeHtmlRenderer) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) TemplateRenderer(de.zalando.ep.zalenium.servlet.renderer.TemplateRenderer) LiveNodeHtmlRenderer(de.zalando.ep.zalenium.servlet.renderer.LiveNodeHtmlRenderer) HtmlRenderer(org.openqa.grid.internal.utils.HtmlRenderer)

Example 4 with DockerSeleniumRemoteProxy

use of de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy in project zalenium by zalando.

the class ZaleniumRegistryTest method proxyIsRemoved.

@Test
public void proxyIsRemoved() throws Exception {
    GridRegistry registry = ZaleniumRegistry.newInstance(new Hub(new GridHubConfiguration()));
    DockerSeleniumRemoteProxy p1 = TestUtils.getNewBasicRemoteProxy("app1", "http://machine1:4444/", registry);
    try {
        registry.add(p1);
        assertTrue(registry.getAllProxies().size() == 1);
        registry.removeIfPresent(p1);
        assertTrue(registry.getAllProxies().size() == 0);
    } finally {
        registry.stop();
    }
}
Also used : Hub(org.openqa.grid.web.Hub) DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy) GridHubConfiguration(org.openqa.grid.internal.utils.configuration.GridHubConfiguration) GridRegistry(org.openqa.grid.internal.GridRegistry) Test(org.junit.Test)

Example 5 with DockerSeleniumRemoteProxy

use of de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy in project zalenium by zalando.

the class LiveNodeServletTest method setUp.

@Before
public void setUp() throws IOException {
    try {
        ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=Hub");
        ManagementFactory.getPlatformMBeanServer().getObjectInstance(objectName);
        new JMXHelper().unregister(objectName);
    } catch (MalformedObjectNameException | InstanceNotFoundException e) {
    // Might be that the object does not exist, it is ok. Nothing to do, this is just a cleanup task.
    }
    registry = ZaleniumRegistry.newInstance(new Hub(new GridHubConfiguration()));
    this.originalContainerClient = ContainerFactory.getContainerClientGenerator();
    ContainerFactory.setContainerClientGenerator(DockerContainerMock::getMockedDockerContainerClient);
    // Creating the configuration and the registration request of the proxy (node)
    RegistrationRequest registrationRequest = TestUtils.getRegistrationRequestForTesting(40000, DockerSeleniumRemoteProxy.class.getCanonicalName());
    registrationRequest.getConfiguration().capabilities.clear();
    registrationRequest.getConfiguration().capabilities.addAll(DockerSeleniumStarterRemoteProxy.getCapabilities());
    DockerSeleniumRemoteProxy proxyOne = DockerSeleniumRemoteProxy.getNewInstance(registrationRequest, registry);
    registrationRequest = TestUtils.getRegistrationRequestForTesting(40001, DockerSeleniumRemoteProxy.class.getCanonicalName());
    registrationRequest.getConfiguration().capabilities.clear();
    registrationRequest.getConfiguration().capabilities.addAll(DockerSeleniumStarterRemoteProxy.getCapabilities());
    DockerSeleniumRemoteProxy proxyTwo = DockerSeleniumRemoteProxy.getNewInstance(registrationRequest, registry);
    registry.add(proxyOne);
    registry.add(proxyTwo);
    request = mock(HttpServletRequest.class);
    response = mock(HttpServletResponse.class);
    when(request.getParameter("refresh")).thenReturn("1");
    when(request.getServerName()).thenReturn("localhost");
    when(response.getOutputStream()).thenReturn(TestUtils.getMockedServletOutputStream());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MalformedObjectNameException(javax.management.MalformedObjectNameException) DockerContainerMock(de.zalando.ep.zalenium.util.DockerContainerMock) Hub(org.openqa.grid.web.Hub) DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy) JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) InstanceNotFoundException(javax.management.InstanceNotFoundException) HttpServletResponse(javax.servlet.http.HttpServletResponse) GridHubConfiguration(org.openqa.grid.internal.utils.configuration.GridHubConfiguration) RegistrationRequest(org.openqa.grid.common.RegistrationRequest) ObjectName(javax.management.ObjectName) Before(org.junit.Before)

Aggregations

DockerSeleniumRemoteProxy (de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy)10 GridHubConfiguration (org.openqa.grid.internal.utils.configuration.GridHubConfiguration)6 Hub (org.openqa.grid.web.Hub)6 RegistrationRequest (org.openqa.grid.common.RegistrationRequest)4 DockerContainerMock (de.zalando.ep.zalenium.util.DockerContainerMock)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)3 MalformedObjectNameException (javax.management.MalformedObjectNameException)3 ObjectName (javax.management.ObjectName)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Before (org.junit.Before)3 Test (org.junit.Test)3 GridRegistry (org.openqa.grid.internal.GridRegistry)3 JMXHelper (org.openqa.selenium.remote.server.jmx.JMXHelper)3 HashMap (java.util.HashMap)2 ExternalSessionKey (org.openqa.grid.internal.ExternalSessionKey)2 TestSession (org.openqa.grid.internal.TestSession)2 BrowserStackRemoteProxy (de.zalando.ep.zalenium.proxy.BrowserStackRemoteProxy)1 DockerSeleniumStarterRemoteProxy (de.zalando.ep.zalenium.proxy.DockerSeleniumStarterRemoteProxy)1 SauceLabsRemoteProxy (de.zalando.ep.zalenium.proxy.SauceLabsRemoteProxy)1