Search in sources :

Example 11 with TestSession

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

the class DockerSeleniumStarterRemoteProxyTest method noContainerIsStartedWhenCapabilitiesAreNotSupported.

@Test
public void noContainerIsStartedWhenCapabilitiesAreNotSupported() {
    // Non supported desired capability for the test session
    Map<String, Object> nonSupportedCapability = new HashMap<>();
    nonSupportedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.SAFARI);
    nonSupportedCapability.put(CapabilityType.PLATFORM_NAME, Platform.MAC);
    TestSession testSession = spyProxy.getNewSession(nonSupportedCapability);
    Assert.assertNull(testSession);
    verify(spyProxy, never()).startDockerSeleniumContainer(timeZone, screenSize);
}
Also used : HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) Test(org.junit.Test)

Example 12 with TestSession

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

the class DockerSeleniumStarterRemoteProxyTest method noContainerIsStartedForAlreadyProcessedRequest.

@Test
public void noContainerIsStartedForAlreadyProcessedRequest() {
    Map<String, Object> requestedCapability = new HashMap<>();
    requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
    requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.LINUX);
    ProcessedCapabilities processedCapabilities = new ProcessedCapabilities(requestedCapability, System.identityHashCode(requestedCapability));
    DockerSeleniumStarterRemoteProxy.processedCapabilitiesList.add(processedCapabilities);
    TestSession testSession = spyProxy.getNewSession(requestedCapability);
    Assert.assertNull(testSession);
    verify(spyProxy, times(0)).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 13 with TestSession

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

the class DockerSeleniumStarterRemoteProxyTest method noContainerIsStartedWhenPlatformIsNotSupported.

@Test
public void noContainerIsStartedWhenPlatformIsNotSupported() {
    // Non supported desired capability for the test session
    Map<String, Object> nonSupportedCapability = new HashMap<>();
    nonSupportedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
    nonSupportedCapability.put(CapabilityType.PLATFORM_NAME, Platform.WINDOWS);
    TestSession testSession = spyProxy.getNewSession(nonSupportedCapability);
    Assert.assertNull(testSession);
    verify(spyProxy, never()).startDockerSeleniumContainer(timeZone, screenSize);
}
Also used : HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) Test(org.junit.Test)

Example 14 with TestSession

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

the class DockerSeleniumStarterRemoteProxyTest method containerIsStartedWhenResolutionIsProvided.

@Test
public void containerIsStartedWhenResolutionIsProvided() {
    // Supported desired capability for the test session
    Dimension customScreenSize = new Dimension(1300, 900);
    Map<String, Object> supportedCapability = new HashMap<>();
    supportedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
    supportedCapability.put(CapabilityType.PLATFORM_NAME, Platform.ANY);
    String screenResolution = String.format("%sx%s", customScreenSize.getWidth(), customScreenSize.getHeight());
    supportedCapability.put("resolution", screenResolution);
    TestSession testSession = spyProxy.getNewSession(supportedCapability);
    Assert.assertNull(testSession);
    verify(spyProxy, timeout(1000).times(1)).startDockerSeleniumContainer(timeZone, customScreenSize);
}
Also used : HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) Dimension(org.openqa.selenium.Dimension) Test(org.junit.Test)

Example 15 with TestSession

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

the class SauceLabsRemoteProxyTest method testEventIsInvoked.

@Test
public void testEventIsInvoked() throws IOException {
    try {
        // 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);
        Assert.assertNotNull(testSession);
        // We release the sessions and invoke the afterCommand with a mocked object
        Environment env = mock(Environment.class);
        when(env.getBooleanEnvVariable("ZALENIUM_SEND_ANONYMOUS_USAGE_INFO", false)).thenReturn(true);
        when(env.getStringEnvVariable("ZALENIUM_GA_API_VERSION", "")).thenReturn("1");
        when(env.getStringEnvVariable("ZALENIUM_GA_TRACKING_ID", "")).thenReturn("UA-88441352");
        when(env.getStringEnvVariable("ZALENIUM_GA_ENDPOINT", "")).thenReturn("https://www.google-analytics.com/collect");
        when(env.getStringEnvVariable("ZALENIUM_GA_ANONYMOUS_CLIENT_ID", "")).thenReturn("RANDOM_STRING");
        HttpClient client = mock(HttpClient.class);
        HttpResponse httpResponse = mock(HttpResponse.class);
        when(client.execute(any(HttpPost.class))).thenReturn(httpResponse);
        GoogleAnalyticsApi ga = new GoogleAnalyticsApi();
        GoogleAnalyticsApi gaSpy = spy(ga);
        gaSpy.setEnv(env);
        gaSpy.setHttpClient(client);
        SauceLabsRemoteProxy.setGa(gaSpy);
        WebDriverRequest webDriverRequest = mock(WebDriverRequest.class);
        HttpServletResponse response = mock(HttpServletResponse.class);
        when(webDriverRequest.getMethod()).thenReturn("DELETE");
        when(webDriverRequest.getRequestType()).thenReturn(RequestType.STOP_SESSION);
        testSession.getSlot().doFinishRelease();
        testSession.setExternalKey(new ExternalSessionKey("testKey"));
        sauceLabsProxy.afterCommand(testSession, webDriverRequest, response);
        verify(gaSpy, times(1)).testEvent(anyString(), anyString(), anyLong());
    } finally {
        SauceLabsRemoteProxy.restoreGa();
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) GoogleAnalyticsApi(de.zalando.ep.zalenium.util.GoogleAnalyticsApi) ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) HashMap(java.util.HashMap) HttpResponse(org.apache.http.HttpResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) TestSession(org.openqa.grid.internal.TestSession) HttpClient(org.apache.http.client.HttpClient) Environment(de.zalando.ep.zalenium.util.Environment) 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