This is the second 2-part series on OCR integration with Appium.
In this article, we’ll look at general OCR libraries that cab achieve image recognition and how this library integrate with Appium.

AirTest Library

It is a cross-platform UI automated testing framework based on image identification. And it is suitable for games and apps, and the supported platforms are Windows, Android and iOS.

Install airtest via pip:

Copy to Clipboard

The module airtest.core.api in Airtest provides a series of cross-platform API for calling, including touch operation touch, drag operation swipe, input text operationtext and other operations.

Copy to Clipboard

Integrate with Appium

Start appium and connect to server:

Copy to Clipboard

Get scale of resolution and set size for image recognition:

Copy to Clipboard

Overwrite findelement function to support image recognition and return ImageElement:

Copy to Clipboard

Appium supports both implicit and explicit wait strategies, to make your tests can robustly wait until your reference UI component exist.
So you need to create your own explicit wait strategies to support find_by_image:

Copy to Clipboard

Finnally achieve the operations under ImageElement class:

Copy to Clipboard

After framework encapsulation, write the test script:

Copy to Clipboard