org.openqa.grid.web.servlet.console.DefaultProxyHtmlRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of selenium-server Show documentation
Show all versions of selenium-server Show documentation
Selenium automates browsers. That's it! What you do with that power is entirely up to you.
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.openqa.grid.web.servlet.console;
import org.openqa.grid.common.SeleniumProtocol;
import org.openqa.grid.common.exception.GridException;
import org.openqa.grid.internal.RemoteProxy;
import org.openqa.grid.internal.TestSession;
import org.openqa.grid.internal.TestSlot;
import org.openqa.grid.internal.utils.HtmlRenderer;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.CapabilityType;
import java.util.Map;
public class DefaultProxyHtmlRenderer implements HtmlRenderer {
private RemoteProxy proxy;
@SuppressWarnings("unused")
private DefaultProxyHtmlRenderer() {}
public DefaultProxyHtmlRenderer(RemoteProxy proxy) {
this.proxy = proxy;
}
public String renderSummary() {
StringBuilder builder = new StringBuilder();
builder.append("");
builder.append("");
builder.append(proxy.getClass().getSimpleName());
// TODO freynaud
builder.append(getHtmlNodeVersion());
String platform = getPlatform(proxy);
builder.append("
id : ");
builder.append(proxy.getId());
builder.append(", OS : ").append(platform).append("
");
builder.append(nodeTabs());
builder.append("");
builder.append(tabBrowsers());
builder.append(tabConfig());
builder.append("");
builder.append("");
return builder.toString();
}
private String getHtmlNodeVersion() {
try {
Map object = proxy.getProxyStatus();
Map, ?> value = (Map, ?>) object.get("value");
Map, ?> build = (Map, ?>) value.get("build");
String version = (String) build.get("version");
return " (version : " + version + ")";
} catch (Exception e) {
return " unknown version," + e.getMessage();
}
}
// content of the config tab.
private String tabConfig() {
StringBuilder builder = new StringBuilder();
builder.append("");
builder.append(proxy.getConfig().toString("%1$s: %2$s
"));
builder.append("");
return builder.toString();
}
// content of the browsers tab
private String tabBrowsers() {
StringBuilder builder = new StringBuilder();
builder.append("");
SlotsLines rcLines = new SlotsLines();
SlotsLines wdLines = new SlotsLines();
for (TestSlot slot : proxy.getTestSlots()) {
if (slot.getProtocol() == SeleniumProtocol.Selenium) {
rcLines.add(slot);
} else {
wdLines.add(slot);
}
}
if (rcLines.getLinesType().size() != 0) {
builder.append("Remote Control (legacy)
");
builder.append(getLines(rcLines));
}
if (wdLines.getLinesType().size() != 0) {
builder.append("WebDriver
");
builder.append(getLines(wdLines));
}
builder.append("");
return builder.toString();
}
// the lines of icon representing the possible slots
private String getLines(SlotsLines lines) {
StringBuilder builder = new StringBuilder();
for (MiniCapability cap : lines.getLinesType()) {
String icon = cap.getIcon();
String version = cap.getVersion();
builder.append("");
if (version != null) {
builder.append("v:").append(version);
}
for (TestSlot s : lines.getLine(cap)) {
builder.append(getSingleSlotHtml(s, icon));
}
builder.append("
");
}
return builder.toString();
}
// icon ( or generic html if icon not available )
private String getSingleSlotHtml(TestSlot s, String icon) {
StringBuilder builder = new StringBuilder();
TestSession session = s.getSession();
if (icon != null) {
builder.append("\n");
} else {
builder.append(">");
builder.append(s.getCapabilities().get(CapabilityType.BROWSER_NAME));
builder.append("");
}
return builder.toString();
}
// the tabs header.
private String nodeTabs() {
StringBuilder builder = new StringBuilder();
builder.append("");
builder.append("");
builder
.append("- Browsers
");
builder
.append("- Configuration
");
builder.append("
");
builder.append("");
return builder.toString();
}
/**
* return the platform for the proxy. It should be the same for all slots of the proxy, so checking that.
* @param proxy remote proxy
* @return Either the platform name, "Unknown", "mixed OS", or "not specified".
*/
public static String getPlatform(RemoteProxy proxy) {
if (proxy.getTestSlots().size() == 0) {
return "Unknown";
}
Platform res = getPlatform(proxy.getTestSlots().get(0));
for (TestSlot slot : proxy.getTestSlots()) {
Platform tmp = getPlatform(slot);
if (tmp != res) {
return "mixed OS";
}
res = tmp;
}
if (res == null) {
return "not specified";
}
return res.toString();
}
private static Platform getPlatform(TestSlot slot) {
Object o = slot.getCapabilities().get(CapabilityType.PLATFORM);
if (o == null) {
return Platform.ANY;
}
if (o instanceof String) {
return Platform.valueOf((String) o);
} else if (o instanceof Platform) {
return (Platform) o;
} else {
throw new GridException("Cannot cast " + o + " to org.openqa.selenium.Platform");
}
}
}