Search in sources :

Example 11 with CommonProxyUtilities

use of de.zalando.ep.zalenium.util.CommonProxyUtilities in project zalenium by zalando.

the class SauceLabsRemoteProxyTest method nodeHasCapabilitiesEvenWhenUrlCallFails.

@SuppressWarnings("ConstantConditions")
@Test
public void nodeHasCapabilitiesEvenWhenUrlCallFails() {
    try {
        CommonProxyUtilities commonProxyUtilities = mock(CommonProxyUtilities.class);
        when(commonProxyUtilities.readJSONFromUrl(anyString(), anyString(), anyString())).thenReturn(null);
        SauceLabsRemoteProxy.setCommonProxyUtilities(commonProxyUtilities);
        RegistrationRequest request = TestUtils.getRegistrationRequestForTesting(30001, SauceLabsRemoteProxy.class.getCanonicalName());
        request = SauceLabsRemoteProxy.updateSLCapabilities(request, "");
        // Now the capabilities should be filled even if the url was not fetched
        Assert.assertFalse(request.getConfiguration().capabilities.isEmpty());
    } finally {
        SauceLabsRemoteProxy.restoreCommonProxyUtilities();
    }
}
Also used : CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) RegistrationRequest(org.openqa.grid.common.RegistrationRequest) Test(org.junit.Test)

Example 12 with CommonProxyUtilities

use of de.zalando.ep.zalenium.util.CommonProxyUtilities 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 13 with CommonProxyUtilities

use of de.zalando.ep.zalenium.util.CommonProxyUtilities in project zalenium by zalando.

the class DashboardCleanupServletTest method postDoCleanupAll.

@Test
public void postDoCleanupAll() throws IOException {
    try {
        CommonProxyUtilities proxyUtilities = TestUtils.mockCommonProxyUtilitiesForDashboardTesting(temporaryFolder);
        Dashboard.setCommonProxyUtilities(proxyUtilities);
        when(request.getParameter("action")).thenReturn("doCleanupAll");
        dashboardCleanupServlet.doPost(request, response);
        Assert.assertEquals("SUCCESS", response.getOutputStream().toString());
    } finally {
        Dashboard.restoreCommonProxyUtilities();
    }
}
Also used : CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) Test(org.junit.Test)

Example 14 with CommonProxyUtilities

use of de.zalando.ep.zalenium.util.CommonProxyUtilities in project zalenium by zalando.

the class BrowserStackRemoteProxyTest method setUp.

@SuppressWarnings("ConstantConditions")
@Before
public void setUp() {
    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()));
    // Creating the configuration and the registration request of the proxy (node)
    RegistrationRequest request = TestUtils.getRegistrationRequestForTesting(30002, BrowserStackRemoteProxy.class.getCanonicalName());
    CommonProxyUtilities commonProxyUtilities = mock(CommonProxyUtilities.class);
    when(commonProxyUtilities.readJSONFromUrl(anyString(), anyString(), anyString())).thenReturn(null);
    BrowserStackRemoteProxy.setCommonProxyUtilities(commonProxyUtilities);
    browserStackProxy = BrowserStackRemoteProxy.getNewInstance(request, registry);
    // we need to register a DockerSeleniumStarter proxy to have a proper functioning BrowserStackProxy
    request = TestUtils.getRegistrationRequestForTesting(30000, DockerSeleniumStarterRemoteProxy.class.getCanonicalName());
    DockerSeleniumStarterRemoteProxy dsStarterProxy = DockerSeleniumStarterRemoteProxy.getNewInstance(request, registry);
    // We add both nodes to the registry
    registry.add(browserStackProxy);
    registry.add(dsStarterProxy);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) Hub(org.openqa.grid.web.Hub) JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) InstanceNotFoundException(javax.management.InstanceNotFoundException) GridHubConfiguration(org.openqa.grid.internal.utils.configuration.GridHubConfiguration) RegistrationRequest(org.openqa.grid.common.RegistrationRequest) ObjectName(javax.management.ObjectName) Before(org.junit.Before)

Aggregations

CommonProxyUtilities (de.zalando.ep.zalenium.util.CommonProxyUtilities)14 Test (org.junit.Test)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 RegistrationRequest (org.openqa.grid.common.RegistrationRequest)7 ObjectName (javax.management.ObjectName)6 TestSession (org.openqa.grid.internal.TestSession)6 WebDriverRequest (org.openqa.grid.web.servlet.handler.WebDriverRequest)6 JMXHelper (org.openqa.selenium.remote.server.jmx.JMXHelper)6 Before (org.junit.Before)5 ExternalSessionKey (org.openqa.grid.internal.ExternalSessionKey)5 InstanceNotFoundException (javax.management.InstanceNotFoundException)4 MalformedObjectNameException (javax.management.MalformedObjectNameException)4 GridHubConfiguration (org.openqa.grid.internal.utils.configuration.GridHubConfiguration)4 Hub (org.openqa.grid.web.Hub)4 JsonElement (com.google.gson.JsonElement)3 TestInformation (de.zalando.ep.zalenium.dashboard.TestInformation)3 Environment (de.zalando.ep.zalenium.util.Environment)3 HashMap (java.util.HashMap)3 JsonObject (com.google.gson.JsonObject)2 BrowserStackRemoteProxy (de.zalando.ep.zalenium.proxy.BrowserStackRemoteProxy)1