持续集成 【官方教程】小程序云测实现 Devops 流程实践分享

Object 测试交流评论80字数 1980阅读模式

简介

小程序云测插件一般是用户手动在开发者工具提交任务。有些用户希望能够做到自动提交测试,将测试能力集成到 devops 流程中,做到定时或者自动触发。
现在云测插件新增第三方接口能力,支持直接用 https 接口调用的方式提测,方便用户将云测能力集成 devops 流程中。文档地址:
https://developers.weixin.qq.com/miniprogram/dev/devtools/minitest/api_exe.html
本文以 Jenkins 为例,详细介绍云测如何和 Jenkins 打通

环境准备

注:环境准备以 Window10+Python 项目 +Git 代码版本管理 +Jenkins 为例介绍,可根据需求准备环境,例如 Linux 操作系统,SVN 代码版本管理,Java 项目等
以下步骤非必须,如果已安装可以跳过文章源自玩技e族-https://www.playezu.com/179665.html

  • 安装 JDK 8
  • 安装 Python 38
  • 安装 Git
  • 下载 Jenkins (https://www.jenkins.io/download/)
  • 安装 Jenkins(可查看用户手册 https://www.jenkins.io/doc/book/getting-started/)
  • 创建管理员用户
  • 配置 Git(这里以 Git 存储测试脚本举例,用户也可以用 SVN 等其他工具存储)
    • 安装 git 插件 Manage Jenkins > Manage Plugins 安装 git plugins
    • 配置 git 工具 Manage Jenkins > Global Tool Configuration
  • 添加凭据 Manage Jenkins > Manage credentials > 添加凭据

Jenkins 实现小程序云测自动测试

  • 新建 Item
    例如选择 Freestyle project

    文章源自玩技e族-https://www.playezu.com/179665.html
  • 配置文章源自玩技e族-https://www.playezu.com/179665.html

1. 选择 GitHub 项目

文章源自玩技e族-https://www.playezu.com/179665.html

2.选择 Git 并添加凭据,在 Additional Behaviours 中选择 Check out to a sub-directory

文章源自玩技e族-https://www.playezu.com/179665.html

文章源自玩技e族-https://www.playezu.com/179665.html

3.构建触发器,选择 Build periodically

文章源自玩技e族-https://www.playezu.com/179665.html

4.构建,选择 Execute Windows batch command,并输入需要执行的命令

文章源自玩技e族-https://www.playezu.com/179665.html

其中 test.py 脚本为请求云测第三方服务接口代码文章源自玩技e族-https://www.playezu.com/179665.html

class MiniTestApi:
def __init__(self, user_token, group_en_id):
self.token = user_token          # 需要填写自己的token
self.group_en_id = group_en_id   # 项目的英文ID
self.minitest_api = 'https://minitest.weixin.qq.com/thirdapi/plan'
def third_auto_task(self):
"""
提交测试任务
:return:
"""
config = {
"assert_capture": True,
"auto_relaunch": True,
"auto_authorize": False,
"audits": True,
"compile_mode": "pages/getOpenId/index?p=1&m=2"
}
data = {
'token': self.token,
'group_en_id': self.group_en_id,
'test_type': 2,
'platforms': 'android,ios',
'wx_id': '',
'wx_version': 3,
'desc': 'Minium测试',
'test_plan_id': 6,
'dev_account_no': 1,
'minium_config': config,
}
resp = requests.post(
self.minitest_api,
json=data
)
resp = resp.json()
print(resp)
return resp
def query_auto_task(self, plan_id):
"""
查询测试任务
:param plan_id:
:return:
"""
data = {
'token': self.token,
'group_en_id': self.group_en_id,
'plan_id': plan_id,
}
resp = requests.get(
self.minitest_api,
params=data
)
resp = resp.json()
print(resp)
if __name__ == '__main__':
minitest_client = MiniTestApi('xxx', 'xxx')
result = minitest_client.third_auto_task()
if "plan_id" not in result["data"].keys():
exit(1)
plan_id = result["data"]["plan_id"]
time.sleep(10)
minitest_client.query_auto_task(plan_id)
文章源自玩技e族-https://www.playezu.com/179665.html
玩技站长微信
添加好友自动发送入群邀请
weinxin
rainbow-shownow
玩技官方公众号
官方微信公众号
weinxin
PLAYEZU
 
  • 版权提示:本站仅供存储任何法律责任由作者承担▷诈骗举报◁▷新闻不符◁▷我要投稿◁
    风险通知:非原创文章均为网络投稿真实性无法判断,侵权联系2523030730
    免责声明:内容来自用户上传发布或新闻客户端自媒体,切勿!切勿!切勿!添加联系方式以免受骗。
  • 原创转载:https://www.playezu.com/179665.html
    转载说明: 点我前往阅读>>>
匿名

发表评论

匿名网友
确定