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

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

在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()

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

 
posted @ 2016-09-28 18:39  天外归云  阅读(2614)  评论(0编辑  收藏  举报