Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced CapabilityUtils #142

Merged
merged 6 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import eu.tsystems.mms.tic.testframework.sikuli.SikuliWebDriver;
import eu.tsystems.mms.tic.testframework.transfer.ThrowablePackedResponse;
import eu.tsystems.mms.tic.testframework.useragents.UserAgentConfig;
import eu.tsystems.mms.tic.testframework.utils.DefaultCapabilityUtils;
import eu.tsystems.mms.tic.testframework.utils.FileUtils;
import eu.tsystems.mms.tic.testframework.utils.Timer;
import eu.tsystems.mms.tic.testframework.utils.TimerUtils;
Expand Down Expand Up @@ -417,7 +418,7 @@ private WebDriver startNewWebDriverSession(
throw new SystemException("Browser must be set through SystemProperty 'browser' or in test.properties file! + is: " + browser);
}

Map<String, Object> cleanedCapsMap = new WebDriverCapabilityLogHelper().clean(finalCapabilities);
Map<String, Object> cleanedCapsMap = new DefaultCapabilityUtils().clean(finalCapabilities);
sessionContext.setCapabilities(cleanedCapsMap);

Gson gson = new GsonBuilder().setPrettyPrinting().create();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Testerra
*
* (C) 2021, Eric Kubenka, T-Systems Multimedia Solutions GmbH, Deutsche Telekom AG
* (C) 2021, Mike Reiche, T-Systems Multimedia Solutions GmbH, Deutsche Telekom AG
*
* Deutsche Telekom AG and all other contributors /
* copyright owners license this file to you under the Apache
Expand All @@ -19,7 +19,7 @@
* under the License.
*/

package eu.tsystems.mms.tic.testframework.webdrivermanager;
package eu.tsystems.mms.tic.testframework.utils;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -28,6 +28,8 @@
import java.util.TreeMap;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.apache.commons.lang3.StringUtils;

/**
* This is a simple helper to modify log messages of {@link Capabilities} to short long values or do other opertations
Expand All @@ -37,7 +39,7 @@
*
* @author Eric Kubenka
*/
class WebDriverCapabilityLogHelper {
public class DefaultCapabilityUtils {

/**
* Clean the given {@link Capabilities} and return a {@link Map}
Expand Down Expand Up @@ -87,4 +89,19 @@ private List<String> shortAllStringsInLists(final Object stringListObject) {
((List<String>) stringListObject).forEach(e -> extList.add(e.substring(0, 10) + "..."));
return extList;
}

/**
* Sets a capability value if the existing value doesn't match the same type,
* is an empty string or doesn't exist.
* @param capabilities
* @param capabilityName
* @param capability
* @param <T>
*/
public <T> void putIfAbsent(DesiredCapabilities capabilities, String capabilityName, T capability) {
Object existingCapability = capabilities.getCapability(capabilityName);
if (!capability.getClass().isInstance(existingCapability) || (existingCapability instanceof String && StringUtils.isBlank((String)existingCapability))) {
capabilities.setCapability(capabilityName, capability);
}
}
}