Search in sources :

Example 41 with TestSession

use of org.openqa.grid.internal.TestSession in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxyTest method containerIsStartedWhenNegativeResolutionIsProvidedUsingDefaults.

@Test
public void containerIsStartedWhenNegativeResolutionIsProvidedUsingDefaults() {
    // Supported desired capability for the test session
    Map<String, Object> supportedCapability = new HashMap<>();
    supportedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
    supportedCapability.put(CapabilityType.PLATFORM_NAME, Platform.ANY);
    supportedCapability.put("resolution", "-1300x800");
    TestSession testSession = spyProxy.getNewSession(supportedCapability);
    Assert.assertNull(testSession);
    verify(spyProxy, timeout(1000).times(1)).startDockerSeleniumContainer(timeZone, screenSize);
}
Also used : HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) Test(org.junit.Test)

Example 42 with TestSession

use of org.openqa.grid.internal.TestSession in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxyTest method containerIsStartedWhenAnInvalidResolutionIsProvidedUsingDefaults.

@Test
public void containerIsStartedWhenAnInvalidResolutionIsProvidedUsingDefaults() {
    // Supported desired capability for the test session
    Map<String, Object> supportedCapability = new HashMap<>();
    supportedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
    supportedCapability.put(CapabilityType.PLATFORM_NAME, Platform.ANY);
    supportedCapability.put("screenResolution", "notAValidScreenResolution");
    TestSession testSession = spyProxy.getNewSession(supportedCapability);
    Assert.assertNull(testSession);
    verify(spyProxy, timeout(1000).times(1)).startDockerSeleniumContainer(timeZone, screenSize);
}
Also used : HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) Test(org.junit.Test)

Example 43 with TestSession

use of org.openqa.grid.internal.TestSession in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxyTest method containerIsStartedForRequestProcessedMoreThan30Times.

@Test
public void containerIsStartedForRequestProcessedMoreThan30Times() {
    Map<String, Object> requestedCapability = new HashMap<>();
    requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
    requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.LINUX);
    ProcessedCapabilities processedCapabilities = new ProcessedCapabilities(requestedCapability, System.identityHashCode(requestedCapability));
    processedCapabilities.setProcessedTimes(31);
    DockerSeleniumStarterRemoteProxy.processedCapabilitiesList.add(processedCapabilities);
    TestSession testSession = spyProxy.getNewSession(requestedCapability);
    Assert.assertNull(testSession);
    verify(spyProxy, timeout(1000).atLeastOnce()).startDockerSeleniumContainer(timeZone, screenSize);
}
Also used : ProcessedCapabilities(de.zalando.ep.zalenium.util.ProcessedCapabilities) HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) Test(org.junit.Test)

Example 44 with TestSession

use of org.openqa.grid.internal.TestSession in project zalenium by zalando.

the class SauceLabsRemoteProxyTest method testInformationIsRetrievedWhenStoppingSession.

@Test
public void testInformationIsRetrievedWhenStoppingSession() throws IOException {
    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 sauce labs node
        SauceLabsRemoteProxy sauceLabsSpyProxy = spy(sauceLabsProxy);
        JsonElement informationSample = TestUtils.getTestInformationSample("saucelabs_testinformation.json");
        CommonProxyUtilities commonProxyUtilities = mock(CommonProxyUtilities.class);
        when(commonProxyUtilities.readJSONFromUrl(anyString(), anyString(), anyString())).thenReturn(informationSample);
        doCallRealMethod().when(commonProxyUtilities).convertFlvFileToMP4(any(TestInformation.class));
        SauceLabsRemoteProxy.setCommonProxyUtilities(commonProxyUtilities);
        TestSession testSession = sauceLabsSpyProxy.getNewSession(requestedCapability);
        Assert.assertNotNull(testSession);
        String mockSeleniumSessionId = "72e4f8ecf04440fe965faf657864ed52";
        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();
        sauceLabsSpyProxy.afterCommand(testSession, request, response);
        verify(sauceLabsSpyProxy, timeout(1000 * 5)).getTestInformation(mockSeleniumSessionId);
        TestInformation testInformation = sauceLabsSpyProxy.getTestInformation(mockSeleniumSessionId);
        Assert.assertEquals(mockSeleniumSessionId, testInformation.getTestName());
        Assert.assertThat(testInformation.getFileName(), CoreMatchers.containsString("saucelabs_72e4f8ecf04440fe965faf657864ed52_googlechrome_Windows_2008"));
        Assert.assertEquals("googlechrome 56, Windows 2008", testInformation.getBrowserAndPlatform());
        Assert.assertThat(testInformation.getVideoUrl(), CoreMatchers.containsString("jobs/72e4f8ecf04440fe965faf657864ed52/assets/video.flv"));
    } finally {
        SauceLabsRemoteProxy.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) JsonElement(com.google.gson.JsonElement) TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Example 45 with TestSession

use of org.openqa.grid.internal.TestSession in project zalenium by zalando.

the class SauceLabsRemoteProxyTest method slotIsReleasedWhenTestIsIdle.

@Test
public void slotIsReleasedWhenTestIsIdle() throws IOException {
    // Supported desired capability for the test session
    Map<String, Object> requestedCapability = new HashMap<>();
    requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.SAFARI);
    requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.MAC);
    SauceLabsRemoteProxy sauceLabsSpyProxy = spy(sauceLabsProxy);
    // Set a short idle time
    sauceLabsSpyProxy.setMaxTestIdleTime(1L);
    // Start poller thread
    sauceLabsSpyProxy.startPolling();
    // Get a test session
    TestSession newSession = sauceLabsSpyProxy.getNewSession(requestedCapability);
    Assert.assertNotNull(newSession);
    newSession.setExternalKey(new ExternalSessionKey("RANDOM_EXTERNAL_KEY"));
    // Start the session
    WebDriverRequest request = TestUtils.getMockedWebDriverRequestStartSession(BrowserType.SAFARI, Platform.MAC);
    HttpServletResponse response = mock(HttpServletResponse.class);
    ServletOutputStream stream = mock(ServletOutputStream.class);
    when(response.getOutputStream()).thenReturn(stream);
    sauceLabsSpyProxy.beforeCommand(newSession, request, response);
    // The terminateIdleSessions() method should be called after a moment
    verify(sauceLabsSpyProxy, timeout(2000)).terminateIdleSessions();
    verify(sauceLabsSpyProxy, timeout(2000)).addTestToDashboard("RANDOM_EXTERNAL_KEY", false);
}
Also used : ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) HashMap(java.util.HashMap) ServletOutputStream(javax.servlet.ServletOutputStream) TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

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