Search in sources :

Example 11 with Environment

use of de.zalando.ep.zalenium.util.Environment in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxyTest method fallbackToDefaultAmountOfValuesWhenVariablesAreNotSet.

/*
        Tests checking the environment variables setup to have a given number of containers on startup
     */
@Test
public void fallbackToDefaultAmountOfValuesWhenVariablesAreNotSet() {
    // Mock the environment class that serves as proxy to retrieve env variables
    Environment environment = mock(Environment.class, withSettings().useConstructor());
    when(environment.getEnvVariable(any(String.class))).thenReturn(null);
    when(environment.getIntEnvVariable(any(String.class), any(Integer.class))).thenCallRealMethod();
    when(environment.getStringEnvVariable(any(String.class), any(String.class))).thenCallRealMethod();
    DockerSeleniumStarterRemoteProxy.setEnv(environment);
    registry.add(spyProxy);
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_AMOUNT_DESIRED_CONTAINERS, DockerSeleniumStarterRemoteProxy.getDesiredContainersOnStartup());
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_AMOUNT_DOCKER_SELENIUM_CONTAINERS_RUNNING, DockerSeleniumStarterRemoteProxy.getMaxDockerSeleniumContainers());
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_SCREEN_SIZE.getHeight(), DockerSeleniumStarterRemoteProxy.getConfiguredScreenSize().getHeight());
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_SCREEN_SIZE.getWidth(), DockerSeleniumStarterRemoteProxy.getConfiguredScreenSize().getWidth());
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_TZ.getID(), DockerSeleniumStarterRemoteProxy.getConfiguredTimeZone().getID());
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_SELENIUM_NODE_PARAMS, DockerSeleniumStarterRemoteProxy.getSeleniumNodeParameters());
}
Also used : Environment(de.zalando.ep.zalenium.util.Environment) Test(org.junit.Test)

Example 12 with Environment

use of de.zalando.ep.zalenium.util.Environment in project zalenium by zalando.

the class KubernetesContainerClient method createContainer.

@Override
public ContainerCreationStatus createContainer(String zaleniumContainerName, String image, Map<String, String> envVars, String nodePort) {
    String containerIdPrefix = String.format("%s-%s-", zaleniumAppName, nodePort);
    // Convert the environment variables into the Kubernetes format.
    List<EnvVar> flattenedEnvVars = envVars.entrySet().stream().map(e -> new EnvVar(e.getKey(), e.getValue(), null)).collect(Collectors.toList());
    Map<String, String> podSelector = new HashMap<>();
    PodConfiguration config = new PodConfiguration();
    config.setNodePort(nodePort);
    config.setClient(client);
    config.setContainerIdPrefix(containerIdPrefix);
    config.setImage(image);
    config.setEnvVars(flattenedEnvVars);
    Map<String, String> labels = new HashMap<>();
    labels.putAll(createdByZaleniumMap);
    labels.putAll(appLabelMap);
    labels.putAll(podSelector);
    config.setLabels(labels);
    config.setMountedSharedFoldersMap(mountedSharedFoldersMap);
    config.setHostAliases(hostAliases);
    config.setNodeSelector(nodeSelector);
    config.setPodLimits(seleniumPodLimits);
    config.setPodRequests(seleniumPodRequests);
    DoneablePod doneablePod = createDoneablePod.apply(config);
    // Create the container
    Pod createdPod = doneablePod.done();
    String containerName = createdPod.getMetadata() == null ? containerIdPrefix : createdPod.getMetadata().getName();
    return new ContainerCreationStatus(true, containerName, nodePort);
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Environment(de.zalando.ep.zalenium.util.Environment) URL(java.net.URL) ContainerClientRegistration(de.zalando.ep.zalenium.container.ContainerClientRegistration) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) HostAlias(io.fabric8.kubernetes.api.model.HostAlias) Map(java.util.Map) Response(okhttp3.Response) ExecListener(io.fabric8.kubernetes.client.dsl.ExecListener) ContainerClient(de.zalando.ep.zalenium.container.ContainerClient) Volume(io.fabric8.kubernetes.api.model.Volume) Logger(org.slf4j.Logger) Pod(io.fabric8.kubernetes.api.model.Pod) ExecWatch(io.fabric8.kubernetes.client.dsl.ExecWatch) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) PodList(io.fabric8.kubernetes.api.model.PodList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Optional(java.util.Optional) ContainerCreationStatus(de.zalando.ep.zalenium.container.ContainerCreationStatus) InputStream(java.io.InputStream) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) Pod(io.fabric8.kubernetes.api.model.Pod) HashMap(java.util.HashMap) ContainerCreationStatus(de.zalando.ep.zalenium.container.ContainerCreationStatus) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) EnvVar(io.fabric8.kubernetes.api.model.EnvVar)

Example 13 with Environment

use of de.zalando.ep.zalenium.util.Environment in project zalenium by zalando.

the class BrowserStackRemoteProxyTest 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 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 BrowserStack 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.setExternalKey(new ExternalSessionKey("BrowserStack Test"));
    testSession.forward(request, response, true);
    Environment env = new Environment();
    // The body should now have the BrowserStack variables
    String expectedBody = String.format("{\"desiredCapabilities\":{\"browserName\":\"internet explorer\",\"platformName\":" + "\"WIN8\",\"browserstack.user\":\"%s\",\"browserstack.key\":\"%s\"}}", env.getStringEnvVariable("BROWSER_STACK_USER", ""), env.getStringEnvVariable("BROWSER_STACK_KEY", ""));
    verify(request).setBody(expectedBody);
}
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) Environment(de.zalando.ep.zalenium.util.Environment) JsonObject(com.google.gson.JsonObject) Mockito.anyString(org.mockito.Mockito.anyString) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Aggregations

Environment (de.zalando.ep.zalenium.util.Environment)13 Test (org.junit.Test)11 HashMap (java.util.HashMap)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 ObjectName (javax.management.ObjectName)5 TestSession (org.openqa.grid.internal.TestSession)5 WebDriverRequest (org.openqa.grid.web.servlet.handler.WebDriverRequest)5 JMXHelper (org.openqa.selenium.remote.server.jmx.JMXHelper)4 JsonObject (com.google.gson.JsonObject)3 CommonProxyUtilities (de.zalando.ep.zalenium.util.CommonProxyUtilities)3 ServletOutputStream (javax.servlet.ServletOutputStream)3 ExternalSessionKey (org.openqa.grid.internal.ExternalSessionKey)3 JsonElement (com.google.gson.JsonElement)2 Mockito.anyString (org.mockito.Mockito.anyString)2 RegistrationRequest (org.openqa.grid.common.RegistrationRequest)2 ContainerClient (de.zalando.ep.zalenium.container.ContainerClient)1 ContainerClientRegistration (de.zalando.ep.zalenium.container.ContainerClientRegistration)1 ContainerCreationStatus (de.zalando.ep.zalenium.container.ContainerCreationStatus)1 TestInformation (de.zalando.ep.zalenium.dashboard.TestInformation)1 GoogleAnalyticsApi (de.zalando.ep.zalenium.util.GoogleAnalyticsApi)1