测试用例获取excel用例数据(接口自动化)

 

#获取excel用例数据
def get_case_data():
    case_path = os.path.join(os.path.dirname(__file__), r'files\apiCase.xls')
    book = xlrd.open_workbook(case_path)
    sheet = book.sheet_by_name('sheet1名字')  # excel标签名
    case = []
    for i in range(0, sheet.nrows):
        if sheet.row_values(i)[0] == 'C端登录' and sheet.row_values(i)[3]=='YES':
            case.append(sheet.row_values(i))
    return case

 

 #调用获取测试用例数据
    case_data=get_case_data()
    #使用装饰器参数化用例数据
    @pytest.mark.parametrize('Function,TestCase,Type,Run,URL,Headers,Parameter,SQL1,SQL2,SQL3,AssertType,Expect1,Expect2,Expect3', case_data)
    def test_login1(self,Function,TestCase,Type,Run,URL,Headers,Parameter,SQL1,SQL2,SQL3,AssertType,Expect1,Expect2,Expect3):
        r=requests.post(url=URL,headers=eval(Headers),json=eval(Parameter))
        response=r.json()
        print(response)
        assert eval(Expect1)['code']==response['code']
        assert eval(Expect1)['msg'] == response['msg']


 

来源

posted @ 2023-09-13 16:55  yimu-yimu  阅读(42)  评论(0编辑  收藏  举报