-
自动化测试框架
自动化测试框架:python+uiautomator2+pytest+pytest-html
-
自动化的设计模式
设计模式:POM(PageObject Model)
说明文件(readme.txt),具体如下:
-
概述
该DEMO项目用于自动化测试APP导航零号的一框搜索功能,内容如下:
-
base目录
basepage.py
# 创建者: zhangxuexin
# 创建时间: :2022/5/10 15:25
import os
import time
from time import sleep
import uiautomator2 as u2
from PIL import Image
from config.config_read import config
from config.log_read import logger
class BasePage():
'''该类用于封装uiautomator2的各种操作,以作为工具类来使用'''
def __init__(self, d):
self.d = d
# 元素定位
def loction(self, attribute, loc):
'''
:param attribute:元素属性名称相当于key
:param loc: 元素属性值,相当于value
:return: 定位到的元素
'''
try:
if attribute == 'resourceId':
return self.d(resourceId=loc)
elif attribute == 'text':
return self.d(text=loc)
logger.error(f'获取元素信息为:{loc},元素属性为:{attribute},元素定位成功')
except Exception as e:
logger.error(f'获取元素信息为:{loc},元素属性为:{attribute},元素定位失败')
# app启动
def start_app(self, package_name):
self.d.app_start(package_name)
# app退出
def stop_app(self, package_name):
self.d.app_stop(package_name)
# app全部退出
def stop_allapp(self):
self.d.app_stop_all()
logger.info('退出设备所有程序')
# 点击操作
def click(self, attribute, loc):
try:
self.loction(attribute, loc).click()
logger.info(f'点击信息为:{loc},元素属性为:{attribute},点击操作成功')
except Exception as e:
logger.error(f'点击信息为:{loc},元素属性为:{attribute},点击操作失败')
# 输入字符
def send_keys(self, attribute, loc, text):