-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_progress_practical.py
More file actions
239 lines (207 loc) · 8.97 KB
/
test_progress_practical.py
File metadata and controls
239 lines (207 loc) · 8.97 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env python3
"""
Practical Progress Indicator Tester
This script will help you diagnose why the Flow tool's progress percentage isn't displaying.
"""
import os
import time
import json
import logging
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
import sys
# Configure logging
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(levelname)s - %(message)s",
handlers=[
logging.StreamHandler(sys.stdout),
logging.FileHandler("test_progress_practical.log", encoding="utf-8"),
],
)
logger = logging.getLogger(__name__)
def setup_chrome_driver(headless=False):
"""Setup Chrome driver with your profile"""
chrome_options = Options()
if headless:
chrome_options.add_argument("--headless=new")
# Chrome profile path for macOS
profile_dir = os.path.expanduser(
"~/Library/Application Support/Google/Chrome/SeleniumProfile"
)
os.makedirs(profile_dir, exist_ok=True)
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--start-maximized")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_argument(f"--user-data-dir={profile_dir}")
try:
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=chrome_options)
driver.implicitly_wait(10)
driver.execute_script(
"Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"
)
logger.info("Chrome driver setup completed successfully")
logger.info(f"Using profile: {profile_dir}")
return driver
except Exception as e:
logger.error(f"Failed to setup Chrome driver: {e}")
sys.exit(1)
def main():
print("=== Google Flow Progress Indicator Test ===\n")
print("This test will help you diagnose the progress percentage display issue.")
print("Follow these steps carefully:\n")
print("1. Browser will open with your Chrome profile (authenticated)")
print("2. Navigate to the image generation interface")
print("3. Enter a prompt and click Generate manually")
print("4. WHEN YOU SEE THE PROGRESS INDICATOR, press Enter here\n")
input("Press Enter to start the test...")
driver = setup_chrome_driver(headless=False)
try:
# Open Flow project
url = "https://labs.google/fx/tools/flow/project/0bdaaba0-dfa6-42ed-8a3c-e0d760d490b9"
driver.get(url)
WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.TAG_NAME, "body"))
)
logger.info(f"Opened Flow tool: {url}")
input("\n=== Press Enter when you see the progress indicator! ===")
# Diagnose progress indicator
print("\nScanning for progress indicators...")
results = []
# 1. Find elements with percentage characters
logger.info("=== Looking for elements containing '%' ===")
percentage_elements = driver.find_elements(
By.XPATH, "//*[contains(text(), '%')]"
)
for i, elem in enumerate(percentage_elements):
if elem.is_displayed():
info = {
"type": "percentage_text",
"index": i,
"tag": elem.tag_name,
"text": elem.text.strip(),
"class": elem.get_attribute("class"),
"style": elem.get_attribute("style"),
"aria": elem.get_attribute("aria-valuenow"),
"displayed": elem.is_displayed(),
"visible": elem.is_displayed()
and elem.size["width"] > 0
and elem.size["height"] > 0,
}
results.append(info)
logger.debug(f"Found: {json.dumps(info, indent=2)}")
# 2. Find progress bar elements
logger.info("\n=== Looking for progress bars ===")
progress_selectors = [
"//*[@role='progressbar']",
"//*[contains(@class, 'progress')]",
"//*[contains(@class, 'progress-bar')]",
]
for selector in progress_selectors:
try:
elements = driver.find_elements(By.XPATH, selector)
for i, elem in enumerate(elements):
if elem.is_displayed():
info = {
"type": "progress_bar",
"index": i,
"tag": elem.tag_name,
"class": elem.get_attribute("class"),
"style": elem.get_attribute("style"),
"aria": elem.get_attribute("aria-valuenow"),
"text": elem.text.strip(),
"width": elem.size["width"],
"height": elem.size["height"],
}
results.append(info)
logger.debug(f"Found: {json.dumps(info, indent=2)}")
except Exception as e:
logger.debug(f"Error with selector {selector}: {e}")
# 3. Find generation status elements
logger.info("\n=== Looking for generation status ===")
status_selectors = [
"//*[contains(text(), 'Generating')]",
"//*[contains(text(), 'Processing')]",
"//*[contains(@class, 'generating')]",
"//*[contains(@class, 'processing')]",
]
for selector in status_selectors:
try:
elements = driver.find_elements(By.XPATH, selector)
for i, elem in enumerate(elements):
if elem.is_displayed():
info = {
"type": "generation_status",
"index": i,
"tag": elem.tag_name,
"class": elem.get_attribute("class"),
"style": elem.get_attribute("style"),
"text": elem.text.strip(),
}
results.append(info)
logger.debug(f"Found: {json.dumps(info, indent=2)}")
except Exception as e:
logger.debug(f"Error with selector {selector}: {e}")
# Save results
output_file = "progress_analysis.json"
with open(output_file, "w", encoding="utf-8") as f:
json.dump(
{
"timestamp": time.time(),
"total_elements": len(results),
"url": driver.current_url,
"page_title": driver.title,
"analysis": results,
},
f,
indent=2,
ensure_ascii=False,
)
# Take screenshot for debugging
screenshot_file = "progress_screenshot.png"
driver.save_screenshot(screenshot_file)
print(f"\n✅ Analysis complete!")
print(f"📊 Results saved to: {output_file}")
print(f"📸 Screenshot saved to: {screenshot_file}")
# Print summary
print(f"\n=== Summary ===")
print(f"Total elements found: {len(results)}")
percentage_count = sum(1 for r in results if r["type"] == "percentage_text")
progress_count = sum(1 for r in results if r["type"] == "progress_bar")
status_count = sum(1 for r in results if r["type"] == "generation_status")
print(f"• Percentage text elements: {percentage_count}")
print(f"• Progress bar elements: {progress_count}")
print(f"• Generation status elements: {status_count}")
if percentage_count > 0:
print(f"\n=== Percentage Text Elements ===")
for i, r in enumerate(
[r for r in results if r["type"] == "percentage_text"]
):
print(f"Element {i}: '{r['text']}'")
print(f" Class: {r['class']}")
print(f" Tag: {r['tag']}")
input("\nPress Enter to close the browser...")
except Exception as e:
logger.error(f"Test failed: {e}")
import traceback
logger.error(f"Stack trace: {traceback.format_exc()}")
print(f"\nError: {e}")
finally:
driver.quit()
logger.info("Browser closed")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\nTest interrupted by user")
logger.info("Test interrupted")