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());
}
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);
}
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);
}
Aggregations