Skip to content

Instantly share code, notes, and snippets.

Avatar
🤖

Elias Nogueira eliasnogueira

🤖
View GitHub Profile
@eliasnogueira
eliasnogueira / DecodeQRCode.java
Created Feb 11, 2021
Decode an image based either on a full path or base64 content
View DecodeQRCode.java
private static String decodeQRCode(Object qrCodeImage) {
Result result = null;
try {
BufferedImage bufferedImage;
// if not (probably it is a URL
if (((String) qrCodeImage).contains("http")) {
bufferedImage = ImageIO.read((new URL((String)qrCodeImage)));
@eliasnogueira
eliasnogueira / ReadSrcAttribute.java
Created Feb 11, 2021
Reads the image src attribute and decode it using Zxing
View ReadSrcAttribute.java
@Test
void readQRCodeFromURL() {
String qrCodeFile = driver.findElement(By.id("qr")).getAttribute("src");
// get the qr code content and assert the result
String qrCodeResult = decodeQRCode(qrCodeFile);
assertThat(qrCodeResult).isEqualTo("c72a0de5-eba3-4bf0-bde2-fc709e71df29");
}
@eliasnogueira
eliasnogueira / GenerateImage.java
Created Feb 11, 2021
Generates an image based on a screenshot and Mobile element
View GenerateImage.java
private BufferedImage generateImage(MobileElement element, File screenshot) {
BufferedImage qrCodeImage = null;
try {
BufferedImage fullImage = ImageIO.read(screenshot);
Point imageLocation = element.getLocation();
int qrCodeImageWidth = element.getSize().getWidth();
int qrCodeImageHeight = element.getSize().getHeight();
@eliasnogueira
eliasnogueira / ExampleTest.java
Last active Dec 29, 2020
Usage example of Allure Environment Writer
View ExampleTest.java
import com.google.common.collect.ImmutableMap;
import static com.github.automatedowl.tools.AllureEnvironmentWriter.allureEnvironmentWriter;
public class ExampleTest {
@BeforeSuite
void setAllureEnvironment() {
allureEnvironmentWriter(
ImmutableMap.<String, String>builder()
.put("Browser", "Chrome")
@eliasnogueira
eliasnogueira / OwnerSingletonUsageExample.java
Last active Dec 24, 2020
Using the provided singleton approach in Onwer
View OwnerSingletonUsageExample.java
public class OwnerSingletonUsageExample {
public void example() {
GeneralConfig generalConfig = ConfigCache.getOrCreate(GeneralConfig.class);
// getting values ignored
}
}
@eliasnogueira
eliasnogueira / GeneralConfig.java
Created Dec 24, 2020
Owner example with the system properties lookup
View GeneralConfig.java
@Config.LoadPolicy(Config.LoadType.MERGE)
@Config.Sources({
"system:properties",
"classpath:general.properties",
"classpath:grid.properties"
})
public interface GeneralConfig extends Config {
}
@eliasnogueira
eliasnogueira / GeneralConfigMerge.java
Created Dec 21, 2020
Example of properties merge in the same model using Owner
View GeneralConfigMerge.java
import org.aeonbits.owner.Config;
@Config.LoadPolicy(Config.LoadType.MERGE)
@Config.Sources({
"classpath:general.properties",
"classpath:grid.properties"
})
public interface GeneralConfig extends Config {
String target();
@eliasnogueira
eliasnogueira / grid.properties
Created Dec 21, 2020
Properties file example
View grid.properties
grid.url = localhost
grid.port = 4444
@eliasnogueira
eliasnogueira / OwnerUsageExample.java
Created Dec 20, 2020
Using Owner to read the properties
View OwnerUsageExample.java
public class OwnerUsageExample {
public void example() {
GeneralConfig generalConfig = ConfigFactory.create(GeneralConfig.class);
String target = generalConfig.target();
String url = generalConfig.url();
int timeout = generalConfig.timeout();
Boolean headlessMode = generalConfig.headless();
}
@eliasnogueira
eliasnogueira / GeneralConfig.java
Last active Dec 20, 2020
Model object to read properties file using Owner
View GeneralConfig.java
import org.aeonbits.owner.Config;
@Config.Sources({"classpath:general.properties"})
public interface GeneralConfig extends Config {
String target();
@Config.Key("url.base")
String url();