
org.openqa.grid.web.servlet.beta.WebProxyHtmlRendererBeta Maven / Gradle / Ivy
Go to download
Selenium automates browsers. That's it! What you do with that power is entirely up to you.
package org.openqa.grid.web.servlet.beta;
import java.util.Map;
import org.json.JSONObject;
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;
public class WebProxyHtmlRendererBeta implements HtmlRenderer {
private RemoteProxy proxy;
@SuppressWarnings("unused")
private WebProxyHtmlRendererBeta() {}
public WebProxyHtmlRendererBeta(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 : " + platform + "
");
builder.append(nodeTabs());
builder.append("");
builder.append(tabBrowsers());
builder.append(tabConfig());
builder.append("");
builder.append("");
return builder.toString();
}
private String getHtmlNodeVersion() {
try {
JSONObject object = proxy.getStatus();
String version = object.getJSONObject("value").getJSONObject("build").getString("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("");
Map config = proxy.getConfig();
for (String key : config.keySet()) {
builder.append("");
builder.append(key);
builder.append(":");
builder.append(config.get(key));
builder.append("
");
}
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:" + 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.
* @return
*/
public static String getPlatform(RemoteProxy proxy) {
Platform res = null;
if (proxy.getTestSlots().size() == 0) {
return "Unknown";
} else {
res = getPlatform(proxy.getTestSlots().get(0));
}
for (TestSlot slot : proxy.getTestSlots()) {
Platform tmp = getPlatform(slot);
if (tmp != res) {
return "mixed OS";
} else {
res = tmp;
}
}
if (res == null) {
return "not specified";
} else {
return res.toString();
}
}
private static Platform getPlatform(TestSlot slot) {
Object o = slot.getCapabilities().get(CapabilityType.PLATFORM);
if (o == null) {
return Platform.ANY;
} else {
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 Paltform");
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy