领导要求删除这个文件,在用例执行的时候,直接从外部的excel读取变量文件,于是用python+xlrd写了下,记录下
excel文件
当Excute为Yes时,导入此行的数据。
#coding=utf=8
import xlrd
import json
import sys
import os
reload(sys)
sys.setdefaultencoding("utf-8")
def get_data():
ff = xlrd.open_workbook('EnvronmentVariable.xlsx')
table = ff.sheet_by_index(0)
data = {}
for i in range(1, table.nrows):
if table.cell(i, 1).value != 'Yes':
continue
data['browser'] = str(table.cell(i, 2).value)
data['url'] = str(table.cell(i, 3).value)
data['dbhost'] = str(table.cell(i, 4).value)
data['dbport'] = str(int(table.cell(i, 5).value))
data['dbuser'] = str(table.cell(i, 6).value)
data['dbpassword'] = str(table.cell(i, 7).value)
data['dbapi'] = str(table.cell(i, 8).value)
data['blacksourcetype'] = str((table.cell(i, 9).value))
data['sourcetype'] = str(int(table.cell(i, 10).value))
data['statustype'] = str(int(table.cell(i, 11).value))
data['addnametype'] = str(int(table.cell(i, 12).value))
data['dbuser_con'] = str(table.cell(i, 13).value)
data['dbpwd'] = str(table.cell(i, 14).value)
data['db_ol_portal'] = str(table.cell(i, 15).value)
data['db_ol_portal_pwd'] = str(table.cell(i, 16).value)
return data
if __name__ == '__main__':
print get_data()
需要注意的是,xlrd会把提取出来的数字添加上小数点,所以就直接转成str。
还需要在RF中写一个关键字,然后在suite setup中设置一下就好了