Search in sources :

Example 6 with WebDriverRequest

use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.

the class SauceLabsRemoteProxyTest method checkBeforeSessionInvocation.

@Test
public void checkBeforeSessionInvocation() throws IOException {
    // Capability which should result in a created session
    Map<String, Object> requestedCapability = new HashMap<>();
    requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.SAFARI);
    requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.MAC);
    // Getting a test session in the sauce labs node
    TestSession testSession = sauceLabsProxy.getNewSession(requestedCapability);
    System.out.println(requestedCapability.toString());
    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 = TestUtils.getMockedWebDriverRequestStartSession(BrowserType.SAFARI, Platform.MAC);
    HttpServletResponse response = mock(HttpServletResponse.class);
    ServletOutputStream stream = mock(ServletOutputStream.class);
    when(response.getOutputStream()).thenReturn(stream);
    testSession.forward(request, response, true);
    Environment env = new Environment();
    // The body should now have the SauceLabs variables
    String expectedBody = String.format("{\"desiredCapabilities\":{\"browserName\":\"safari\",\"platformName\":" + "\"MAC\",\"username\":\"%s\",\"accessKey\":\"%s\",\"version\":\"latest\"}}", env.getStringEnvVariable("SAUCE_USERNAME", ""), env.getStringEnvVariable("SAUCE_ACCESS_KEY", ""));
    verify(request).setBody(expectedBody);
}
Also used : HashMap(java.util.HashMap) ServletOutputStream(javax.servlet.ServletOutputStream) TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) Environment(de.zalando.ep.zalenium.util.Environment) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Example 7 with WebDriverRequest

use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.

the class TestingBotRemoteProxyTest method credentialsAreAddedInSessionCreation.

@Test
public void credentialsAreAddedInSessionCreation() 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 TestingBot node
    TestSession testSession = testingBotProxy.getNewSession(requestedCapability);
    Assert.assertNotNull(testSession);
    // We need to mock all the needed objects to forward the session and see how in the beforeMethod
    // the TestingBot user and api key get added to the body request.
    WebDriverRequest request = TestUtils.getMockedWebDriverRequestStartSession(BrowserType.IE, Platform.WIN8);
    HttpServletResponse response = mock(HttpServletResponse.class);
    ServletOutputStream stream = mock(ServletOutputStream.class);
    when(response.getOutputStream()).thenReturn(stream);
    testSession.forward(request, response, true);
    Environment env = new Environment();
    // The body should now have the TestingBot variables
    String expectedBody = String.format("{\"desiredCapabilities\":{\"browserName\":\"internet explorer\",\"platformName\":" + "\"WIN8\",\"key\":\"%s\",\"secret\":\"%s\",\"version\":\"latest\"}}", env.getStringEnvVariable("TESTINGBOT_KEY", ""), env.getStringEnvVariable("TESTINGBOT_SECRET", ""));
    verify(request).setBody(expectedBody);
}
Also used : HashMap(java.util.HashMap) ServletOutputStream(javax.servlet.ServletOutputStream) TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) Environment(de.zalando.ep.zalenium.util.Environment) JsonObject(com.google.gson.JsonObject) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Example 8 with WebDriverRequest

use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.

the class TestingBotRemoteProxyTest method dashboardFilesGetCopied.

@Test
public void dashboardFilesGetCopied() {
    try {
        // Capability which should result in a created session
        Map<String, Object> requestedCapability = new HashMap<>();
        requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
        requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.MAC);
        // Getting a test session in the TestingBot node
        TestingBotRemoteProxy spyProxy = spy(testingBotProxy);
        TestSession testSession = spyProxy.getNewSession(requestedCapability);
        Assert.assertNotNull(testSession);
        String mockSeleniumSessionId = "2cf5d115-ca6f-4bc4-bc06-a4fca00836ce";
        testSession.setExternalKey(new ExternalSessionKey(mockSeleniumSessionId));
        // We release the session, the node should be free
        WebDriverRequest request = mock(WebDriverRequest.class);
        HttpServletResponse response = mock(HttpServletResponse.class);
        when(request.getMethod()).thenReturn("DELETE");
        when(request.getRequestType()).thenReturn(RequestType.STOP_SESSION);
        testSession.getSlot().doFinishRelease();
        spyProxy.afterCommand(testSession, request, response);
        CommonProxyUtilities proxyUtilities = TestUtils.mockCommonProxyUtilitiesForDashboardTesting(temporaryFolder);
        Dashboard.setCommonProxyUtilities(proxyUtilities);
        TestInformation testInformation = spyProxy.getTestInformation(mockSeleniumSessionId);
        Dashboard.updateDashboard(testInformation);
        File videosFolder = new File(temporaryFolder.getRoot().getAbsolutePath(), "videos");
        Assert.assertTrue(videosFolder.isDirectory());
        File amountOfRunTests = new File(videosFolder, "executedTestsInfo.json");
        Assert.assertTrue(amountOfRunTests.exists());
        File dashboard = new File(videosFolder, "dashboard.html");
        Assert.assertTrue(dashboard.exists());
        Assert.assertTrue(dashboard.isFile());
        File testList = new File(videosFolder, "list.html");
        Assert.assertTrue(testList.exists());
        Assert.assertTrue(testList.isFile());
        File cssFolder = new File(videosFolder, "css");
        Assert.assertTrue(cssFolder.exists());
        Assert.assertTrue(cssFolder.isDirectory());
        File jsFolder = new File(videosFolder, "js");
        Assert.assertTrue(jsFolder.exists());
        Assert.assertTrue(jsFolder.isDirectory());
    } finally {
        Dashboard.restoreCommonProxyUtilities();
    }
}
Also used : TestInformation(de.zalando.ep.zalenium.dashboard.TestInformation) ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonObject(com.google.gson.JsonObject) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) File(java.io.File) Test(org.junit.Test)

Example 9 with WebDriverRequest

use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.

the class TestUtils method getMockedWebDriverRequestStartSession.

public static WebDriverRequest getMockedWebDriverRequestStartSession(String browser, Platform platform) {
    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.START_SESSION);
    JsonObject jsonObject = new JsonObject();
    JsonObject desiredCapabilities = new JsonObject();
    desiredCapabilities.addProperty(CapabilityType.BROWSER_NAME, browser);
    desiredCapabilities.addProperty(CapabilityType.PLATFORM_NAME, platform.name());
    jsonObject.add("desiredCapabilities", desiredCapabilities);
    when(request.getBody()).thenReturn(jsonObject.toString());
    Enumeration<String> strings = Collections.emptyEnumeration();
    when(request.getHeaderNames()).thenReturn(strings);
    return request;
}
Also used : JsonObject(com.google.gson.JsonObject) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest)

Example 10 with WebDriverRequest

use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.

the class CloudTestingRemoteProxy method afterCommand.

@Override
public void afterCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) {
    if (request instanceof WebDriverRequest && "DELETE".equalsIgnoreCase(request.getMethod())) {
        WebDriverRequest seleniumRequest = (WebDriverRequest) request;
        if (seleniumRequest.getRequestType().equals(RequestType.STOP_SESSION)) {
            long executionTime = (System.currentTimeMillis() - session.getSlot().getLastSessionStart()) / 1000;
            getGa().testEvent(getProxyClassName(), session.getRequestedCapabilities().toString(), executionTime);
            addTestToDashboard(session.getExternalKey().getKey(), true);
        }
    }
    super.afterCommand(session, request, response);
}
Also used : WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest)

Aggregations

WebDriverRequest (org.openqa.grid.web.servlet.handler.WebDriverRequest)22 HttpServletResponse (javax.servlet.http.HttpServletResponse)17 Test (org.junit.Test)17 TestSession (org.openqa.grid.internal.TestSession)17 HashMap (java.util.HashMap)11 ExternalSessionKey (org.openqa.grid.internal.ExternalSessionKey)11 JsonObject (com.google.gson.JsonObject)10 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 JsonElement (com.google.gson.JsonElement)3 Mockito.anyString (org.mockito.Mockito.anyString)3 JsonParser (com.google.gson.JsonParser)2 ObjectName (javax.management.ObjectName)2 RegistrationRequest (org.openqa.grid.common.RegistrationRequest)2 JMXHelper (org.openqa.selenium.remote.server.jmx.JMXHelper)2 GoogleAnalyticsApi (de.zalando.ep.zalenium.util.GoogleAnalyticsApi)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1