https://blog.csdn.net/weixin_45912307/article/details/122422674
app自动化之前置处理—欢迎页划屏
1. 下载app
app下载链接:https://stock.pingan.com/static/info/download/app.html
2. 安装app(平安证券app)
- 方式1:进入cmd窗口adb命令方式安装
adb -s 设备号 install 包名
- 方式2:通过脚本安装
driver.install_app(r'C:\Users\xxxx\Downloads\pastock_pazq.apk')
- 方式3:通过模拟器工具(本人采用这种)
3. 元素定位和编写脚本
注意:参考此篇进行元素定位https://blog.csdn.net/weixin_45912307/article/details/122392478?spm=1001.2014.3001.5501
import time
from logger import logger
from appium import webdriver
from appium.webdriver.webdriver import WebDriver
class App:
def __init__(self, driver: WebDriver = None):
self._driver = driver
def start(self):
if self._driver is None:
caps = {
"platformName": "Android",
"platformVersion": "5.1.1",
"deviceName": "emulator-5554",
"appPackage": "com.hundsun.winner.pazq",
"appActivity": "com.hundsun.winner.pazqapp.ui.home.activity.NewSplashActivity",
"noRest": False,
"skipServerInstallation": True
# "skipDeviceInitialization":True
}
self._driver = webdriver.Remote("http://127.0.0.1:5554/wd/hub", caps)
else:
self._driver.launch_app()
self._driver.implicitly_wait(10)
return self
def restart(self):
pass
def stop(self):
self._driver.quit()
def main(self):
return self._driver
class TestPAZQLogin:
"""以平安证券app划屏为例"""
def __init__(self):
self.app = App()
self.main = self.app.start().main()
def set_up(self):
self.main.find_element_by_id("com.hundsun.winner.pazq:id/pa_dialog_positive_btn").click()
self.swipe_screen(4)
def login_pz(self):
pass
def swipe_screen(self, times):
"""从右向左滑"""
logger.info('开始滑屏操作')
# 滑动四次进入"立即开启"按钮页面
for i in range(1, times + 1):
iphone_size = self.main.get_window_size()
start_x = iphone_size['width'] * 0.9 # x轴开始位置
end_x = iphone_size['width'] * 0.1 # x轴结束位置
start_y = iphone_size['height'] * 0.5 # y轴屏幕中间位置
i += 1
self.main.swipe(start_x, start_y, end_x, start_y, 200) # 从右向左滑,操作耗时200ms
time.sleep(2)
# 点击首页”立即体验“按钮
self.main.find_element_by_class_name('android.widget.ImageView').click()
def teardown_class(self):
self.app.stop()
if __name__ == '__main__':
LG = TestPAZQLogin()
LG.set_up()
4. 执行脚本结果