Search code examples
javaandroidautomationandroid-emulatorappium

Appium Mobile Automation : How to check the location of bouncing ball in Animation


I am testing demo apk app provided by appium , in which I am testing Reverse Animation. On clicking "Play" and "Reverse" button , the ball goes up and down. Is it possible to check , if the ball has reached a certain coordinate. The ball has no locator as such

enter image description here

enter image description here


Solution

  • There is a feature in Appium to find elements by image. There is an article written for this on the Appium Pro platform: https://appiumpro.com/editions/32-finding-elements-by-image-part-1.

    Create image: It accepts a base64 image to search for an element, you can do this by making an image of the ball and put it in the main/resources folder. With the correct method you can create the base64:

    private String getReferenceImageB64() throws URISyntaxException, IOException {
        URL refImgUrl = getClass().getClassLoader().getResource("Edition031_Reference_Image.png");
        File refImgFile = Paths.get(refImgUrl.toURI()).toFile();
        return Base64.getEncoder().encodeToString(Files.readAllBytes(refImgFile.toPath()));
    }
    

    getLocation(): Once it successfully found the image and you can steer the element, you may use the .getLocation() method. This is described on the documentation: http://appium.io/docs/en/advanced-concepts/image-elements/.