10 多年测试老兵,擅长自动化测试,欢迎各位测试友友们交流沟通!!!
https://testerhome.com/topics/40069
看下这个工具,uiautodev,查找元素很方便,兼容新版 android 系统
一般都是落地 android 端,iOS 成本大,如果没有苹果机器先研究 Android 端的,比较容易落地,面试的话研究 Android 来提高就可以,具体执行等入职后再根据产品形态进行下一步落地方案,面试的话先从 Android 来
大模型调用和存储的成本如何,如果全套自动化测试下来需要 1K 张截图给大模型来计算, 成本如何?
试试下面的方法:
def swipe_up_count(count):
for _ in range(count): # 尝试滑动两次以确保成功
result = adb_swipe_up(
start_x_percent=0.5,
start_y_percent=0.8, # 调整起始点更靠近屏幕底部
end_x_percent=0.5,
end_y_percent=0.2, # 调整终点避免过度滑动
duration=500, # 增加滑动持续时间,使动作更平滑
)
if result:
print("滑动成功")
break
time.sleep(1)
def adb_swipe_up(
start_x_percent=0.5,
start_y_percent=0.7,
end_x_percent=0.5,
end_y_percent=0.3,
duration=300,
max_attempts=3,
delay=1,
):
"""使用 ADB 命令执行上滑操作,支持自定义滑动参数和重试机制
该函数提供以下功能:
1. 支持通过百分比设置滑动起始和终点位置
2. 自动获取设备屏幕尺寸并计算实际坐标
3. 可配置滑动持续时间
4. 内置重试机制,处理滑动失败的情况
Args:
start_x_percent (float): 起始点 x 坐标在屏幕宽度上的百分比,默认 0.5(屏幕中间)
start_y_percent (float): 起始点 y 坐标在屏幕高度上的百分比,默认 0.7(屏幕偏下位置)
end_x_percent (float): 终点 x 坐标在屏幕宽度上的百分比,默认 0.5(屏幕中间)
end_y_percent (float): 终点 y 坐标在屏幕高度上的百分比,默认 0.3(屏幕偏上位置)
duration (int): 滑动持续时间(毫秒),默认 300ms
max_attempts (int): 最大重试次数,默认 3 次
delay (int): 重试间隔时间,默认 1 秒
Returns:
bool: 滑动操作是否成功。成功返回 True,失败返回 False
"""
for attempt in range(max_attempts):
try:
# 获取屏幕尺寸
output = subprocess.check_output(["adb", "shell", "wm", "size"])
size_str = output.decode("utf-8").strip()
width, height = map(int, size_str.split(": ")[1].split("x"))
# 计算实际滑动坐标
start_x = int(width * start_x_percent)
start_y = int(height * start_y_percent)
end_x = int(width * end_x_percent)
end_y = int(height * end_y_percent)
print(
f"开始执行滑动操作:从 ({start_x}, {start_y}) 滑动到 ({end_x}, {end_y})"
)
# 执行滑动操作
try:
subprocess.run(
[
"adb",
"shell",
"input",
"swipe",
str(start_x),
str(start_y),
str(end_x),
str(end_y),
str(duration),
],
check=True,
)
time.sleep(0.5) # 等待滑动动画完成
print("滑动操作执行成功")
return True
except subprocess.CalledProcessError as swipe_error:
print(f"滑动操作执行失败: {swipe_error}")
except Exception as e:
print(f"第 {attempt + 1} 次滑动尝试失败: {e}")
time.sleep(delay)
return False
具体代码块发一下,滑动好好多方式,看你用的哪个?看报错是 http 不支持
用下面的 adb 滑动方法试试
def adb_swipe_up(
start_x_percent=0.5,
start_y_percent=0.7,
end_x_percent=0.5,
end_y_percent=0.3,
duration=300,
max_attempts=3,
delay=1,
):
"""使用 ADB 命令执行上滑操作,支持自定义滑动参数和重试机制
该函数提供以下功能:
1. 支持通过百分比设置滑动起始和终点位置
2. 自动获取设备屏幕尺寸并计算实际坐标
3. 可配置滑动持续时间
4. 内置重试机制,处理滑动失败的情况
Args:
start_x_percent (float): 起始点 x 坐标在屏幕宽度上的百分比,默认 0.5(屏幕中间)
start_y_percent (float): 起始点 y 坐标在屏幕高度上的百分比,默认 0.7(屏幕偏下位置)
end_x_percent (float): 终点 x 坐标在屏幕宽度上的百分比,默认 0.5(屏幕中间)
end_y_percent (float): 终点 y 坐标在屏幕高度上的百分比,默认 0.3(屏幕偏上位置)
duration (int): 滑动持续时间(毫秒),默认 300ms
max_attempts (int): 最大重试次数,默认 3 次
delay (int): 重试间隔时间,默认 1 秒
Returns:
bool: 滑动操作是否成功。成功返回 True,失败返回 False
"""
for attempt in range(max_attempts):
try:
# 获取屏幕尺寸
output = subprocess.check_output(["adb", "shell", "wm", "size"])
size_str = output.decode("utf-8").strip()
width, height = map(int, size_str.split(": ")[1].split("x"))
# 计算实际滑动坐标
start_x = int(width * start_x_percent)
start_y = int(height * start_y_percent)
end_x = int(width * end_x_percent)
end_y = int(height * end_y_percent)
print(
f"开始执行滑动操作:从 ({start_x}, {start_y}) 滑动到 ({end_x}, {end_y})"
)
# 执行滑动操作
try:
subprocess.run(
[
"adb",
"shell",
"input",
"swipe",
str(start_x),
str(start_y),
str(end_x),
str(end_y),
str(duration),
],
check=True,
)
time.sleep(0.5) # 等待滑动动画完成
print("滑动操作执行成功")
return True
except subprocess.CalledProcessError as swipe_error:
print(f"滑动操作执行失败: {swipe_error}")
except Exception as e:
print(f"第 {attempt + 1} 次滑动尝试失败: {e}")
time.sleep(delay)
return False
确保每个页面都被点击需要额外控制,点击频率可以统计 activity,工具的话可以搜一下,有工具可以直接用,但是无法保证每个页面都被点到,因为有些页面是需要特定条件才能点进去的,需要二次开发才行
问答机器人可以整理一下之前用户的反馈和问的问题当做数据进行测试,这个应该也是有个产品文档和分类的吧,按照需求来就行,还是要针对业务来测,我们不知道你们业务其实没有好的建议
10 多年测试老兵,擅长自动化测试,欢迎各位测试友友们交流沟通!!!