|
2#
楼主 |
发表于 2017-6-28 11:32:13
|
只看该作者
本帖最后由 小爸爸 于 2017-6-28 11:35 编辑
PageObject
- <p><span style='color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: 0.45px; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 12px; font-style: normal; font-weight: normal; word-spacing: 0px; float: none; display: inline !important; white-space: pre-wrap; orphans: 2; widows: 2; background-color: rgb(249, 249, 249); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px;'>class Login:
- '''
- kwargs:
- path: 用例文件目录
- initPath: 请求头部目录
- '''
- def __init__(self, **kwargs):
- self.path = kwargs["path"] # 用例yaml目录
- self.param = getYam(self.path)["param"] # 请求参数
- self.req = getYam(self.path)["req"] # 请求url
- self.readParam = readParam(self.param) # 读取并处理请求参数
- pairPatchParam(params=self.readParam, paramPath=PATH("../Log/param.log"),
- paramRequestPath=PATH("../Log/paramRequest.log")) # pict生成参数
- self.getParam = readPictParam(paramRequestPath=PATH("../Log/paramRequest.log")) # 得到pict生成的参数
- self.readReq = readReq(self.req) # 0 用例id,1 用例介绍,2 url,3 mehtod
- print(self.readReq)
- self.head = requestHead(kwargs["initPath"]) # initPath 请求头准备
- print(self.head)
- # self.head = requestHead(PATH("../yaml/init.yaml")) # protocol ,header,port,host,title
- '''
- 发请求
- '''
- def operate(self):
- for item in self.getParam:
- param = paramsFilter(item) # 过滤接口,如果有其他加密,可以自行扩展
- f = request(header=self.head["header"], host=self.head["host"], protocol=self.head["protocol"], port=self.head["port"])
- if self.readReq[3] == "POST":
- BaseAsy.asyn(f.post(self.readReq[2], param=param))
- else:
- BaseAsy.asyn(f.get(self.readReq[2], param=param))
- </span>
- </p>
复制代码 test
- <span style='color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: 0.45px; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 12px; font-style: normal; font-weight: normal; word-spacing: 0px; float: none; display: inline !important; white-space: pre-wrap; orphans: 2; widows: 2; background-color: rgb(249, 249, 249); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px;'>from PageObject.PageLogin import Login
- PATH = lambda p: os.path.abspath(
- os.path.join(os.path.dirname(__file__), p)
- )
- class LoginTest(unittest.TestCase):
- def testLogin(self):
- login = Login(path=PATH("../yaml/login.yaml"), initPath=PATH("../yaml/init.yaml"))
- login.operate()
- )
- </span>
复制代码
代码入口实例
- <span style='color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: 0.45px; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 12px; font-style: normal; font-weight: normal; word-spacing: 0px; float: none; display: inline !important; white-space: pre-wrap; orphans: 2; widows: 2; background-color: rgb(249, 249, 249); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px;'>from Base.BaseRunner import ParametrizedTestCase
- from test.TestLogin import LoginTest
- def runnerCase():
- starttime = datetime.now()
- suite = unittest.TestSuite()
- suite.addTest(ParametrizedTestCase.parametrize(LoginTest))
- unittest.TextTestRunner(verbosity=2).run(suite)
- endtime = datetime.now()
- if __name__ == '__main__':
- runnerCase()</span>
复制代码
结果执行过程
- <span style='color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: 0.45px; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 12px; font-style: normal; font-weight: normal; word-spacing: 0px; float: none; display: inline !important; white-space: pre-wrap; orphans: 2; widows: 2; background-color: rgb(249, 249, 249); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px;'>https://XXX post接口参数为:...
- Task ret: {'status_code': 409}
- https://XXX post接口参数为:{}
- {'status_code': 400}
- Task ret: {'status_code': 400}
- https://XXX/login post接口参数为:....
- {'status_code': 200, 'resultCode': 0, 'info': 'Success', '...
- https:/...r/login post接口参数为:{'name': 'XXX', 'pwd': 'XXX'}
- {'status_code': 409}
- ....
- [[{'param': {'XX': 'AAAAAAAAAAAA'}, 'result': {'status_code': 409}, 'url': '/XX/login', 'method': 'POST'}, {'param': {}, 'result': {'status_code': 400}, 'url': '/XX/login', 'method': 'POST'}, {'param': {'name': 'aa', 'XX': 'AAAAAAAAAAAA'}, 'result': {'data': {'resultList': {'token': '5A2EFCE9F0C12EF99D8D18D930D7B71E:8CD9AFC8F3FB5B6B072FAE403A522D9040769B62FB557F90786DF4FFC1AF6356BA269B6E8905197B5B55359D0066146A', 'result': 'success'}}, 'resultCode': 0, 'info': 'Success', 'status_code': 200}, 'url': '/XX/login', 'method': 'POST'}, {'param': {'name': 'aa', 'XX': 'AAAAAAAAAAAA1'}, 'result': {'status_code': 409}, 'url': '/XX/login', 'method': 'POST'}, {'param': {'name': 'aa1', 'XX': 'AAAAAAAAAAAA'}, 'result': {'status_code': 409}, 'url': '/XX/login', 'method': 'POST'}, {'param': {'XX': 'AAAAAAAAAAAA1'}, 'result': {'status_code': 409}, 'url': '/XX/login', 'method': 'POST'}, {'param': {'name': 'aa'}, 'result': {'status_code': 400}, 'url': '/XX/login', 'method': 'POST'}, {'param': {'name': 'aa1'}, 'result': {'status_code': 400}, 'url': '/XX/login', 'method': 'POST'}, {'param': {'name': 'aa1', 'XX': 'AAAAAAAAAAAA1'}, 'result': {'status_code': 409}, 'url': '/XX/login', 'method': 'POST'}]]
- ......
- </span>
复制代码
|
|