appium常用代码

参考

mirrors / openatx / uiautomator2 · GitCode

【测试】Python手机自动化测试库uiautomator2和weditor的详细使用_uiautomator2连接wifi_冰冷的希望的博客-CSDN博客

Python函数:

range(start, stop, step)

range(初值, 终值, 步长)

ramdom函数

random.randint(start, stop)

方法返回指定范围内的整数,以下实例返回一个 1 到 9 之间的数字(大于等于 1,小于等于 9 ):print(random.randint(1, 9))

定时器

使用 threading 模块的 Timer 类来实现定时任务。这个类接受两个参数,第一个参数是时间间隔(以秒为单位),第二个参数是需要执行的函数。

import threading
 
def my_function():
# 需要定时执行的代码 
timer = threading.Timer(60, my_function)  # 每隔60秒执行一次 my_function
timer.start()

 

定义手机/模拟器

desired_caps={
    "platformName":"Android",
    "platformVersion":"7.1.2",
    "deviceName":"huawei",
    "appPackage":"com.tencent.mobileqq",
    "appActivity":"com.tencent.mobileqq.activity.SplashActivity",
    "noReset":True
}

连接

driver=webdriver.Remote("http://127.0.0.1:4723/wd/hub",desired_caps)

获取屏幕尺寸

window_size=driver.get_window_size()
print(window_size)
x=window_size["width"]
y=window_size["height"]

三种等待

参考:新手学 appium-Appium 的三种等待时间设置方法 · TesterHome

显示等待:

element = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_id("com.tencent.mobileqq:id/et_search_keyword"))

元素定位:

Appium-Python-Client   1.3.0版本:

find_element_by_id("com.tencent.mobileqq:id/et_search_keyword")
el_cron=driver.find_element_by_android_uiautomator('new UiSelector().text("搜索")').send_keys('fjm')

元素操作:

点击:.click()

发送:.send_keys('')

滑动:

driver.swipe(x*0.8,y*0.5,x*0.3,y*0.5,1000)
posted @ 2023-08-22 17:52  疯狂的草  阅读(69)  评论(0)    收藏  举报