您好,登錄后才能下訂單哦!
在GUI自動(dòng)化測(cè)試中,截圖和對(duì)比是非常重要的一部分
from PIL import ImageGrab
def take_screenshot():
screenshot = ImageGrab.grab()
screenshot.save("screenshot.png")
import cv2
import numpy as np
from PIL import ImageGrab
def take_screenshot():
screenshot = ImageGrab.grab()
img_np = np.array(screenshot)
cv2.imwrite("screenshot.png", img_np)
from selenium import webdriver
def take_screenshot():
driver = webdriver.Chrome()
driver.get("https://www.example.com")
driver.save_screenshot("screenshot.png")
driver.quit()
import pyautogui
def take_screenshot():
screenshot = pyautogui.screenshot()
screenshot.save("screenshot.png")
import subprocess
def take_screenshot():
subprocess.call(["import", "-window", "root", "screenshot.png"])
import subprocess
def compare_images(image1, image2):
result = subprocess.run(["compare", "-metric", "AE", image1, image2, "diff.png"], capture_output=True, text=True)
return int(result.stdout.strip())
difference = compare_images("image1.png", "image2.png")
print(f"Difference: {difference}")
import cv2
def compare_images(image1, image2):
img1 = cv2.imread(image1)
img2 = cv2.imread(image2)
difference = cv2.absdiff(img1, img2)
return cv2.countNonZero(difference)
difference = compare_images("image1.png", "image2.png")
print(f"Difference: {difference}")
from PIL import Image, ImageChops
def compare_images(image1, image2):
img1 = Image.open(image1)
img2 = Image.open(image2)
diff = ImageChops.difference(img1, img2)
return sum(diff.getdata())
difference = compare_images("image1.png", "image2.png")
print(f"Difference: {difference}")
這些示例展示了如何使用不同的Python庫(kù)進(jìn)行截圖和對(duì)比。你可以根據(jù)你的需求選擇合適的庫(kù)。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。