1、配置小程序
coding:utf-8
author = ‘lili’
‘’’
description:driver配置
‘’’
import time
from appium import webdriver
class driver_configure():
@property
def get_driver(self):
# 获取driver
try:
desired_caps = {}
desired_caps[‘platformName’] = ‘Android’ # 平台
desired_caps[‘platformVersion’] = ‘23’ # 系统版本
desired_caps[‘deviceName’] = ‘c3756aa**’ # 设备名称
desired_caps[‘appPackage’] = ‘com.tencent.mm’ # APK包名
desired_caps[‘appActivity’] = ‘com.tencent.mm.ui.LauncherUI’ # 被测程序启动时的Activity
desired_caps[‘unicodeKeyboard’] = ‘true’ # 是否支持unicode的键盘。如果需要输入中文,要设置为“true”
desired_caps[‘resetKeyboard’] = ‘true’ # 是否在测试结束后将键盘重置为系统默认的输入法。
desired_caps[‘newCommandTimeout’] = ‘120’ # Appium服务器待appium客户端发送新消息的时间。默认为60秒
desired_caps[‘noReset’] = True # true:不重新安装APP,false:重新安装app
desired_caps[‘automationName’] = ‘uiautomator2’
desired_caps[‘chromeOptions’] = {‘androidProcess’: ‘com.tencent.mm:appbrand’} # 当前小程序运行的进程
self.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)
time.sleep(5)
return self.driver
except Exception as e:
print(‘启动失败’)
raise e
2、uiautomatorviewer页面元素定义
coding:utf-8
author = ‘lili’
‘’’
description:元素定义
‘’’
from common import Base_page
from appium.webdriver.common import mobileby
import time
class swipe_page(Base_page.Base_page):
by = mobileby.MobileBy()
item_fx = (by.XPATH, “//android.widget.TextView[@text=‘发现’]”) # 点击“发现”
item_xcx = (by.NAME, “小程序”) # 点击小程序
item_wdxcx = (by.NAME, “我的小程序”) # 点击我的小程序
item_kjxs = (by.NAME, “科技线上”) # 点击科技线上
def click_fx(self):
self.find_element(*self.item_fx).click() # 点击“发现”
def click_xcx(self):
self.find_element(*self.item_xcx).click() # 点击小程序
time.sleep(3)
self.find_element(*self.item_wdxcx).click() # 点击我的小程序
time.sleep(3)
self.find_element(*self.item_kjxs).click() # 点击科技线上
def swipe_down(self, n): # # 向下滑动
x = self.driver.get_window_size()['width']
y = self.driver.get_window_size()['height']
for i in range(n):
self.driver.swipe(x / 2, y * 3 / 4, x / 2, y / 4)
def swipe_up(self, n):
'''上滑'''
x = self.driver.get_window_size()['width']
y = self.driver.get_window_size()['height']
for i in range(n):
self.driver.swipe(x / 2, y / 4, x / 2, y * 3 / 4)
3、启动小程序,以及具体的test_case
coding:utf-8
author = ‘lili’
‘’’
description:
‘’’
import unittest
from common import driver_configure
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_c