当前位置: 首页 > news >正文

网站建设 请示在百度如何发布作品

网站建设 请示,在百度如何发布作品,鲜花网站模板,漳州最专业的网站建设本节介绍,使用python实现接口自动化实现。 思路:讲接口数据存放在excel文档中,读取excel数据,将每一行数据存放在一个个列表当中。然后获取URL,header,请求体等数据,进行请求发送。 结构如下 excel文档内容如下&#x…

 本节介绍,使用python实现接口自动化实现。

  思路:讲接口数据存放在excel文档中,读取excel数据,将每一行数据存放在一个个列表当中。然后获取URL,header,请求体等数据,进行请求发送。

  结构如下

  

  excel文档内容如下:

  

   一、Common与Config包

  Config里面的config.ini主要存放的默认的路径内容等,如excel文件的地址,工作簿名称

  

   Common里面主要是一些通用的方法,目前只需要读取config里面的数据

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

import configparser

import os.path

#读取config里面的数据

class ReadConfig:

    def __init__(self):

        self.filePath = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))+"\\config\\config.ini"

        print(self.filePath)

        self.config = configparser.ConfigParser()

        self.config.read(self.filePath,encoding='utf-8')

    def get_data(self,section,key):

        return self.config.get(section,key)

    def get_list(self,section):

        return self.config.items(section)

if __name__ == '__main__':

    conf = ReadConfig()

    print(conf.get_data("excel""file_path"))

  二、excel包

  主要是实现读取excel表格数据,此处用的是openpyxl进行实现

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

import openpyxl

class ReadExcel:

    def __init__(self,excel_path,sheet_name):

        self.excel_path = excel_path

        self.sheet_name = sheet_name

    def get_data(self,row):

        workbook = openpyxl.load_workbook(self.excel_path)

        sh = workbook[self.sheet_name]

        data = []

        for in list(sh.rows)[row]:

            data.append(c.value)

        return data

if __name__ == '__main__':

    ex = ReadExcel('request.xlsx','Sheet1')

    print(ex.get_data(0))

    print(ex.get_data(1))

    print(ex.get_data(2))

    print(ex.get_data(3))

    print(ex.get_data(4))

  三、requests包

  主要用于发送请求,这里只写了常用的get post请求,需要可以加其他的。

  由于post请求体有多种,此处只区分了两种,其他的可以加上。

  

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

import json

import requests

class Request:

    def get_url(self,url,headers=None,paras=None):

        if url==None:

            print("URL地址为空")

        elif paras == None:

            = requests.get(url,headers=headers,params=paras)

        else:

            = requests.get(url, headers=headers, params=json.loads(paras))

        return r

    def post_url(self,url,content_type,headers=None,payload=None):

        if url==None:

            print("URL地址为空")

        else:

            if content_type == "application/json":

               payload_json = json.dumps(payload)

               = requests.post(url,headers=headers,data=payload_json)

            elif content_type =="application/x-www-form-urlencoded":

                = requests.post(url,headers=headers,data=payload)

            else:

                print("no this content-type")

            return r

    def choose_method(self,method,url,content_type,headers=None,payload=None):

        if method == "get":

            return self.get_url(url,headers,payload)

        elif method == "post":

            return self.post_url(url,content_type,headers,payload)

        else:

            print("no this method request")

  四、testcases包

  使用pytest框架进行自动化测试

  

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

import json

import pytest

from autoStruct.apiAuto.common.requests import Request

from autoStruct.apiAutoTesting.common.readConfig import ReadConfig

from autoStruct.apiAutoTesting.excel.readExcel import ReadExcel

class TestApi:

    def setup_class(self):

        file_path = ReadConfig().get_data('excel''file_path')

        sheet_name = ReadConfig().get_data('excel''sheet_name')

        self.ex = ReadExcel(file_path, sheet_name)

    @pytest.mark.parametrize('num',[1,2,3,4,5])

    def testcase(self,num):

            data = self.ex.get_data(num)

            print(data)

            if data[3]==None:

                = Request().choose_method(data[1],data[0],data[4],json.loads(data[2]),data[3])

            else:

                = Request().choose_method(data[1], data[0], data[4], json.loads(data[2]), json.loads(data[3]))

            print(r.text)

if __name__ == '__main__':

    pytest.main(['-vs','testapi.py'])

Python接口自动化测试零基础入门到精通(2023最新版)

 

http://www.hkea.cn/news/974578/

相关文章:

  • 为什么要进行网站备案佛山市人民政府门户网站
  • 摄影网站开发背景百度app交易平台
  • 吉林网站建设石家庄百度快照优化排名
  • 大学生网站开发总结报告app推广接单发布平台
  • 自己做的网站怎么推广seo顾问培训
  • 怎么做业务网站百度搜索提交入口
  • 网页设计网站图片西安百度推广运营公司
  • 济南网站开发推广网络服务包括
  • 五星级酒店网站建设关键词歌词表达的意思
  • 浙江高端建设网站网站关键词如何优化
  • 2017网站开发工程师五合一网站建设
  • 学编程的孩子有什么好处seo网站诊断文档案例
  • 广州中新知识城开发建设网站无锡百姓网推广
  • 宝鸡做网站费用关键词你们懂的
  • wordpress 仿站 教程百度竞价点击一次多少钱
  • 做h的游戏 迅雷下载网站百度推广管家
  • 营销型网站建设的目的外贸网站平台都有哪些 免费的
  • 广东做网站公司广州从化发布
  • 能发外链的网站国际新闻今天最新消息
  • 做软件的网站关键词优化快速排名
  • 网站建设与管理简介网站链接交易
  • 英文网站建设教程网盘资源搜索神器
  • 做旅游网站的引言最新网络推广平台
  • 服务器上给网站做301跳转企业网站注册
  • 网站建设好做吗乐事薯片软文推广
  • wordpress 年月归档如何优化培训体系
  • 威海高区建设局网站长春做网络优化的公司
  • 安平做网站百度一下首页百度一下知道
  • 苏州建设网站市政中标项目如何做推广引流赚钱
  • 17网站一起做网店怎么下单来宾网站seo