python实现appium代码
from appium import webdriver
import time
from appium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver.common.multi_action import MultiAction
class MyAppDriver:
def __init__(self):
self.desired_capabilities = {
"platformName": "Android",
"platformVersion": "5.1.1",
"deviceName": "DemoDevice",
"appPackage": "cn.gov.tax.its",
"appActivity": "cn.gov.tax.its.MainActivity",
"udid": "127.0.0.1:62001"
}
self.driver = webdriver.Remote("http://localhost:4723/wd/hub",self.desired_capabilities)
def app_demo(self):
mywait = WebDriverWait(self.driver,30,poll_frequency=0.5)
element = mywait.until(EC.presence_of_element_located((MobileBy.XPATH,"//*[contains(@text,\"确定\")]")))
element.click()
mytouch = TouchAction(self.driver)
for i in range(2):
mytouch.press(x=500,y=500).move_to(x=200,y=500).release().perform()
time.sleep(1)
lijitiyan_element = mywait.until(EC.presence_of_element_located((MobileBy.ANDROID_UIAUTOMATOR,
'new UiSelector().text("立即体验")')))
lijitiyan_element_rect = lijitiyan_element.rect
print(lijitiyan_element_rect)
lijitiyan_element_size = lijitiyan_element.size
print(lijitiyan_element_size)
lijitiyan_element.click()
self.driver.keyevent(22)
self.driver.press_keycode(22)
def get_android_devices(self):
devices = []
result = subprocess.Popen("adb devices",stdout=subprocess.PIPE,shell=True)
contents = result.stdout.read()
print(contents)
contents1 = contents.decode(encoding="utf-8")
contents1 = contents1.replace("\r\n","#").split("#")
print(contents1)
for item in contents1:
matched = re.match(r"(.*?)\s+device$",item)
if matched:
result = matched.group(1)
devices.append(result)
return devices
if __name__ == '__main__':
mytest = MyAppDriver().app_demo()
|