chore: 提交现有客户端自动化代码
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
"""实验脚本:手动跑通"打开商品页 → 进规格面板 → 选颜色尺码"的流程。
|
||||
|
||||
**这是实验脚本,正式流程不得导入本文件。**
|
||||
|
||||
里面的东西都是为了手动调试方便才这么写的,一样都不能带进正式服务:
|
||||
|
||||
- 硬编码的商品号、设备地址、商品标题类名;
|
||||
- `print` 输出(正式代码用日志,见 `docs/client/06-quality-security.md` §6);
|
||||
- 写到当前目录的 xml/png(正式代码写 `data/artifacts/`,
|
||||
见 `docs/client/03-data-model.md` §2.1);
|
||||
- 出错就 `return`、不区分原因(正式代码要返回结构化错误,
|
||||
不能把所有失败都变成 `False` 或 `None`,见 `docs/client/02-architecture.md` §9)。
|
||||
|
||||
要把这里的逻辑正式化,迁到 PDD 适配层,接口见 `02-architecture.md` §9。
|
||||
|
||||
运行前提:手机已连接、已登录拼多多。本脚本**不会下单**——
|
||||
最后的 `device.click(*coord)` 是注释掉的,不要随手放开。
|
||||
"""
|
||||
|
||||
import time
|
||||
|
||||
import uiautomator2 as u2
|
||||
from util.loaded_pdd import wait_goods_page
|
||||
from util.get_size_panle_coord import get_size_panel_coord
|
||||
from util.select_color_size import select_color_size
|
||||
from util.get_order_button import get_order_button
|
||||
|
||||
package_name='com.xunmeng.pinduoduo'
|
||||
goods_id="737116531267"
|
||||
goods_url=f"https://mobile.yangkeduo.com/goods.html?goods_id={goods_id}"
|
||||
goods_title_node_class="androidx.viewpager.widget.ViewPager"
|
||||
goods_color="抹茶绿长款"
|
||||
goods_size="L(80-115斤)"
|
||||
def main():
|
||||
# 连接设备
|
||||
device = u2.connect("192.168.0.173:5555")
|
||||
|
||||
#获取当前应用包名
|
||||
current_package_name=device.app_current()["package"]
|
||||
|
||||
#如果不是拼多多则启动
|
||||
if current_package_name!=package_name:
|
||||
device.app_start(package_name)
|
||||
|
||||
# 等待拼多多启动
|
||||
device.app_wait(package_name)
|
||||
|
||||
# 等待拼多多首页加载完成
|
||||
device.idle_delay=10
|
||||
device.implicitly_wait(5)
|
||||
|
||||
# 打开商品链接
|
||||
device.open_url(goods_url)
|
||||
if wait_goods_page(device):
|
||||
print("商品页面加载完成")
|
||||
else:
|
||||
print("商品页面加载超时")
|
||||
print(device.app_current())
|
||||
device.screenshot("load_timeout.png")
|
||||
# 等待页面跳转完成
|
||||
# device.implicitly_wait(15)
|
||||
|
||||
|
||||
# 获取只能直接获取 Android 无障碍控件树,用来给llm分析改点击哪个
|
||||
goods_home_xml = device.dump_hierarchy(pretty=True)
|
||||
with open(f"{goods_id}_home.xml","w",encoding='utf-8') as f:
|
||||
f.write(goods_home_xml)
|
||||
|
||||
#判断商品标题node是否存在
|
||||
goods_title_node=device(className=goods_title_node_class)
|
||||
if goods_title_node.exists==False:
|
||||
print("在规格面板")
|
||||
return
|
||||
print("在商品详情页")
|
||||
device.screenshot(f"{goods_id}_home.png")
|
||||
|
||||
# 获取规格面板坐标
|
||||
coord=get_size_panel_coord(goods_home_xml)
|
||||
if coord is None:
|
||||
print("解析失败")
|
||||
return
|
||||
|
||||
# 点击进入规格面板
|
||||
device.click(*coord)
|
||||
time.sleep(1)
|
||||
|
||||
print("等待规格面板加载完成")
|
||||
|
||||
color_size_xml = device.dump_hierarchy(pretty=True)
|
||||
with open(f"{goods_id}_size.xml","w",encoding='utf-8') as f:
|
||||
f.write(color_size_xml)
|
||||
device.screenshot(f"{goods_id}_size.png")
|
||||
|
||||
# #尝试滑倒面板下面选择尺码
|
||||
# size_panle_scroller = device(scrollable=True)
|
||||
# if size_panle_scroller.exists==False:
|
||||
# print("没有找到可滚动的规格面板")
|
||||
# return
|
||||
|
||||
# #尝试滑动到底部
|
||||
# size_panle_scroller.scroll.toEnd(max_swipes=20, steps=50)
|
||||
# time.sleep(1)
|
||||
# size_panle_xml = device.dump_hierarchy(pretty=True)
|
||||
# with open(f"{goods_id}_size.xml","w",encoding='utf-8') as f:
|
||||
# f.write(size_panle_xml)
|
||||
# device.screenshot(f"{goods_id}_size.png")
|
||||
|
||||
# #选中颜色分类
|
||||
# color_node=device(text=goods_color)
|
||||
# if color_node.exists==False:
|
||||
# print("颜色分类不存在")
|
||||
# return
|
||||
# color_node.click()
|
||||
# time.sleep(1)
|
||||
|
||||
# #选中尺码
|
||||
# size_node=device(text=goods_size)
|
||||
# if size_node.exists==False:
|
||||
# print("尺码不存在")
|
||||
# return
|
||||
# size_node.click()
|
||||
# time.sleep(1)
|
||||
|
||||
success = select_color_size(
|
||||
device=device,
|
||||
xml_data=color_size_xml,
|
||||
target_color=goods_color,
|
||||
target_size=goods_size,
|
||||
)
|
||||
if success:
|
||||
print("颜色和尺码选择完成")
|
||||
else:
|
||||
print("没有找到指定颜色或尺码")
|
||||
|
||||
order_xml = device.dump_hierarchy(pretty=True)
|
||||
coord=get_order_button(order_xml)
|
||||
print(coord)
|
||||
# device.click(*coord)
|
||||
if __name__ == "__main__":
|
||||
import sys,os
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
main()
|
||||
Reference in New Issue
Block a user