浏览代码

feat: tijiao

liumiaomiao 1 年之前
父节点
当前提交
578a76fe73
共有 2 个文件被更改,包括 25 次插入27 次删除
  1. 15 5
      cases/登录功能/链接验证/check_link_svip_buy.py
  2. 10 22
      lib/linkapi.py

+ 15 - 5
cases/登录功能/链接验证/check_link_svip_buy.py

@@ -2,13 +2,23 @@ from hytest import *
 from lib.linkapi import apilink
 class c1:
     #测试用例名称
-    name='pc超级订阅购买页面能否正常打开'
+    tags=['pc超级订阅购买页面能否正常打开']
     #测试步骤
+    url1 = 'https://www.jianyu360.cn/swordfish/page_big_pc/free/svip/buy'
+    url2 = 'https://wx.jianyu360.cn/jy_mobile/swordfish/newhistorypush'
+    ddt_cases = [
+        {
+            'name': 'pc超级订阅购买页面能否正常打开',
+            'para': url1
+        },
+        {
+            'name': '微信端推送历史记录页面能否正常打开',
+            'para': url2
+        }
+    ]
     def teststeps(self):
-        INFO('测试步骤')
-        url='https://www.jianyu360.cn/swordfish/page_big_pc/free/svip/buy'
-        value='快速链接'
-        result = apilink.check_value_in_source(url,value)
+        url=self.para
+        result = apilink.open_url_status(url)
 
         # 设置检查点
         CHECK_POINT('pc超级订阅购买页面能否正常打开', result)

+ 10 - 22
lib/linkapi.py

@@ -21,28 +21,16 @@ class APILink():
         else:
             return False
 
-    def fetch_page_source(self,url):
-        try:
-            response = requests.get(url)
-            response.raise_for_status()  # 检查请求是否成功
-            return response.text  # 返回网页源代码
-        except requests.RequestException as e:
-            print(f"Error fetching the URL: {e}")
-            return None
-
-    def check_value_in_source(self,url,value):
-        page_source = self.fetch_page_source(url)
-        if page_source:
-            if value in page_source:
-                # print(f"'{value_to_check}' exists in the page source.")
-                return True
-            else:
-                # print(f"'{value_to_check}' does not exist in the page source.")
-                return False
-        else:
-            # print("Failed to retrieve the page source.")
-            return False
-
+    #打开链接,返回页面底部某个值
+    def obtain_url_bottom(self,url,loc):
+        response = requests.get(url)
+        response.encoding = 'utf-8'  # 设置编码为gbk
+        soup = BeautifulSoup(response.text, 'html.parser')
+        # 查找元素并获取值
+        element = soup.find('div', attrs={'class': loc})
+        # element = soup.find(loc)
+        element_value = element.text
+        return element_value
 
     def setup(self):
         # 初始化 Playwright