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();
}
}
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();
}
}
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();
}
}
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();
}
}
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());
}
Aggregations