多测师是一家拥有先进的教学理念,强大的师资团队,业内好评甚多的接口自动化测试培训机构!

17727591462

联系电话

您现在所在位置:接口自动化测试培训 > 新闻资讯

API接口测试之脚本

更新时间:2022-07-12 09:03:13 作者:多测师 浏览:40

API接口测试之脚本

  API接口测试脚本

  Excel处理

  # coding:utf-8

  import openpyxl

  from openpyxl import load_workbook

  def write(filename, row, value, sheetname):

  wb = load_workbook(filename)

  # ws = wb.get_active_sheet()

  ws = wb.get_sheet_by_name(sheetname)

  ws[row] = value

  wb.save(filename)

  class ExcelReader:

  def __init__(self, excel_path, sheet_name='sheet1'):

  self.wb = openpyxl.load_workbook(excel_path)

  self.ws = self.wb.get_sheet_by_name(sheet_name)

  # self.ws_current = self.ws.active

  self.rowNum = self.ws.max_row

  self.colNum = self.ws.max_column

  def list_data(self):

  if self.rowNum <= 1:

  print("总行数小于1行")

  else:

  r = []

  # j = 1

  for row in range(2, self.rowNum+1):

  c = self.ws['B'+str(row)].value

  r.append(c)

  return r

  if __name__ == "__main__":

  filepath = "D:\debug_api.xlsx"

  sheetName = "Sheet1"

  data = ExcelReader(filepath, sheetName)

  data_deal = data.list_data()

  print(data_deal)

  print(len(data_deal))

  for i in range(2, len(data_deal)+2):

  write("D:\debug_api.xlsx", 'F'+str(i), 'WRIGHT', '结果-数据')

  API接口

  def get_response():

  """Make an api call, and return the response."""

  url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'

  headers = {'Accept': 'application/vnd.github.v3+json'}

  r = requests.get(url, headers=headers)

  return r

  def get_repo_dicts(r):

  """Return a set of dicts representing the most popular repositories."""

  response_dict = r.json()

  repo_dicts = response_dict['items']

  return repo_dicts

  def get_project_data(repo_dicts):

  """Return data needed for each project in visualization."""

  repo_links, stars, labels = [], [], []

  for repo_dict in repo_dicts:

  repo_name = repo_dict['name']

  repo_url = repo_dict['html_url']

  repo_link = f"{repo_name}"

  repo_links.append(repo_link)

  stars.append(repo_dict['stargazers_count'])

  owner = repo_dict['owner']['login']

  description = repo_dict['description']

  label = f"{owner}

  {description}"

  labels.append(label)

  return repo_links, stars, labels

  if __name__ == '__main__':

  r = get_response()

  repo_dicts = get_repo_dicts(r)

  repo_links, stars, labels = get_project_data(repo_dicts)

  value3 = [['URL', '星星', '标签'], repo_links, stars, labels]

  wt = WriteExcel()

  wt.write_excel('d:\abc.xlsx', '人员信息表', value3)

  print('数据插入完毕')

  以上内容为大家介绍了API接口测试之脚本,本文由多测师亲自撰写,希望对大家有所帮助。了解更多接口测试相关知识:https://www.aichudan.com/xwzx/

联系电话

17727591462

返回顶部