All Downloads are FREE. Search and download functionalities are using the official Maven repository.

qa.justtestlah.utils.ImageUtils Maven / Gradle / Ivy

Go to download

JustTestLah! is a JAVA test framework targeting projects that support multiple platforms, in particular Web, Android and iOS. It follows a BDD approach and allows testing against all platforms using the same feature files. JustTestLah's main aim is to make the configuration and the actual test code as easy as possible.

There is a newer version: 1.9-RC4
Show newest version
package qa.justtestlah.utils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Basic utility methods for image processing
 *
 * 

This class is extended in justtestlah-visual {@linkplain} qa.justtestlah.visual.ImageUtils}. */ @Component public class ImageUtils { private static final Logger LOG = LoggerFactory.getLogger(ImageUtils.class); protected static final String IMAGE_FOLDER = "images"; /** * @param imageName the name of a test image (as used in the locator yaml files) * @return a Base64 encoded {@link String} representing the specified image */ public static String getImageAsBase64String(String imageName) { return encodeBase64(getFullPath(imageName)); } /** * @param imageName the name of a test image (as used in the locator yaml files) * @return the fully-qualified path to the specified image */ public static String getFullPath(String imageName) { return ImageUtils.class.getClassLoader().getResource(IMAGE_FOLDER + "/" + imageName).getFile(); } /** * @param fullPath fully-qualified path to an image file * @return a Base64 encoded {@link String} representing the specified image */ public static String encodeBase64(String fullPath) { try { return Base64.getEncoder().encodeToString(Files.readAllBytes(Paths.get(fullPath))); } catch (IOException exception) { LOG.error(String.format("Error reading image %s", fullPath), exception); return null; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy