Files
anroid-CheckShot/test_location_watermark.py

114 lines
3.8 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from airtest.core.api import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
import time
# 初始化设备
init_device("Android", uuid="emulator-5554")
poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
print("=" * 50)
print("开始测试拍照功能 - 位置水印测试")
print("=" * 50)
# 启动应用
print("\n[1] 启动应用...")
home()
start_app("com.inspection.camera")
sleep(5)
# 等待应用加载
print("[2] 等待应用加载...")
snapshot("app_loaded.png")
print("[INFO] 已保存截图: app_loaded.png")
# 等待定位完成,检测定位文本
print("\n[3] 等待定位完成最多15秒...")
location_text = ""
for i in range(15):
try:
# 尝试通过poco获取定位文本UI中的卡片文本
# 定位文本可能位于某个Card内我们尝试查找包含"定位"的文本元素
elements = poco(textMatches=".*定位.*")
if elements.exists():
location_text = elements.get_text()
print(f"[INFO] 检测到定位文本: {location_text}")
if location_text != "正在定位...":
break
except Exception as e:
pass
sleep(1)
print(f"等待 {i+1}/15 秒")
# 如果未找到定位文本,尝试其他选择器
if not location_text:
try:
# 尝试查找包含"定位"或"位置"的文本
for text in ["定位", "位置", "地点"]:
elements = poco(textMatches=f".*{text}.*")
if elements.exists():
location_text = elements.get_text()
print(f"[INFO] 通过关键词 '{text}' 找到定位文本: {location_text}")
break
except Exception as e:
print(f"[WARNING] 查找定位文本失败: {e}")
print(f"\n[INFO] 最终定位文本: '{location_text}'")
# 验证定位是否失败(超时后应显示"定位失败"
if location_text == "定位失败":
print("[SUCCESS] 定位超时后正确显示'定位失败'")
else:
print(f"[WARNING] 定位文本不是'定位失败',而是: {location_text}")
# 点击拍照按钮(屏幕中央下方)
print("\n[4] 点击拍照按钮...")
shell("input tap 540 2100")
sleep(3)
snapshot("after_capture.png")
print("[INFO] 拍照后截图: after_capture.png")
# 检查保存的图片文件
print("\n[4.5] 检查保存的图片文件...")
sleep(2) # 等待文件保存
# 列出图片目录
output = shell("ls -t /sdcard/Pictures/InspectionCamera/*.jpg 2>/dev/null | head -1")
if output and output.strip():
latest_image = output.strip()
print(f"[INFO] 找到最新图片: {latest_image}")
# 获取文件大小
size_output = shell(f"du -h {latest_image} 2>/dev/null | cut -f1")
if size_output:
print(f"[INFO] 文件大小: {size_output.strip()}")
else:
print("[WARNING] 未找到保存的图片文件,可能路径不同")
# 尝试其他可能路径
shell("ls -l /sdcard/Pictures/ 2>/dev/null")
shell("ls -l /sdcard/DCIM/ 2>/dev/null")
# 打开相册
print("\n[5] 打开相册...")
shell("am start -n com.google.android.apps.photos/.home.HomeActivity")
sleep(3)
snapshot("gallery.png")
print("[INFO] 相册截图: gallery.png")
# 点击最新图片(假设第一张缩略图位于屏幕中央)
print("\n[6] 点击最新图片...")
touch([540, 600])
sleep(2)
snapshot("gallery_detail.png")
print("[INFO] 图片详情截图: gallery_detail.png")
print("\n[7] 测试完成,请检查截图文件中的水印")
print("\n" + "=" * 50)
print("测试完成!")
print("=" * 50)
print("\n请检查截图文件:")
print("1. app_loaded.png - 应用界面")
print("2. after_capture.png - 拍照后")
print("3. gallery.png - 相册")
print("4. gallery_detail.png - 图片详情")
print("\n检查照片左下角是否有时间+位置水印")
print("=" * 50)