# -*- coding: utf-8 -*- """ Puzzle/Merge Function Test Script Test flow: 1. Click "Puzzle" in bottom navigation 2. Select 2x2 layout 3. Select 4 images 4. Click "Preview" 5. Confirm merge result 6. Return to main page 7. Enter gallery 8. Check latest merge result """ from airtest.core.api import * from PIL import Image import numpy as np import os # Initialize device def init_device(): dev = connect_device("android://127.0.0.1:5037/emulator-5554") print(f"Device connected: {dev}") return dev # Capture screen def capture_screen(filename="screen.png"): screen = device().snapshot() img = Image.fromarray(screen) img.save(filename) print(f"Screenshot saved: {filename}") return screen # Wait for app launch def wait_app_launch(): print("Waiting for app launch...") sleep(3) # Test 1: Click "Puzzle" tab in bottom navigation def click_merge_tab(): print("Test 1: Click 'Puzzle' tab...") # Bottom navigation: Camera(0), Gallery(1), Puzzle(2), Settings(3) # Click puzzle button at bottom right touch([810, 2300]) sleep(2) capture_screen("01_click_merge.png") print("Clicked puzzle") return True # Test 2: Select 2x2 layout def select_2x2_layout(): print("Test 2: Select 2x2 layout...") touch([180, 200]) sleep(1) capture_screen("02_select_2x2.png") print("Selected 2x2 layout") return True # Test 3: Select 4 images def select_4_images(): print("Test 3: Select 4 images...") # Click add image button (first empty cell) touch([270, 500]) sleep(2) # This will open system image picker capture_screen("03_before_select_image.png") # Click "Gallery" option touch([540, 800]) sleep(1) # Select first image touch([200, 400]) sleep(1) # Second image touch([540, 400]) sleep(1) # Third image touch([880, 400]) sleep(1) # Fourth image touch([200, 700]) sleep(1) # Confirm selection (click OK button) touch([900, 2300]) sleep(2) capture_screen("04_selected_4_images.png") print("Selected 4 images") return True # Test 4: Click preview button def click_preview_button(): print("Test 4: Click preview button...") touch([300, 2200]) sleep(3) capture_screen("05_preview.png") print("Clicked preview") return True # Test 5: Close preview dialog def close_preview(): print("Test 5: Close preview dialog...") touch([540, 1500]) sleep(1) capture_screen("06_preview_closed.png") print("Closed preview") return True # Test 6: Click save button def click_save_button(): print("Test 6: Click save button...") touch([800, 2200]) sleep(2) capture_screen("07_save_dialog.png") return True # Test 7: Confirm save def confirm_save(): print("Test 7: Confirm save...") touch([700, 1400]) sleep(3) capture_screen("08_saved.png") print("Saved") return True # Test 8: Return to home page def go_back_home(): print("Test 8: Return to home page...") touch([100, 100]) sleep(2) capture_screen("09_back_home.png") print("Returned to home") return True # Test 9: Click "Gallery" tab def click_gallery_tab(): print("Test 9: Click 'Gallery' tab...") touch([270, 2300]) sleep(3) capture_screen("10_gallery.png") print("Clicked gallery") return True # Test 10: View latest image def view_latest_image(): print("Test 10: View latest image...") touch([540, 600]) sleep(2) capture_screen("11_latest_image.png") print("Opened latest image") return True # 测试11: 检查图片是否为纯白色 def check_white_image(): print("Test 11: Check if image is pure white...") # 读取截图 img = Image.open("11_latest_image.png") img_array = np.array(img) # 检查是否为纯白色 (RGB都接近255) # 取图片中心区域进行判断 h, w = img_array.shape[:2] center_region = img_array[h//4:3*h//4, w//4:3*w//4] # 计算平均颜色 avg_color = np.mean(center_region, axis=(0, 1)) print(f"Image center average color: {avg_color}") # 判断是否接近白色 (R, G, B 都 > 250) is_white = all(c > 250 for c in avg_color[:3]) if is_white: print("WARNING: Image is pure white, merge function may not work!") else: print("OK: Image is not pure white, merge function works") return not is_white # Main test function def main(): print("=" * 60) print("Puzzle/Merge Function Automated Test") print("=" * 60) try: # Initialize device init_device() # Wait for app launch wait_app_launch() # Execute test steps click_merge_tab() select_2x2_layout() select_4_images() click_preview_button() close_preview() click_save_button() confirm_save() go_back_home() click_gallery_tab() view_latest_image() # Check result result = check_white_image() print("\n" + "=" * 60) if result: print("TEST PASSED! Merge function works normally") else: print("TEST FAILED! Merge result is pure white") print("=" * 60) except Exception as e: print(f"Test error: {e}") import traceback traceback.print_exc() if __name__ == "__main__": main()