手把手教你学会接口自动化系列十六-登录接口的自动化测试,Excel篇

我们在之前也普及了相关的Excel读取数据的相关代码,现在就是正式把这块的内容用于编写登录的代码中,如下:

# !/usr/bin/env python

# -*- coding: utf-8 -*-

# @Time : 2024/01

# @Author : laopi

import json

import os



import openpyxl

import requests



from config.read_json_file import read_json_file

from config.setting import ConfigHandler

from tools.yamlControl import GetYamlData

baseUrl = GetYamlData(ConfigHandler.config_path).get_yaml_data()

root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

case_path = os.path.join(root_path, 'testdata')

os.chdir(case_path) # 修改工作路径

workbook = openpyxl.load_workbook('接口测试用例.xlsx') # 返回一个workbook数据类型的值

sheet =workbook.active

workbook = openpyxl.load_workbook('接口测试用例.xlsx')

workbook._active_sheet_index =0

sheet =workbook.active

url = baseUrl['host']+sheet.cell(row=2,column=2).value

print(url)

print(sheet.max_row) #获取有多少行

for i in range(6,sheet.max_row+1):

headers = json.loads(sheet.cell(i,2).value)

data = json.loads(sheet.cell(i,3).value)

response = requests.post(url=url,

headers=headers,

data=data)

print(response.text)

你可能感兴趣的:(接口自动化测试,linux,运维,服务器,自动化测试,软件测试,自动化,python)