Appium + python -小程序实例

Posted teachertao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Appium + python -小程序实例相关的知识,希望对你有一定的参考价值。

from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
from time import sleep

desired_caps =
‘platformName‘: ‘android‘,
‘platformVersion‘: ‘9‘,
‘deviceName‘: ‘4871660c‘,
‘appPackage‘: ‘com.tencent.mm‘,
‘appActivity‘: ‘.ui.LauncherUI‘,
‘automationName‘: ‘Appium‘,
# ‘unicodeKeyboard‘: True,
# ‘resetKeyboard‘: True,
‘noReset‘: True,
‘chromeOptions‘: ‘androidProcess‘: ‘com.tencent.mm:appbrand0‘


driver = webdriver.Remote(‘http://localhost:4723/wd/hub‘, desired_caps)

# def swipeDown(driver,t=100,n=1):
# """向下滑动屏幕"""
# size = driver.get_window_size()
# print(size)
# x1 = size[‘width‘]*0.5
# y1 = size[‘height‘]*0.25
# y2 = size[‘height‘]*0.75
# for i in range(n):
# driver.swipe(x1,y1,x1,y2,t)
#
# swipeDown(driver)
# sleep(2)

sleep(3)
#打印屏幕宽和高
print(driver.get_window_size())
#获取屏幕的宽
x = driver.get_window_size()[‘width‘]
#获取屏幕的高
y = driver.get_window_size()[‘height‘]

#向下滑动
driver.swipe(1 / 2 * x, 1 / 7 * y, 1 / 2 * x, 6 / 7 * y, 200)
sleep(3)

#获取当前的会话
print(driver.contexts)

#点开小程序
driver.find_element_by_id("com.tencent.mm:id/jb")[1].click()
sleep(2)



以上是关于Appium + python -小程序实例的主要内容,如果未能解决你的问题,请参考以下文章

python+appium自动化测试 —— Appium并发测试之python启动appium服务

Appium python appium 用 uiautomator2 后报错

Python爬虫编程思想(128):使用Appium抓取移动数据--启动Appium服务

Appium python

Appium+python自动化22-Appium Desktop转载

Appium+python自动化-Appium Python API