Created
December 26, 2020 15:15
-
-
Save bbchriscesar/1c9ee1df47585c584329f17cda00be18 to your computer and use it in GitHub Desktop.
This file contains 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
from appium import webdriver | |
import time | |
import os.path | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.common.by import By | |
xpath = By.XPATH | |
id = By.ID | |
css = By.CSS_SELECTOR | |
name = By.NAME | |
className = By.CLASS_NAME | |
udid = '192.168.53.108:5557' | |
appPackage = 'com.android.settings' | |
appActivity = '.Settings' | |
lang=("en-US,de") | |
for lang in lang.split(","): | |
desired_capabilities = {} | |
desired_capabilities['platformName'] = 'Android' | |
desired_capabilities['deviceName'] = 'Pixel 2' | |
desired_capabilities['orientation'] = 'PORTRAIT' | |
desired_capabilities['noReset'] = False | |
desired_capabilities['udid'] = udid | |
desired_capabilities['appPackage'] = appPackage | |
desired_capabilities['appActivity'] = appActivity | |
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_capabilities) | |
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) | |
time.sleep(1) | |
def stopApp(): | |
adb = 'adb -s ' + udid + ' shell am force-stop ' + appPackage | |
os.system(adb) | |
time.sleep(1) | |
def clearApp(): | |
adb = 'adb -s ' + udid + ' shell am clear ' + appPackage | |
os.system(adb) | |
time.sleep(1) | |
def startApp(): | |
adb = 'adb -s ' + udid + ' shell am start -n ' + appPackage + '/' + appActivity | |
os.system(adb) | |
time.sleep(1) | |
def swipeDown(x2, y2, x1, y1, delay): | |
driver.swipe(x2, y2, x1, y1, delay) | |
time.sleep(2) | |
def findAndClickElements(locator, value, index): | |
driver.find_elements(locator, value)[index].click() | |
time.sleep(1) | |
def findAndClick(locator, value): | |
driver.find_element(locator, value).click() | |
time.sleep(1) | |
def takeScreenshot(filename): | |
time.sleep(1) | |
driver.save_screenshot(filename + '.png') | |
b = os.path.split(filename)[1] | |
print('Take screenshot for ' + b) | |
def waitForElement(locator, value): | |
wait = WebDriverWait(driver, 60) | |
try: | |
element = wait.until(EC.element_to_be_clickable((locator, value))) | |
print('Waiting for the element to be clickable') | |
except Exception as ex: | |
print(ex) | |
def customDelay(secondsToDelay): | |
time.sleep(secondsToDelay) | |
print('Added ' + str(secondsToDelay) + ' seconds to delay') | |
def homeScreen(): | |
adb = 'adb -s ' + udid + ' shell input keyevent KEYCODE_HOME' | |
os.system(adb) | |
time.sleep(1) | |
path = '/Users/christiannec/PycharmProjects/AndroidProjects/Screenshots/Sample/' + lang | |
if not os.path.exists(path): | |
os.makedirs(path) | |
changeLocale() | |
stopApp() | |
startApp() | |
print('***' + lang + '***') | |
print('Press ENTER to take screenshot') | |
os.system("""bash -c 'read -s -n 1 -p "\nTake a screenshot #1..."'""") | |
# Screen pinning off | |
takeScreenshot(path + '/' + 'LocationWork') | |
homeScreen() | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment