Skip to content

Instantly share code, notes, and snippets.

@oshinko
Last active August 6, 2017 04:35
Show Gist options
  • Save oshinko/cbe86a1f68d06f8427a5d2f211dba7ef to your computer and use it in GitHub Desktop.
Save oshinko/cbe86a1f68d06f8427a5d2f211dba7ef to your computer and use it in GitHub Desktop.
Automated GUI Testing with OpenCV.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from cvwrapper import AndroidAgent, Image
# Create agent
agent = AndroidAgent()
# Capture image
image = agent.capture()
# Create template
tpl = Image('button.png')
# Do Template Matching (Max loc only)
if tpl in image * 0.8:
agent.touch()
# Do Template Matching (Retrieves all)
for loc in image.find(tpl):
agent.touch(loc)
# Do Contour Area Matching (First match only)
if (100, 200) in image:
agent.touch()
# Do Contour Area Matching (Retrieves all)
for loc in image.find((100, 200)):
agent.touch(loc)
# Do OCR (First match only)
if 'OK' in image:
agent.touch()
# Do OCR (Retrieves all)
for loc in image.find('OK'):
agent.touch(loc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment