Source:
protected By buildByFromShortFindBy(ExtendedFindBy findByCarina) { if (!"".equals(findByCarina.iosPredicate())) { return MobileBy.iOSNsPredicateString(findByCarina.iosPredicate()); } if (!"".equals(findByCarina.androidUIAutomator())) { return MobileBy.AndroidUIAutomator(findByCarina.androidUIAutomator()); } if (!"".equals(findByCarina.iosClassChain())) { return MobileBy.iOSClassChain(findByCarina.iosClassChain()); } if (!"".equals(findByCarina.accessibilityId())) { return MobileBy.AccessibilityId(findByCarina.accessibilityId()); } if (!"".equals(findByCarina.text())) { return By.xpath(String.format(BY_TEXT_TEMPLATE, findByCarina.text())); } if (!"".equals(findByCarina.image())) { String annotationLocator = BASE_IMAGE_DIR.concat(findByCarina.image()); LOGGER.debug("ExtendedFindBy annotation image locator : " + annotationLocator); if (annotationLocator.contains(SpecialKeywords.FORMAT_ELEMENT_SYMBOL)) { LOGGER.debug("Special char has been detected in the image locator. Call format method on element before interaction."); return MobileBy.image(annotationLocator); } else { Path path = Paths.get(annotationLocator); LOGGER.debug("Path to search the image template : " + path); String base64image = null; try { base64image = new String(Base64.encode(Files.readAllBytes(path))); LOGGER.debug("Base64 image representation has been successfully obtained."); return MobileBy.image(base64image); } catch (IOException e) { throw new RuntimeException("Error while reading image file for ExtendedFindBy annotation : " + annotationLocator, e); } } } return null; }

Target:
protected By buildByFromShortFindBy(ExtendedFindBy findByCarina) { if (!"".equals(findByCarina.iosPredicate())) { return MobileBy.iOSNsPredicateString(findByCarina.iosPredicate()); } if (!"".equals(findByCarina.androidUIAutomator())) { return MobileBy.AndroidUIAutomator(findByCarina.androidUIAutomator()); } if (!"".equals(findByCarina.iosClassChain())) { return MobileBy.iOSClassChain(findByCarina.iosClassChain()); } if (!"".equals(findByCarina.accessibilityId())) { return MobileBy.AccessibilityId(findByCarina.accessibilityId()); } if (!"".equals(findByCarina.text())) { return By.xpath(String.format(BY_TEXT_TEMPLATE, findByCarina.text())); } if (!"".equals(findByCarina.image())) { if (findByCarina.image().contains("%")) { LOGGER.debug("Special char has been detected in the image locator. Call format method on element before interaction."); return MobileBy.image(ClassLoader.getSystemResource("").getPath() + findByCarina.image()); } String annotationLocator; URL fileUrl = ClassLoader.getSystemResource(findByCarina.image()); if (null != fileUrl) { annotationLocator = fileUrl.getPath(); } else { throw new RuntimeException("Error while reading system resource for ExtendedFindBy annotation. Check if image exists in class path: " + ClassLoader.getSystemResource("") + findByCarina.image()); } LOGGER.debug("ExtendedFindBy annotation image locator : " + annotationLocator); Path path = Paths.get(annotationLocator); LOGGER.debug("Path to search image template : " + path); String base64image = null; try { base64image = new String(Base64.encode(Files.readAllBytes(path))); LOGGER.debug("Base64 image representation has been successfully obtained."); return MobileBy.image(base64image); } catch (IOException e) { throw new RuntimeException("Error while reading image file for ExtendedFindBy annotation : " + annotationLocator, e); } } return null; }