I made a Python Script to Automate a Sudoku Game on Android after watching Engineer Man’s Videos on Youtube doing the same for different games.
The script can be divided into 5 parts
Out of the 5, I will be focusing mostly on 2,3 & 5 as 1 & 4 are topics that have been extensively covered.
Link to the game I automated: https://play.google.com/store/apps/details?id=com.quarzo.sudoku
The complete code is available on the following repository:
Github: haideralipunjabi/sudoku_automate
You can also watch the script in action:
Most of the tutorials on internet use Wired ADB, which discourages many people from using this method. I will be using Wireless ADB, which isn’t very difficult to setup.
You can define the following function to connect to the first ADB device connected to your computer using Python
from ppadb.client import Client
def connect_device():
adb = Client(host='127.0.0.1',port=5037)
devices = adb.devices()
if len(devices) == 0:
print("No Devices Attached")
quit()
return devices[0]
We will be using this function later to return an instance of ppadb.device.Device
which will be used to take a screenshot, and send input to your device.
pure-python-adb makes it very easy to capture a screenshot of your device. The screencap
function is all that you need to get the screenshot. Use Pythons File IO to save it to screen.png
def take_screenshot(device):
image = device.screencap()
with open('screen.png', 'wb') as f:
f.write(image)
#python #androi #automation