-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_compression_functionality.py
More file actions
52 lines (39 loc) · 1.64 KB
/
Copy pathtest_compression_functionality.py
File metadata and controls
52 lines (39 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from playwright.sync_api import sync_playwright
import os
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
# 导航到PNG压缩页面
page.goto('http://localhost:8085/png-compress/index.html')
page.wait_for_load_state('networkidle')
# 等待TinyPNG加载
page.wait_for_timeout(2000)
# 检查TinyPNG是否加载成功
tinypng_loaded = page.evaluate("() => typeof TinyPNG !== 'undefined'")
print(f"TinyPNG loaded: {tinypng_loaded}")
# 准备测试图片路径
test_image_path = os.path.abspath('docs\favicon.png')
print(f"Testing with image: {test_image_path}")
# 上传图片
file_input = page.locator('#fileInput')
file_input.set_input_files(test_image_path)
# 等待图片上传完成
page.wait_for_timeout(2000)
# 检查是否有图片卡片生成
image_cards = page.locator('.image-card').count()
print(f"Number of image cards: {image_cards}")
if image_cards > 0:
# 点击压缩按钮
compress_button = page.locator('#compressAllBtn')
compress_button.click()
# 等待压缩完成
page.wait_for_timeout(5000)
# 检查压缩状态
status_elements = page.locator('.image-status')
for i in range(status_elements.count()):
status = status_elements.nth(i).text_content()
print(f"Image {i+1} status: {status}")
# 截图
page.screenshot(path='f:\\my_tools\\ImgHLP\\compression_test_screenshot.png')
print("Screenshot saved to compression_test_screenshot.png")
browser.close()