一、Python3脚本生成
1.1 安装相关库环境
pip3 install allpairspy
1.2 编写输入文件
编写输入文件,最好是txt文本,格式如下:
浏览器:Chrome,IE,Firefox
操作系统:Windows,Liunx,Mac
插件:RealPlayer,MediaPlayer
1.3 执行命令
将下面脚本文件保存并命令omgtc.py,并在终端执行:
# 直接将结果输出至终端
python3 omgtc.py 文件名称(可包含路径)
# 将结果输出至指定文件
python3 omgtc.py 文件名称(可包含路径) > 文件名称(可包含路径)
例如:
python3 omgtc.py demoinput.txt > demooutput.txt
结果样例:
PAIRWISE:
0: ['Chrome', 'Windows', 'RealPlayer']
1: ['IE', 'Liunx', 'RealPlayer']
2: ['Firefox', 'Mac', 'RealPlayer']
3: ['Firefox', 'Liunx', 'MediaPlayer']
4: ['IE', 'Windows', 'MediaPlayer']
5: ['Chrome', 'Mac', 'MediaPlayer']
6: ['Chrome', 'Liunx', 'MediaPlayer']
7: ['IE', 'Mac', 'MediaPlayer']
8: ['Firefox', 'Windows', 'MediaPlayer']
1.4 脚本内容
omgtc.py
# -*- coding: utf-8 -
from __future__ import print_function
import sys
import re
from allpairspy import AllPairs
def fread(file_name):
# 读取文档写入list
f = open(file_name, "r") # 设置文件对象
data = f.readlines() # 直接将文件中按行读到list里
f.close() # 关闭文件
return data
def parse(data):
# 解析/过滤读取的文件成为可识别格式
parameters = []
for line in data:
a = line.strip('\n') # 去除每行尾的\n
b = a.replace(' ', '') # 去除每行中的所有空格
c = b[b.rfind(':', 1) + 1:] # 去除:前的所有字符
d = c[c.rfind(':', 1) + 1:] # 去除:前的所有字符
e = re.split('[,,]', d) # 根据,或,符号拆分字符
parameters.append(e)
return parameters
def allpairs(parameters):
print("PAIRWISE:")
for i, pairs in enumerate(AllPairs(parameters)):
print("{:2d}: {}".format(i, pairs))
if __name__ == "__main__":
file_name = sys.argv[1]
parameters = parse(fread(file_name))
allpairs(parameters)
二、pairs工具(尝试过mac不可用)
2.1 下载地址:
链接:https://www.satisfice.com/download/allpairs
或者链接:https://pan.baidu.com/s/1v7DzszegtrgEq4ASRNOv1w 密码:21o6
2.2 使用方式
- 解压文件至任意位置
unzip pairs.zip ~/software/
- 写入数据,新建文本,写入参数和可选值,例如:参数A有5中可选值,参数B有3种可选值,参数C有4种可选值,参数D有6种可选值
a b c d a1 b1 c1 d1 a2 b2 c2 d2 a3 b3 c3 d3 a4 c4 d4 a5 d5 d6
- 终端执行命令行
cd ~/software/pairs # 进入工具文件夹 allpairs test.txt>testcase.txt # 指定上述文件名称,以及测试用例文件名称
- 获取用例
其中的~表示使用可以任意值,同样可以保证测试覆盖TEST CASES case a b c d pairings 1 a1 b1 c1 d1 6 2 a2 b2 c2 d1 6 3 a3 b3 c3 d1 6 4 a1 b3 c2 d2 6 5 a2 b1 c1 d2 5 6 a3 b2 c4 d2 6 7 a1 b2 c3 d3 6 8 a2 b3 c4 d3 6 9 a3 b1 c1 d3 5 10 a4 b2 c1 d4 6 11 a5 b1 c2 d4 6 12 a1 b1 c4 d4 4 13 a2 b3 c3 d4 4 14 a4 b1 c3 d5 6 15 a5 b3 c1 d5 6 16 a3 b2 c2 d5 4 17 a4 b3 c2 d6 5 18 a5 b2 c3 d6 5 19 a1 b1 c1 d6 3 20 a4 ~b1 c4 d1 3 21 a5 ~b1 c3 d2 2 22 a5 ~b1 c2 d3 2 23 a1 ~b2 c4 d5 2 24 a2 ~b1 c4 d6 2 25 a5 ~b3 c4 d1 2 26 a4 ~b2 ~c1 d2 1 27 a4 ~b3 ~c1 d3 1 28 a3 ~b3 ~c1 d4 1 29 a2 ~b2 ~c1 d5 1 30 a3 ~b1 ~c2 d6 1