Is there way to inspect an image on native app and get its base64 code

Im trying to inspect an image of some app on play store, but so far i reach nothing, is there way to extract the base64 code or the image itself, then i can convert it to base64 and use it later for testing purposes, something like in picture below

@Aleksei have you experienced something like that

1 Like

so how i can add matching percentage
lets say if i have

wait.until(ExpectedConditions.visibilityof(ImageBase64))

how i can add , or where to add this

        driver.setSetting(Setting.IMAGE_MATCH_THRESHOLD, 0.3);

just before searching for image. i suggest you use some default value and restore it if it changed.
e.g.

  • set some default value = 0.3 (e.g. somewhere in beginning of test)
  • search your image with wait
  • you need change value -> set it to needed -> search -> restore default
1 Like

hi aleksei,

i tried the method you have shared in the link above, but keep getting nullpointer however i have thrown all required exception, i have highlighted the failed like with SOLID font

private static final String appName = System.getenv("APP_NAME");
private static final String imagePath = "target/"+appName+".png";

public String convertedImageBase64(String imgPath) throws IOException, URISyntaxException {
    URL refImgUrl = getClass().getClassLoader().getResource(imgPath);
    **File refImgFile = Paths.get(refImgUrl.toURI()).toFile();**
    return Base64.getEncoder().encodeToString(Files.readAllBytes(refImgFile.toPath()));
} 


public  void installTestingApp () throws URISyntaxException, IOException {
    if (appPackage.equals("com.sarajevo.food.dictionary")) {
        wait.until(ExpectedConditions.visibilityOf(searchFieldInput));
        wait.until(ExpectedConditions.elementToBeClickable(searchFieldInput));
        searchFieldInput.click();
        wait.until(ExpectedConditions.visibilityOf(searchBox));
        searchBox.sendKeys(appName);
        driver.hideKeyboard();
        driver.pressKey(new KeyEvent(AndroidKey.ENTER));
        wait.until(ExpectedConditions.visibilityOf(test.get(0)));
        takeElementSreenshot();
        try {
            wait.until(ExpectedConditions.visibilityOf(driver.findElementByImage**(convertedImageBase64(imagePath)**)));
            touch.longPress(LongPressOptions.longPressOptions()
                    .withElement(ElementOption.element(**driver.findElementByImage(convertedImageBase64(imagePath)**))).withDuration(Duration.ofSeconds(4)))
                    .release()
                    .perform();
            wait.until(ExpectedConditions.visibilityOf(installButton));
            installButton.click();
            wait = new WebDriverWait(driver, 300);
            wait.until(ExpectedConditions.visibilityOf(SFDInstalled));
        }finally {
            driver.quit();
        }
    }
}

surround it with try-catch. if it fails = there is reason e.g. wrong path…

Could you send the editing

I have tried alot of different ways, also i have provided the link directly and still getting same error

use example better -> https://grokonez.com/java/java-advanced/java-8-encode-decode-an-image-base64

Great thanks for help

i have used the method below

private File getImageFile(String imgPath) {
return new File(imgPath);
}

private String getReferenceImageB64(String imgPath) throws IOException {
    Path refImgPath = getImageFile(imgPath).toPath();
   return Base64.getEncoder().encodeToString(Files.readAllBytes(refImgPath));
}

        wait.until(ExpectedConditions.visibilityOf(driver.findElementByImage(getReferenceImageB64(imagePath))));