python接口自动化-excel案例

excel案例展示:

python接口自动化-excel案例_第1张图片 1、params和headers实现了参数化

2、获取请求结果,设置为全局变量

3、excel后面的案例使用全局变量。!参数名!形式。

源码如下:

import time
import random
from common.DoGlobal_params import DoGlobalYaml
from common.GetToken import GetToken
import re
globalParams = DoGlobalYaml('global_params.yaml')
class DoChangeParams():
    def __init__(self,params):
        self.params = params

    def doChange(self):
        newParams = self.params
        if '${timeStamp}' in newParams:
            t1 = time.time()
            time_stamp = int(round(t1 * 1000))
            newParams = newParams.replace('${timeStamp}',str(time_stamp))
        if '${productName}' in newParams:
            name = random.randint(100,200)
            newParams = newParams.replace('${productName}','杜麦兜' +

你可能感兴趣的:(自动化,python,pycharm)