Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
[BUA-925] Adding default screenResolution for requests missing it.
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Mar 21, 2017
1 parent 9eabde4 commit 423dad9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void copyVideos(final String containerId) throws IOException, DockerException, I
IOUtils.copy(tarStream, outputStream);
outputStream.close();
Dashboard.updateDashboard(testInformation);
LOGGER.log(Level.INFO, "{0} Video files copies to: {1}", new Object[]{getId(),
LOGGER.log(Level.INFO, "{0} Video files copied to: {1}", new Object[]{getId(),
testInformation.getVideoFolderPath()});
}
} catch (Exception e) {
Expand Down Expand Up @@ -409,6 +409,8 @@ public void run() {
"thread, stopping thread execution.", e);
Thread.currentThread().interrupt();
dockerSeleniumRemoteProxy.ga.trackException(e);
dockerSeleniumRemoteProxy.stopPolling();
dockerSeleniumRemoteProxy.startPolling();
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public class DockerSeleniumStarterRemoteProxy extends DefaultRemoteProxy impleme
private static int firefoxContainersOnStartup;
private static int maxDockerSeleniumContainers;
private static String timeZone;
private static int configuredScreenWidth;
private static int screenWidth;
private static int configuredScreenHeight;
private static int screenHeight;
private static String containerName;
private List<Integer> allocatedPorts = new ArrayList<>();
Expand Down Expand Up @@ -110,9 +112,11 @@ private static void readConfigurationFromEnvVariables() {

int sWidth = env.getIntEnvVariable(ZALENIUM_SCREEN_WIDTH, DEFAULT_SCREEN_WIDTH);
setScreenWidth(sWidth);
setConfiguredScreenWidth(sWidth);

int sHeight = env.getIntEnvVariable(ZALENIUM_SCREEN_HEIGHT, DEFAULT_SCREEN_HEIGHT);
setScreenHeight(sHeight);
setConfiguredScreenHeight(sHeight);

String tz = env.getStringEnvVariable(ZALENIUM_TZ, DEFAULT_TZ);
setTimeZone(tz);
Expand Down Expand Up @@ -263,6 +267,22 @@ protected static void setScreenHeight(int screenHeight) {
DockerSeleniumStarterRemoteProxy.screenHeight = screenHeight <= 0 ? DEFAULT_SCREEN_HEIGHT : screenHeight;
}

public static int getConfiguredScreenWidth() {
return configuredScreenWidth;
}

public static void setConfiguredScreenWidth(int configuredScreenWidth) {
DockerSeleniumStarterRemoteProxy.configuredScreenWidth = configuredScreenWidth;
}

public static int getConfiguredScreenHeight() {
return configuredScreenHeight;
}

public static void setConfiguredScreenHeight(int configuredScreenHeight) {
DockerSeleniumStarterRemoteProxy.configuredScreenHeight = configuredScreenHeight;
}

@VisibleForTesting
protected static void setEnv(final Environment env) {
DockerSeleniumStarterRemoteProxy.env = env;
Expand Down Expand Up @@ -323,13 +343,14 @@ public TestSession getNewSession(Map<String, Object> requestedCapability) {
String waitingForNode = String.format("waitingFor_%s_Node", browserName.toUpperCase());
if (!requestedCapability.containsKey(waitingForNode)) {
LOGGER.log(Level.INFO, LOGGING_PREFIX + "Starting new node for {0}.", requestedCapability);
startDockerSeleniumContainer(browserName);
requestedCapability.put(waitingForNode, 1);
if (startDockerSeleniumContainer(browserName)) {
requestedCapability.put(waitingForNode, 1);
}
} else {
int attempts = (int) requestedCapability.get(waitingForNode);
attempts++;
if (attempts >= 20) {
LOGGER.log(Level.INFO, LOGGING_PREFIX + "Request has waited 20 attempts for a node, something " +
if (attempts >= 10) {
LOGGER.log(Level.INFO, LOGGING_PREFIX + "Request has waited 10 attempts for a node, something " +
"went wrong with the previous attempts, creating a new node for {0}.", requestedCapability);
startDockerSeleniumContainer(browserName);
requestedCapability.put(waitingForNode, 1);
Expand Down Expand Up @@ -479,9 +500,6 @@ private void createStartupContainers() {
This method will search for a screenResolution capability to be passed when creating a docker-selenium node.
*/
private void configureScreenResolutionFromCapabilities(Map<String, Object> requestedCapability) {
int configuredScreenWidth = env.getIntEnvVariable(ZALENIUM_SCREEN_WIDTH, DEFAULT_SCREEN_WIDTH);
int configuredScreenHeight = env.getIntEnvVariable(ZALENIUM_SCREEN_HEIGHT, DEFAULT_SCREEN_HEIGHT);

boolean wasConfiguredScreenWidthAndHeightChanged = false;
String[] screenResolutionNames = {"screenResolution", "resolution", "screen-resolution"};
for (String screenResolutionName : screenResolutionNames) {
Expand All @@ -495,8 +513,8 @@ private void configureScreenResolutionFromCapabilities(Map<String, Object> reque
setScreenWidth(screenWidth);
wasConfiguredScreenWidthAndHeightChanged = true;
} else {
setScreenWidth(configuredScreenWidth);
setScreenHeight(configuredScreenHeight);
setScreenWidth(getConfiguredScreenWidth());
setScreenHeight(getConfiguredScreenHeight());
LOGGER.log(Level.FINE, "One of the values provided for screenResolution is negative, " +
"defaults will be used. Passed value -> " + screenResolution);
}
Expand All @@ -513,8 +531,8 @@ private void configureScreenResolutionFromCapabilities(Map<String, Object> reque
// Also in the capabilities, to avoid the situation where a request grabs the node from other request
// just because the platform, version, and browser match.
if (!wasConfiguredScreenWidthAndHeightChanged) {
setScreenWidth(configuredScreenWidth);
setScreenHeight(configuredScreenHeight);
setScreenWidth(getConfiguredScreenWidth());
setScreenHeight(getConfiguredScreenHeight());
String screenResolution = String.format("%sx%s", getScreenWidth(), getScreenHeight());
requestedCapability.put("screenResolution", screenResolution);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.zalando.tip.zalenium.util;

import de.zalando.tip.zalenium.proxy.DockerSeleniumRemoteProxy;
import de.zalando.tip.zalenium.proxy.DockerSeleniumStarterRemoteProxy;
import org.openqa.grid.internal.utils.DefaultCapabilityMatcher;
import org.openqa.grid.selenium.proxy.DefaultRemoteProxy;
import org.openqa.selenium.remote.CapabilityType;
Expand All @@ -13,8 +14,7 @@
* The purpose of this class is to let docker-selenium process requests where a capability "version=latest" is present
*/
public class DockerSeleniumCapabilityMatcher extends DefaultCapabilityMatcher {
private static final Logger logger = Logger.getLogger(DockerSeleniumCapabilityMatcher.class.getName());

private final Logger logger = Logger.getLogger(DockerSeleniumCapabilityMatcher.class.getName());
private DefaultRemoteProxy proxy;

public DockerSeleniumCapabilityMatcher(DefaultRemoteProxy defaultRemoteProxy) {
Expand Down Expand Up @@ -46,15 +46,24 @@ public boolean matches(Map<String, Object> nodeCapability, Map<String, Object> r
}

boolean screenResolutionCapabilityMatches = true;
boolean containsScreenResolutionCapability = false;
// This validation is only done for docker-selenium nodes
if (proxy instanceof DockerSeleniumRemoteProxy) {
String[] screenResolutionNames = {"screenResolution", "resolution", "screen-resolution"};
for (String screenResolutionName : screenResolutionNames) {
if (requestedCapability.containsKey(screenResolutionName)) {
screenResolutionCapabilityMatches = nodeCapability.containsKey(screenResolutionName) &&
requestedCapability.get(screenResolutionName).equals(nodeCapability.get(screenResolutionName));
containsScreenResolutionCapability = true;
}
}
// This is done to avoid having the test run on a node with a configured screen resolution different from
// the global configured one. But not putting it to tests that should go to a cloud provider.
if (!containsScreenResolutionCapability && super.matches(nodeCapability, requestedCapability)) {
String screenResolution = String.format("%sx%s", DockerSeleniumStarterRemoteProxy.getConfiguredScreenWidth(),
DockerSeleniumStarterRemoteProxy.getConfiguredScreenHeight());
requestedCapability.put("screenResolution", screenResolution);
}
}

// If the browser version has been matched, then implicitly the matcher from the super class has also been
Expand Down

0 comments on commit 423dad9

Please sign in to comment.