فهرست منبع

小程序用户登录/退出

jialuyao 7 ماه پیش
والد
کامیت
37789e844c
3فایلهای تغییر یافته به همراه107 افزوده شده و 0 حذف شده
  1. 20 0
      cases/wxapi/login_wxapi.py
  2. 8 0
      cases/wxapi/登录/__st__.py
  3. 79 0
      lib/wxapi.py

+ 20 - 0
cases/wxapi/login_wxapi.py

@@ -0,0 +1,20 @@
+from hytest import *
+from lib.wxapi import apimgr
+class c1:
+    #测试用例名称
+    name='小程序登录接口验证'
+    #测试步骤
+    def teststeps(self):
+        INFO('测试步骤')
+        STEP(1,'打印接口返回值')    #会出现在测试报告中
+        r = apimgr.mgr_login_wxapi()
+        res = r.json()
+        INFO(res)
+        actural = res['data']['status']
+        STEP(2,'第二步设置检查点')
+        #设置检查点
+        CHECK_POINT('检查app登录接口是否正常',actural == 1)
+    #清除方法
+    def teardown(self):
+        INFO('用户退出app')
+        apimgr.mgr_logout_wxapi()

+ 8 - 0
cases/wxapi/登录/__st__.py

@@ -0,0 +1,8 @@
+from hytest import *
+from lib.wxapi import apimgr
+def suite_setup():
+    INFO('用户登录')
+    apimgr.mgr_login_wxapi()
+def suite_teardown():
+    INFO('用户退出')
+    apimgr.mgr_logout_wxapi()

+ 79 - 0
lib/wxapi.py

@@ -0,0 +1,79 @@
+import json
+import requests
+from hytest.common import *
+from cfg import cfg
+from bs4 import BeautifulSoup
+from requests.packages import urllib3
+
+#存放公用方法
+# 存储 全局共享 数据
+GSTORE = {}
+class APIMgr():
+    #打印https请求与消息
+    def __init__(self):
+        self.ui = None
+        self.token = None
+
+    def printRequest(self,req):
+        if req.body==None:
+            msgBody=''
+        else:
+            msgBody=req.body
+        self.ui.outputWindow.append(
+            '{}\n{}\n{}\n\n{}'.format(
+                '\n\n-------发送请求--------',
+                req.method+''+req.url,
+                '\n'.join('{}:{}'.format(k,v) for k,v in req.headers.items()),
+                msgBody,
+            ))
+
+    # 打印http相应消息的函数
+    def printResponse(self, response):
+        print('\n\n----- https response begin    -----')
+        print(response.status_code)
+        # print(response.headers)
+        for k, v in response.headers.items():
+            print(f'{k}:{v}')
+
+        print(response.content.decode('utf8'))
+        print('----- https response end-----\n\n')
+
+
+    headers = {
+        'Accept-Charset':'utf-8',
+        'Accept':'*/*',
+        'Accept-Encoding':'gzip, deflate, br',
+        'User-Agent':'Apifox/1.0.0 (https://apifox.com)',
+        'Content-Type':'application/json',
+         'MiniprogramCode':'wy_zbxm'
+    }
+
+    #headers设置为全局变量
+    GSTORE['headers'] = headers
+    # session对象设置为全局变量
+    s = requests.Session()
+    GSTORE['s'] = s
+
+    # 小程序登录接口
+    def mgr_login_wxapi(self, useproxies=False):
+        headers=GSTORE['headers']
+        s = GSTORE['s']
+        if useproxies:
+            self.s.proxies.update({'http':'127.0.0.1:8888'})
+        response = self.s.post(f"{cfg.target_host_wxapi}/debrisproduct/free/autologin",headers=headers,json=
+                                    {
+                                     'phone':'15037870765',
+                                     'token':'8817684142977367381'
+                                    })
+        self.printResponse(response)
+        # 把response对象返回出去
+        return response
+
+    """退出登录小程序"""
+    def mgr_logout_wxapi(self):
+        url = f"{cfg.target_host_wxapi}/debrisproduct/logout"
+        headers = GSTORE['headers']
+        s = GSTORE['s']
+        s.post(url=url, headers=headers)
+
+apimgr = APIMgr()