自动化

minium+python 进行小程序自动化

2023-02-13  本文已影响0人  花开半夏fly

一、minium框架的简介

minium 是为小程序专门开发的自动化框架,通过config 管理运行设备,通过suite方式管理用例

二、项目目录结构

项目目录结构.jpeg

三、元素定位及页面操作

元素定位及页面操作.png

四、Page Object 模式

1、Page Object 采用分层封装的设计思想,不同层关心不同的问题。
2、页面对象层只关心元素定位问题,测试用例只关心测试的数据。
3、通过对界面元素和功能模块的封装减少冗余代码,在后期维护中,若元素定位或功能模块发生变化,只需要调整页面元素或功能模块封装的代码,显著提高测试用例的可维护性。

五、断言

在测试用例中,执行完测试用例后,判断测试结果是PASS还是Fail


断言.png

六、运行测试用例

1、运行单个用例生成测试报告命令:test.first_test 为单个用例名称

minitest -m test.first_test -c config.json -g

2、测试计划 suite.json,通过suite可以跑多个测试用例,测试用例命名必须包含test
suite.json的pkg_list字段说明要执行用例的内容和顺序,pkg_list是一个数组,每个数组元素是一个匹配规则,会根据pkg去匹配包名,找到测试类,然后再根据case_list里面的规则去查找测试类的测试用例。可以根据需要编写匹配的粒度。注意匹配规则不是正则表达式,而是通配符

{
  "pkg_list": [
    {
      "case_list": [
        "test_*"
      ],
      "pkg": "*_test"
    }
  ]
}

执行命令

minitest -s suite.json -c config.json -g

七、测试报告:

测试结果存储在outputs下,运行命令python3 -m http.server 12345 -d outputs然后在浏览器上访问http://localhost:12345即可查看报告,如图:
或者直接通过命令minitest -s suite.json -c config.json -g也可以生产,通过右键-选择浏览器打开html报告

image.png
测试报告内容:

八、定时跑自动化项目:

1、创建run.sh文件


run.sh.jpg

2、项目里面创建run.py文件,设定时间定时跑项目

import os
import datetime

class CheckService(object):
    def __init__(self):
        pass

    def timerFun(self, sched_Timer):
        flag = 0
        while True:
            now = datetime.datetime.now()
            if now == sched_Timer:
                os.system('/Users/macbookair/Desktop/p8care/run/run.sh')
                flag = 1
            else:
                if flag == 1:
                    # 把hours = 1,改成minutes = 1,就变成了每个小时定时任务,改成days = 1
                    # 就变成每天的定时任务
                    sched_Timer = sched_Timer + datetime.timedelta(days=1)
                    print('run the timer task at {0}'.format(sched_Timer))
                    flag = 0

if __name__ == "__main__":
    cs = CheckService()
    # 每天10点0分会执行任务
    sched_Timer = datetime.datetime(2022, 8, 2, 13, 45)
    print('run the timer task at {0}'.format(sched_Timer))
    cs.timerFun(sched_Timer)


九、参考文档:

1、minium文档:https://minitest.weixin.qq.com/#/minium/Python/readme
2、定时任务文档:
https://developer.aliyun.com/article/642819
https://www.cnblogs.com/royfans/p/7232881.html

上一篇 下一篇

猜你喜欢

热点阅读