seleniumConsulting.ch.selenium.framework.metadata.MetadataManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of selenium-java-toolkit-base Show documentation
Show all versions of selenium-java-toolkit-base Show documentation
Selenium-Toolkit is a Java based test-toolkit for selenium-testing with testNg.
The goal of the toolkit is, to suport you in different things like 'how to manage testdata in the source', parallelisation, Webdriver-managemet, reporting and a lot more.
package seleniumConsulting.ch.selenium.framework.metadata;
import java.util.HashMap;
import java.util.Map;
import vendors.grid.TestInfo;
/**
* Stores Metadata to the TestMethods like Browser and Version
*/
public class MetadataManager {
/**
* Map> to store Metadata
*/
static Map> metadataMap = new HashMap();
/**
* Get Metadata to a Test by Key {@link TestInfo}
* @param mapKey to get the right store-Map
* @param key to get the Value
* @return Object value of Store returns "" if ther is no value in store
*/
public static Object getMetadata(TestInfo mapKey, String key) {
Map map = getMetadataMap(mapKey);
if(map != null){
return map.get(key);
} else {
return "";
}
}
/**
* Set Metadata to a Test by Key {@link TestInfo}
* @param mapKey to get the right store-Map
* @param key to set the Value
* @param object Value to store
*/
public static void setMetadata(TestInfo mapKey, String key, Object object) {
Map map = getMetadataMap(mapKey);
if(map != null){
map.put(key, object);
}
}
/**
* Del Metadata to Test by Key = {@link TestInfo}
* @param mapKey to remove the right store-Map
*/
public static void delMetadata(TestInfo mapKey) {
metadataMap.remove(getHashOfMethodDescription(mapKey));
}
/**
* Get the store-Map to the {@link TestInfo}
* @param mapKey to get the Map
* @return Map or {@code null} if there is no Map
*/
private static Map getMetadataMap(TestInfo mapKey){
if(mapKey != null){
Map map = metadataMap.get(getHashOfMethodDescription(mapKey));
if(map == null){
metadataMap.put(getHashOfMethodDescription(mapKey), new HashMap<>());
map = metadataMap.get(getHashOfMethodDescription(mapKey));
}
return map;
} else {
return null;
}
}
/**
* Get Hashcode of the Method-Description
* @param mapKey the method
* @return Integer hashcode
*/
private static Integer getHashOfMethodDescription(TestInfo mapKey){
return mapKey.getMetaKey().hashCode();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy