Auty自动化测试框架第二篇——读取与执行脚本列表

本文介绍了一个简单的自动化测试框架搭建过程,包括如何通过Python脚本读取待执行脚本列表,并逐一执行这些脚本。该框架初步实现了自动化测试的基础功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[本文出自天外归云的博客园]

在Auty中的文件结构,lib目录下的read_selection.py和execute_selection.py文件:

其中read_selection.py文件的功能是把selection.txt文件中的可执行脚本列表读取并返回:

# -*- coding: utf-8 -*-
import sys
import os

def read_selection():
    path = os.path.abspath(os.path.dirname(__file__))
    parentPath = os.path.dirname(path)
    selectionFilePath = os.path.join(parentPath,'scripts','selection.txt')
    selection = []
    for line in open(selectionFilePath):
        selection.append(line.replace('\n',''))
    return selection

而execute_selection.py文件的功能是把read_selction.py文件返回的列表中包含的脚本在命令行中执行:

# -*- coding: utf-8 -*-
from .read_selection import read_selection
import os

def execute_selection():
    selection = read_selection()
    for scriptPath in selection:
        os.system('python '+scriptPath)

至此就可以在根目录的start.py脚本中执行execute_selection方法来执行所有的脚本文件了:

# -*- coding: utf-8 -*-
from lib.execute_selection import execute_selection

if __name__ == '__main__':
    execute_selection()

一个自动化测试框架至此已经有了骨架,接下来要完善日志收集、生成测试结果文件等功能。

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值