Search in sources :

Example 26 with TestSession

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")));
}
Also used : ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) HashMap(java.util.HashMap) ServletOutputStream(javax.servlet.ServletOutputStream) TestSession(org.openqa.grid.internal.TestSession) JsonObject(com.google.gson.JsonObject) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonObject(com.google.gson.JsonObject) Mockito.anyString(org.mockito.Mockito.anyString) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Example 27 with TestSession

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.");
}
Also used : TestSession(org.openqa.grid.internal.TestSession)

Example 28 with TestSession

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);
}
Also used : SauceLabsRemoteProxy(de.zalando.ep.zalenium.proxy.SauceLabsRemoteProxy) HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) TestingBotRemoteProxy(de.zalando.ep.zalenium.proxy.TestingBotRemoteProxy) BrowserStackRemoteProxy(de.zalando.ep.zalenium.proxy.BrowserStackRemoteProxy)

Example 29 with TestSession

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();
}
Also used : HashMap(java.util.HashMap) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) TestSession(org.openqa.grid.internal.TestSession) TestSlot(org.openqa.grid.internal.TestSlot)

Example 30 with TestSession

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();
            }
        }
    }
}
Also used : TestSession(org.openqa.grid.internal.TestSession) RemoteDevice(com.qaprosoft.carina.commons.models.RemoteDevice) STFDevice(com.qaprosoft.zafira.models.stf.STFDevice) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

TestSession (org.openqa.grid.internal.TestSession)49 Test (org.junit.Test)43 HashMap (java.util.HashMap)32 HttpServletResponse (javax.servlet.http.HttpServletResponse)17 WebDriverRequest (org.openqa.grid.web.servlet.handler.WebDriverRequest)17 ExternalSessionKey (org.openqa.grid.internal.ExternalSessionKey)11 JsonObject (com.google.gson.JsonObject)9 CommonProxyUtilities (de.zalando.ep.zalenium.util.CommonProxyUtilities)6 Environment (de.zalando.ep.zalenium.util.Environment)6 ServletOutputStream (javax.servlet.ServletOutputStream)6 TestInformation (de.zalando.ep.zalenium.dashboard.TestInformation)4 Mockito.anyString (org.mockito.Mockito.anyString)4 Dimension (org.openqa.selenium.Dimension)4 RegistrationRequest (org.openqa.grid.common.RegistrationRequest)3 JsonElement (com.google.gson.JsonElement)2 DockerSeleniumRemoteProxy (de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy)2 ProcessedCapabilities (de.zalando.ep.zalenium.util.ProcessedCapabilities)2 TimeZone (java.util.TimeZone)2 ObjectName (javax.management.ObjectName)2 JMXHelper (org.openqa.selenium.remote.server.jmx.JMXHelper)2