|
@@ -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
|