def setUpClass(cls): cls.obj = None if datadriven.runtype == 'WEB': cls.obj = Browser(datadriven.writer) if datadriven.runtype == 'APP': cls.obj = APP(datadriven.writer) if datadriven.runtype == 'HTTP': cls.obj = HTTP(datadriven.writer) if datadriven.runtype == 'SOAP': cls.obj = SOAP(datadriven.writer)
func(line[4],line[5]) return if len(args) == 3: func(line[4],line[5],line[6]) return print('warning:目前只支持三个关键字调用') reader = Reader() reader.open_excel('./lib/cases/basic接口测试用例.xls') sheetname = reader.get_sheets() writer = Writer() writer.copy_open('./lib/cases/basic接口测试用例.xls', './lib/results/result-basic接口测试用例.xls') http = HTTP(writer) # 测试开始时间 writer.set_sheet(sheetname[0]) startTime = str(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) writer.write(1,3,str(startTime)) for sheet in sheetname: # 设置当前读取的sheet页面 reader.set_sheet(sheet) # 设置写的sheet页,保持读和写是同一个sheet writer.set_sheet(sheet) for i in range(reader.rows): writer.row = i line = reader.readline() runcase(line) # 写入结束时间 endTime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
import unittest, datetime, time
from interface.inter import HTTP #构建关键字驱动对象 http = HTTP() #登录前奏(授权) http.post('http://112.74.191.10/inter/HTTP/auth') #断言是否授权 http.assertequals('status', '200') #保存token http.savejson('token', 't') #关联token信息 http.addheader('token', '{t}') #登录 http.post('http://112.74.191.10/inter/HTTP/login', d="{'username':'******','password':'******'}") http.assertequals('status', '200') http.savejson('userid', 'userid') #获取用户信息 http.post('http://112.74.191.10/inter/HTTP/getuserinfo', id='id={userid}') http.post('http://112.74.191.10/inter/HTTP/logout') http.assertequals('status', '200')
#coding:utf-8 from interface.inter import HTTP import random http = HTTP() http.postJson('http://112.74.191.10:8081/inter/HTTP/auth') http.assertequals('status','200') http.savaJson('token','t') http.addheader('token','{t}') # 3、登录 # # d={'username':'******','password':'******'} # 这种也可以 http.postJson('http://112.74.191.10:8081/inter/HTTP/login',d= 'username=Ronnie2658&password=123456') http.assertequals('status',200) # 4、获取用户信息 http.savaJson('userid','id') # savaJson(self,key,p)中self.param[p] = self.jsonres[key],即保存的参数id2为键,userid为上一个请求返回的json的键 # print("保存的参数",http.param) # 注意这时候param中保存了多个参数了,这样,如果下个请求需要多个参数,直接使用即可 # 这里d='id={id2}',其中id2必须与上一步http.savaJson('userid','id2')的id2保持一致,因为 postJson中调用__get_param(self, s)方法,它是遍历已经保存的参数,并将传入的字符串里面,满足{key}所有字符串用key对应的值来替换,如无,则不替换 http.postJson(url='http://testingedu.com.cn/inter/HTTP/getUserInfo',d='id={id}') http.assertequals('status',200) # 5、退出登陆 http.postJson('http://112.74.191.10:8081/inter/HTTP/logout') # print(http.jsonres) http.assertequals('status',200)