Last active
January 8, 2021 18:41
-
-
Save bbchriscesar/4b2febfe35afc5f671b60b4a78463cbf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import time | |
| udid = '9A221FFBA002JN' | |
| appPackage = 'com.google.android.apps.gmm' | |
| appActivity = 'com.google.android.maps.MapsActivity' | |
| def startApp(): | |
| print('Start application ' + appPackage) | |
| adb = 'adb -s ' + udid + ' shell am start -n ' + appPackage + '/' + appActivity | |
| os.system(adb) | |
| time.sleep(2) | |
| def stopApp(): | |
| adb = 'adb -s ' + udid + ' shell am force-stop ' + appPackage | |
| os.system(adb) | |
| time.sleep(1) | |
| adb1 = 'clear' | |
| os.system(adb1) | |
| def changeLocale(): | |
| adb = 'adb -s ' + udid + ' shell am broadcast -a com.google.android.testing.i18n.localeswitcher.CHANGE_LOCALE -e LANGUAGE_TAG ' + lang | |
| os.system(adb) | |
| print('Locale switched to ' + '[ ' + lang + ' ]') | |
| time.sleep(1) | |
| def takeScreenshot(filename): | |
| # Create a directory | |
| print('[ ' + lang + ' ]' + ' Taking screenshot for ' + filename) | |
| adb1 = 'adb -s ' + udid + ' shell mkdir /sdcard/' + lang | |
| os.system(adb1) | |
| # Capture screenshot | |
| adb2 = 'adb -s ' + udid + ' shell screencap /sdcard/' + lang + '/' + filename + '.png' | |
| os.system(adb2) | |
| # Pull screenshot from sdcard | |
| adb3 = 'adb -s ' + udid + ' pull /sdcard/' + lang + '/' + filename + '.png' + ' ' + path | |
| os.system(adb3) | |
| # Delete screenshot from sdcard | |
| adb4 = 'adb -s ' + udid + ' shell rm /sdcard/' + lang + '/' + '*' | |
| os.system(adb4) | |
| # Delete folder from sdcard | |
| adb5 = 'adb -s ' + udid + ' shell rmdir /sdcard/' + lang | |
| os.system(adb5) | |
| time.sleep(2) | |
| def tap(coordinates): | |
| adb = 'adb -s ' + udid + ' shell input tap ' + coordinates | |
| os.system(adb) | |
| time.sleep(2) | |
| def back(): | |
| adb = 'adb -s ' + udid + ' shell input keyevent KEYCODE_BACK' | |
| os.system(adb) | |
| time.sleep(1) | |
| def longPressPower(): | |
| adb = 'adb -s ' + udid + ' shell input keyevent --longpress KEYCODE_POWER' | |
| os.system(adb) | |
| time.sleep(1) | |
| def hideNotifIcons(): | |
| adb = 'adb -s ' + udid + ' shell am broadcast -a com.android.systemui.demo -e command notifications -e visible false' | |
| os.system(adb) | |
| time.sleep(2) | |
| def collapseNotificationBar(): | |
| adb = 'adb -s ' + udid + ' shell cmd statusbar collapse' | |
| os.system(adb) | |
| time.sleep(2) | |
| def swipe(xyCoordinatesSpeed): | |
| adb = 'adb -s ' + udid + ' shell input swipe ' + xyCoordinatesSpeed | |
| os.system(adb) | |
| time.sleep(1) | |
| def closeNotif(): | |
| adb = 'adb -s ' + udid + ' shell input swipe 635 342 635 153 700' | |
| os.system(adb) | |
| time.sleep(1) | |
| def screenOrientation(orientation): | |
| # 1 - landscape, 0 - portrait | |
| adb = 'adb -s ' + udid + ' shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:' + orientation | |
| os.system(adb) | |
| time.sleep(1) | |
| lang = ("en-US") | |
| for lang in lang.split(","): | |
| path = '/Users/christiannec/PycharmProjects/AndroidProjects/Screenshots/sample/' + lang | |
| if not os.path.exists(path): | |
| os.makedirs(path) | |
| changeLocale() | |
| hideNotifIcons() | |
| closeNotif() | |
| print('[ ' + lang + ' ]') | |
| startApp() | |
| time.sleep(4) | |
| # START YOUR SCRIPT HERE... | |
| stopApp() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment