Search in sources :

Example 16 with JMXHelper

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

Example 17 with JMXHelper

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

the class LiveNodeServletTest 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);
    objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:40001\"");
    new JMXHelper().unregister(objectName);
    ContainerFactory.setContainerClientGenerator(originalContainerClient);
}
Also used : JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) ObjectName(javax.management.ObjectName) After(org.junit.After)

Example 18 with JMXHelper

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

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

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

the class ZaleniumConsoleServletTest method tearDown.

@After
public void tearDown() throws MalformedObjectNameException {
    ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:30000\"");
    new JMXHelper().unregister(objectName);
    objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"https://ondemand.saucelabs.com:443\"");
    new JMXHelper().unregister(objectName);
    objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://hub-cloud.browserstack.com:80\"");
    new JMXHelper().unregister(objectName);
    objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://hub.testingbot.com:80\"");
    new JMXHelper().unregister(objectName);
    objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:40000\"");
    new JMXHelper().unregister(objectName);
    objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:40001\"");
    new JMXHelper().unregister(objectName);
    ContainerFactory.setContainerClientGenerator(originalContainerClient);
}
Also used : JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) ObjectName(javax.management.ObjectName) After(org.junit.After)

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