Search in sources :

Example 6 with DockerSeleniumRemoteProxy

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

the class VncAuthenticationServletTest 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)

Example 7 with DockerSeleniumRemoteProxy

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

the class ZaleniumConsoleServletTest 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(30000, DockerSeleniumStarterRemoteProxy.class.getCanonicalName());
    DockerSeleniumStarterRemoteProxy proxyZero = DockerSeleniumStarterRemoteProxy.getNewInstance(registrationRequest, registry);
    registrationRequest = TestUtils.getRegistrationRequestForTesting(30001, SauceLabsRemoteProxy.class.getCanonicalName());
    CommonProxyUtilities commonProxyUtilities = mock(CommonProxyUtilities.class);
    when(commonProxyUtilities.readJSONFromUrl(anyString(), anyString(), anyString())).thenReturn(null);
    SauceLabsRemoteProxy.setCommonProxyUtilities(commonProxyUtilities);
    SauceLabsRemoteProxy sauceLabsProxy = SauceLabsRemoteProxy.getNewInstance(registrationRequest, registry);
    registrationRequest = TestUtils.getRegistrationRequestForTesting(30002, BrowserStackRemoteProxy.class.getCanonicalName());
    BrowserStackRemoteProxy.setCommonProxyUtilities(commonProxyUtilities);
    BrowserStackRemoteProxy browserStackRemoteProxy = BrowserStackRemoteProxy.getNewInstance(registrationRequest, registry);
    registrationRequest = TestUtils.getRegistrationRequestForTesting(30003, TestingBotRemoteProxy.class.getCanonicalName());
    TestingBotRemoteProxy.setCommonProxyUtilities(commonProxyUtilities);
    TestingBotRemoteProxy testingBotRemoteProxy = TestingBotRemoteProxy.getNewInstance(registrationRequest, registry);
    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();
    List<MutableCapabilities> capabilities = DockerSeleniumStarterRemoteProxy.getCapabilities();
    MutableCapabilities desiredCapabilities = new MutableCapabilities();
    desiredCapabilities.setCapability(CapabilityType.BROWSER_NAME, "NEW_BROWSER");
    desiredCapabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.LINUX);
    desiredCapabilities.setCapability(RegistrationRequest.MAX_INSTANCES, 1);
    capabilities.add(desiredCapabilities);
    registrationRequest.getConfiguration().capabilities.addAll(capabilities);
    DockerSeleniumRemoteProxy proxyTwo = DockerSeleniumRemoteProxy.getNewInstance(registrationRequest, registry);
    registry.add(proxyZero);
    registry.add(proxyOne);
    registry.add(proxyTwo);
    registry.add(sauceLabsProxy);
    registry.add(browserStackRemoteProxy);
    registry.add(testingBotRemoteProxy);
    request = mock(HttpServletRequest.class);
    response = mock(HttpServletResponse.class);
    when(request.getParameter("config")).thenReturn("true");
    when(request.getParameter("configDebug")).thenReturn("true");
    when(request.getServerName()).thenReturn("localhost");
    when(response.getOutputStream()).thenReturn(TestUtils.getMockedServletOutputStream());
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) SauceLabsRemoteProxy(de.zalando.ep.zalenium.proxy.SauceLabsRemoteProxy) DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy) JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) InstanceNotFoundException(javax.management.InstanceNotFoundException) TestingBotRemoteProxy(de.zalando.ep.zalenium.proxy.TestingBotRemoteProxy) HttpServletResponse(javax.servlet.http.HttpServletResponse) RegistrationRequest(org.openqa.grid.common.RegistrationRequest) ObjectName(javax.management.ObjectName) HttpServletRequest(javax.servlet.http.HttpServletRequest) DockerContainerMock(de.zalando.ep.zalenium.util.DockerContainerMock) DockerSeleniumStarterRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumStarterRemoteProxy) Hub(org.openqa.grid.web.Hub) MutableCapabilities(org.openqa.selenium.MutableCapabilities) GridHubConfiguration(org.openqa.grid.internal.utils.configuration.GridHubConfiguration) BrowserStackRemoteProxy(de.zalando.ep.zalenium.proxy.BrowserStackRemoteProxy) Before(org.junit.Before)

Example 8 with DockerSeleniumRemoteProxy

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

the class TestUtils method createProxy.

private static DockerSeleniumRemoteProxy createProxy(GridRegistry registry, RegistrationRequest req) {
    final DockerSeleniumRemoteProxy remoteProxy = new DockerSeleniumRemoteProxy(req, registry);
    remoteProxy.setupTimeoutListener();
    return remoteProxy;
}
Also used : DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy)

Example 9 with DockerSeleniumRemoteProxy

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

the class ZaleniumRegistry method takeRequestHandler.

private boolean takeRequestHandler(RequestHandler handler) {
    final TestSession session = proxies.getNewSession(handler.getRequest().getDesiredCapabilities());
    final boolean sessionCreated = session != null;
    if (sessionCreated) {
        String remoteName = "";
        if (session.getSlot().getProxy() instanceof DockerSeleniumRemoteProxy) {
            remoteName = ((DockerSeleniumRemoteProxy) session.getSlot().getProxy()).getRegistration().getContainerId();
        }
        long timeToAssignProxy = System.currentTimeMillis() - handler.getRequest().getCreationTime();
        LOG.info(String.format("Test session with internal key %s assigned to remote (%s) after %s seconds (%s ms).", session.getInternalKey(), remoteName, timeToAssignProxy / 1000, timeToAssignProxy));
        activeTestSessions.add(session);
        handler.bindSession(session);
    }
    return sessionCreated;
}
Also used : DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy) TestSession(org.openqa.grid.internal.TestSession)

Example 10 with DockerSeleniumRemoteProxy

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

the class ZaleniumRegistry method terminate.

/**
 * Ends this test session for the hub, releasing the resources in the hub / registry. It does not
 * release anything on the remote. The resources are released in a separate thread, so the call
 * returns immediately. It allows release with long duration not to block the test while the hub is
 * releasing the resource.
 *
 * @param session The session to terminate
 * @param reason  the reason for termination
 */
public void terminate(final TestSession session, final SessionTerminationReason reason) {
    // Thread safety reviewed
    String remoteName = "";
    if (session.getSlot().getProxy() instanceof DockerSeleniumRemoteProxy) {
        remoteName = ((DockerSeleniumRemoteProxy) session.getSlot().getProxy()).getRegistration().getContainerId();
    }
    String internalKey = Optional.ofNullable(session.getInternalKey()).orElse("No internal key");
    ExternalSessionKey externalKey = Optional.ofNullable(session.getExternalKey()).orElse(new ExternalSessionKey("No external key was assigned"));
    new Thread(() -> _release(session.getSlot(), reason), "Terminate Test Session int id: [" + internalKey + "] ext id: [" + externalKey + "] container: [" + remoteName + "]").start();
}
Also used : ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy)

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