liumiaomiao 1 рік тому
батько
коміт
7a2bbb5944

+ 0 - 0
cases/未登录功能/链接验证/check_app_search_link.py → cases/未登录功能/链接验证/222.py


+ 25 - 0
cases/未登录功能/链接验证/check_app_search_link_del.py

@@ -0,0 +1,25 @@
+# from hytest import *
+# from lib.linkapi import apilink
+# class T0001:
+#     #测试用例名称
+#     name = "app标讯搜索页验证"
+#     #测试步骤
+#     def teststeps(self):
+#         STEP(1, "访问页面并截取特定区域快照")
+#         # url = 'https://app-a1.jianyu360.cn/jy_mobile/search/middle/bidding'
+#         url = 'https://wx.jianyu360.cn/jy_mobile/search/result/bidding'
+#
+#         #样本快照,每一个链接,快照的名字不一样,要修改
+#         expected_screenshot = 'images/expected_app_search_screenshot.png'
+#         current_screenshot = 'images/current_app_search_screenshot.png'
+#
+#         # 定义要截取的区域
+#         clip = {
+#             'x': 0,
+#             'y': 0,
+#             'width': 1280,  # 根据你的截图实际宽度设置
+#             'height': 600  # 根据你的截图实际高度设置
+#         }
+#         result=apilink.contrast_snapshot(url,expected_screenshot,current_screenshot,clip)
+#
+#         CHECK_POINT("检查app标讯搜索页面是否正常打开", result)

BIN
images/current_app_search_screenshot.png


BIN
images/expected_app_search_screenshot.png


+ 13 - 7
lib/linkapi.py

@@ -15,9 +15,15 @@ class APILink():
         self.playwright.stop()
 
 
-    def save_screenshot(self,url, output_path, clip):
+    def save_screenshot(self,url, output_path, elements, clip=None):
+        locs = []
         self.page.goto(url)
-        self.page.screenshot(path=output_path, clip=clip)
+        for element in elements:
+            loc = self.page.locator(element)
+            locs.append(loc)
+        self.page.screenshot(path=output_path,mask=locs, clip=clip)
+
+
 
     def compare_images(self, image1_path, image2_path):
         image1 = Image.open(image1_path)
@@ -31,13 +37,13 @@ class APILink():
             return False
 
 #对比样本快照与当前快照
-    def contrast_snapshot(self,url,expected_screenshot,current_screenshot,clip):
+    def contrast_snapshot(self,url,expected_screenshot,current_screenshot,element,clip):
         # 如果不存在样本照片,生成样本照片
-        if not os.path.exists(expected_screenshot):
-            self.save_screenshot(url, expected_screenshot, clip)
-            INFO(f"样本快照已保存:{expected_screenshot}")
+        self.save_screenshot(url, expected_screenshot,element,clip)
+        INFO(f"样本快照已保存:{expected_screenshot}")
         #生成对比照片
-        apilink.save_screenshot(url, current_screenshot, clip)
+        apilink.save_screenshot(url, current_screenshot,element,clip)
+        INFO(f"对比快照已保存:{expected_screenshot}")
         #返回对比结果
         result = apilink.compare_images(current_screenshot, expected_screenshot)
         return result