use of org.openqa.grid.internal.TestSession in project zalenium by zalando.
the class BrowserStackRemoteProxyTest method requestIsNotModifiedInOtherRequestTypes.
@Test
public void requestIsNotModifiedInOtherRequestTypes() throws IOException {
// Capability which should result in a created session
Map<String, Object> requestedCapability = new HashMap<>();
requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.IE);
requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.WIN8);
// Getting a test session in the sauce labs node
TestSession testSession = browserStackProxy.getNewSession(requestedCapability);
Assert.assertNotNull(testSession);
// We need to mock all the needed objects to forward the session and see how in the beforeMethod
// the SauceLabs user and api key get added to the body request.
WebDriverRequest request = mock(WebDriverRequest.class);
when(request.getRequestURI()).thenReturn("session");
when(request.getServletPath()).thenReturn("session");
when(request.getContextPath()).thenReturn("");
when(request.getMethod()).thenReturn("POST");
when(request.getRequestType()).thenReturn(RequestType.REGULAR);
JsonObject jsonObject = new JsonObject();
JsonObject desiredCapabilities = new JsonObject();
desiredCapabilities.addProperty(CapabilityType.BROWSER_NAME, BrowserType.IE);
desiredCapabilities.addProperty(CapabilityType.PLATFORM_NAME, Platform.WIN8.name());
jsonObject.add("desiredCapabilities", desiredCapabilities);
when(request.getBody()).thenReturn(jsonObject.toString());
Enumeration<String> strings = Collections.emptyEnumeration();
when(request.getHeaderNames()).thenReturn(strings);
HttpServletResponse response = mock(HttpServletResponse.class);
ServletOutputStream stream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(stream);
testSession.setExternalKey(new ExternalSessionKey("BrowserStack Test"));
testSession.forward(request, response, true);
// The body should not be affected and not contain the BrowserStack variables
Assert.assertThat(request.getBody(), CoreMatchers.containsString(jsonObject.toString()));
Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("browserstack.user")));
Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("browserstack.key")));
when(request.getMethod()).thenReturn("GET");
testSession.forward(request, response, true);
Assert.assertThat(request.getBody(), CoreMatchers.containsString(jsonObject.toString()));
Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("browserstack.user")));
Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("browserstack.key")));
}
use of org.openqa.grid.internal.TestSession in project zalenium by zalando.
the class ZaleniumRegistry method release.
private void release(String internalKey, SessionTerminationReason reason) {
if (internalKey == null) {
return;
}
final TestSession session1 = activeTestSessions.findSessionByInternalKey(internalKey);
if (session1 != null) {
release(session1, reason);
return;
}
LOG.warn("Tried to release session with internal key " + internalKey + " but couldn't find it.");
}
use of org.openqa.grid.internal.TestSession in project zalenium by zalando.
the class CloudProxyHtmlRenderer method getSingleSlotHtml.
private String getSingleSlotHtml(TestSlot s) {
TestSession session = s.getSession();
String icon = "";
if (proxy instanceof TestingBotRemoteProxy) {
icon = "/grid/admin/ZaleniumResourceServlet/images/testingbot.png";
}
if (proxy instanceof BrowserStackRemoteProxy) {
icon = "/grid/admin/ZaleniumResourceServlet/images/browserstack.png";
}
if (proxy instanceof SauceLabsRemoteProxy) {
icon = "/grid/admin/ZaleniumResourceServlet/images/saucelabs.png";
}
String slotClass = "";
String slotTitle;
if (session != null) {
slotClass = "busy";
slotTitle = session.get("lastCommand").toString();
} else {
slotTitle = s.getCapabilities().toString();
}
Map<String, String> singleSlotValues = new HashMap<>();
singleSlotValues.put("{{slotIcon}}", icon);
singleSlotValues.put("{{slotClass}}", slotClass);
singleSlotValues.put("{{slotTitle}}", slotTitle);
return templateRenderer.renderSection("{{singleSlots}}", singleSlotValues);
}
use of org.openqa.grid.internal.TestSession in project zalenium by zalando.
the class LiveNodeHtmlRenderer method tabBrowsers.
// content of the browsers tab
private String tabBrowsers() {
StringBuilder browserSection = new StringBuilder();
for (TestSlot testSlot : proxy.getTestSlots()) {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities(testSlot.getCapabilities());
String icon = getConsoleIconPath(desiredCapabilities);
String version = desiredCapabilities.getVersion();
TestSession session = testSlot.getSession();
String slotClass = "";
String slotTitle;
if (session != null) {
slotClass = "busy";
slotTitle = session.get("lastCommand") == null ? "" : session.get("lastCommand").toString();
} else {
slotTitle = testSlot.getCapabilities().toString();
}
Map<String, String> browserValues = new HashMap<>();
browserValues.put("{{browserVersion}}", Optional.ofNullable(version).orElse("N/A"));
browserValues.put("{{slotIcon}}", Optional.ofNullable(icon).orElse("N/A"));
browserValues.put("{{slotClass}}", slotClass);
browserValues.put("{{slotTitle}}", slotTitle);
browserSection.append(templateRenderer.renderSection("{{tabBrowsers}}", browserValues));
}
return browserSection.toString();
}
use of org.openqa.grid.internal.TestSession in project carina by qaprosoft.
the class DeviceInfo method process.
protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setStatus(HttpStatus.SC_NOT_FOUND);
String id = request.getParameter("session");
if (id != null) {
TestSession session = this.getRegistry().getExistingSession(ExternalSessionKey.fromString(id));
if (session != null) {
Map<String, Object> cap = session.getSlot().getCapabilities();
if (cap.containsKey("udid")) {
RemoteDevice device = new RemoteDevice();
device.setName((String) cap.get("deviceName"));
device.setOs((String) cap.get("platformName"));
device.setOsVersion((String) cap.get("platformVersion"));
device.setType((String) cap.get("deviceType"));
device.setUdid((String) cap.get("udid"));
STFDevice stfDevice = STF.getDevice(device.getUdid());
if (stfDevice != null) {
device.setRemoteURL((String) stfDevice.getRemoteConnectUrl());
}
response.setStatus(HttpStatus.SC_OK);
response.getWriter().print(new ObjectMapper().writeValueAsString(device));
response.getWriter().close();
}
}
}
}
Aggregations