Skip to main content

PandaTest SDK & CLI — 移动端自动化测试平台的 Python 客户端

Project description

PandaTest SDK & CLI

PandaTest 移动端自动化测试平台的 Python SDK 和命令行工具。

安装

pip install pandatest

开发模式安装:

cd packages/pandatest
pip install -e .

快速开始

SDK 使用

from pandatest import PandaTest

client = PandaTest(api_key="pk_xxx")

# 项目作用域
scope = client.project(2)

# 列出构建
builds = scope.builds.list()
for build in builds.items:
    print(f"{build.id}: {build.name}")

# 触发构建
result = scope.builds.trigger("build-14-xxx")
print(f"Job created: {result.job_id}")

# 等待 Job 完成
job = scope.jobs.wait(result.job_id, timeout=600)
print(f"Status: {job.status}, Pass rate: {job.pass_rate}%")

CLI 使用

# 配置
pt config set --api-key pk_xxx --url https://your-domain.com
pt config show

# 触发构建并等待
pt run --build build-14-xxx --wait --timeout 600

# 管理构建
pt builds list
pt builds get build-14-xxx
pt builds create --name "回归测试" --app 1 --parallel --concurrency 3
pt builds trigger build-14-xxx
pt builds delete build-14-xxx

# 查看 Job
pt jobs list --build build-14-xxx
pt jobs get job-xxx
pt jobs cancel job-xxx
pt jobs rerun job-xxx

# 查看 Task
pt tasks list --job job-xxx
pt tasks get task-xxx
pt tasks logs task-xxx

# 管理调度
pt schedules list
pt schedules create --name "每日回归" --build build-14-xxx --frequency daily --time 02:00
pt schedules enable schedule-xxx
pt schedules disable schedule-xxx
pt schedules trigger schedule-xxx
pt schedules delete schedule-xxx

# 设备与自动化锁(OpenAPI)
pt devices list
pt devices list --platform android --status online
pt devices acquire R58N30ABCDE
pt devices status R58N30ABCDE
pt devices release R58N30ABCDE --lease-token <from-acquire>

SDK 示例(acquire 自动带心跳,release 自动停心跳):

from pandatest import PandaTest

client = PandaTest(api_key="pk_xxx", base_url="http://localhost:8000")
client.devices.acquire("R58N30ABCDE")
try:
    # 在这里执行自动化任务,心跳自动保活
    pass
finally:
    client.devices.release("R58N30ABCDE")  # 无需传 token,SDK 自动记住
    client.close()

CI/CD (GitHub Actions)

- name: Install PandaTest CLI
  run: pip install pandatest

- name: Run Tests
  env:
    PANDA_API_KEY: ${{ secrets.PANDA_API_KEY }}
    PANDA_PROJECT_ID: "2"
  run: pt run --build build-14-xxx --wait --timeout 600

配置

配置按优先级加载(高到低):

  1. 构造函数参数 / CLI 参数
  2. 环境变量: PANDA_API_KEY, PANDA_API_URL, PANDA_PROJECT_ID
  3. 配置文件: ~/.pandatest/config.toml

SDK API

项目作用域

SDK 采用项目作用域模式,项目级 API 需要先绑定 project_id

client = PandaTest(api_key="pk_xxx")

# 风格 A: ProjectScope(推荐)
scope = client.project(123)
scope.builds.list()
scope.jobs.list()
scope.tasks.list()
scope.schedules.list()

# 风格 B: 每模块单独绑定
client.builds(123).list()
client.jobs(123).list()

Projects(全局,无需项目作用域)

方法 说明
client.projects.list() 获取当前用户可访问的项目列表
client.projects.get(id) 获取项目详情

Builds

方法 说明
scope.builds.list() 列出构建
scope.builds.get(id) 获取构建详情
scope.builds.create(name=, app=) 创建构建
scope.builds.update(id, **fields) 更新构建
scope.builds.delete(id) 删除构建
scope.builds.trigger(id) 触发构建
scope.builds.duplicate(id) 复制构建
scope.builds.toggle_pin(id) 切换置顶状态
scope.builds.recent_jobs(id, limit=10) 获取最近的 Job 列表
scope.builds.trigger_image_build(id) 触发 Runner 镜像构建
scope.builds.image_status(id) 获取 Runner 镜像状态
scope.builds.logs(id, tail=500) 获取构建日志

Jobs

方法 说明
scope.jobs.list(build_id=) 列出 Job
scope.jobs.get(id) 获取 Job 详情
scope.jobs.cancel(id) 取消 Job
scope.jobs.rerun(id) 重新运行 Job
scope.jobs.tasks(id) 获取 Job 下的 Task
scope.jobs.wait(id, timeout=600) 等待 Job 完成
scope.jobs.report_summary(id) 获取 Job 报告摘要
scope.jobs.share(id, action=, expires_days=) 创建/禁用分享链接
scope.jobs.share_status(id) 获取分享状态

Tasks

方法 说明
scope.tasks.list(job_id=) 列出 Task
scope.tasks.get(id) 获取 Task 详情
scope.tasks.logs(id) 获取 Task 日志
scope.tasks.running_stats() 获取运行中的 Task 统计

Schedules

方法 说明
scope.schedules.list() 列出调度
scope.schedules.get(id) 获取调度详情
scope.schedules.create(name=, build=, frequency=) 创建调度
scope.schedules.update(id, **fields) 更新调度
scope.schedules.delete(id) 删除调度
scope.schedules.enable(id) 启用调度
scope.schedules.disable(id) 禁用调度
scope.schedules.trigger(id) 立即触发调度

Devices(全局,无需项目作用域)

方法 说明
client.devices.list() 获取设备列表(含锁状态)
client.devices.get(device_id) 获取单个设备详情
client.devices.acquire(device_id) 占用设备(自动启动心跳)
client.devices.release(device_id) 释放设备(自动停止心跳)
client.devices.lock_status(device_id) 查询设备锁状态
client.devices.remote_debug_start(device_id) 启动 ADB 远程调试代理
client.devices.remote_debug_stop(device_id) 停止 ADB 远程调试代理
client.devices.close() 释放所有已占用设备

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pandatest-0.1.0.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pandatest-0.1.0-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

Details for the file pandatest-0.1.0.tar.gz.

File metadata

  • Download URL: pandatest-0.1.0.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for pandatest-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3fce2a4ea118cd0585f4d90000f2da9ab1f15af35df4c0489232b1fe0b561e1c
MD5 e33c5b2a335e62230354cb33b9153e4b
BLAKE2b-256 7892ff702426df88bfdefcd244857176ae4bb8158d2f759b6291892d6f201e89

See more details on using hashes here.

File details

Details for the file pandatest-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pandatest-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 39.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for pandatest-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be8987a06140f7600dcf97c51ebf81e08e4ec82db7d1029117b2b1e2540deccf
MD5 4a5e6e5f7d8e9431ec2b8078f92bf2cc
BLAKE2b-256 ee7a0156b0d9bb161e2080cb21244806f642856fcb87280f9fbd39667dcb8818

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page