-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplay_console_declarations.py
More file actions
137 lines (117 loc) · 4.47 KB
/
Copy pathplay_console_declarations.py
File metadata and controls
137 lines (117 loc) · 4.47 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
#!/usr/bin/env python3
"""Complete Google Play Console App Content declarations via CDP connection to existing Chrome."""
import time
import json
from playwright.sync_api import sync_playwright
from play_artifacts import ARTIFACTS_DIR, screenshot_path
DEVELOPER_ID = "8239620436488925047"
BASE = f"https://play.google.com/console/u/0/developers/{DEVELOPER_ID}"
def safe_click(page, selector, timeout=5000):
try:
el = page.locator(selector).first
el.wait_for(state="visible", timeout=timeout)
el.click()
time.sleep(1.5)
return True
except Exception:
return False
def safe_click_text(page, text, timeout=5000):
try:
el = page.get_by_text(text, exact=False).first
el.wait_for(state="visible", timeout=timeout)
el.click()
time.sleep(1.5)
return True
except Exception:
return False
def save_page(page):
"""Click Save button if present."""
for label in ["Save", "Submit", "Confirm"]:
if safe_click_text(page, label, timeout=3000):
print(f" Clicked '{label}'")
time.sleep(2)
return True
return False
def screenshot(page, name):
path = screenshot_path(f"play_{name}.png")
page.screenshot(path=path)
print(f" Screenshot: {path}")
def main():
with sync_playwright() as p:
print("Connecting to Chrome on port 9222...")
browser = p.chromium.connect_over_cdp("http://localhost:9222")
context = browser.contexts[0]
# Find the Play Console tab or open a new one
play_page = None
for page in context.pages:
if "play.google.com/console" in page.url:
play_page = page
break
if not play_page:
play_page = context.new_page()
play_page.goto(f"{BASE}/app-list", wait_until="networkidle", timeout=60000)
time.sleep(3)
page = play_page
print(f"Current URL: {page.url}")
screenshot(page, "00_start")
# Navigate to app if on app-list
if "app-list" in page.url:
print("Clicking into Random Timer app...")
if safe_click_text(page, "Random Timer"):
time.sleep(3)
screenshot(page, "01_app_dashboard")
# Get current URL to extract app ID
current_url = page.url
print(f"App URL: {current_url}")
# Navigate to App content
print("\n=== Navigating to App Content ===")
if safe_click_text(page, "App content"):
time.sleep(3)
elif safe_click_text(page, "Policy and programs"):
time.sleep(2)
safe_click_text(page, "App content")
time.sleep(3)
screenshot(page, "02_app_content")
print(f"URL: {page.url}")
# List all the declaration sections visible
sections = page.locator("text=/Start|Manage|Complete/i").all()
print(f"\nFound {len(sections)} action items on App Content page")
for i, s in enumerate(sections):
try:
text = s.text_content()
print(f" [{i}] {text}")
except:
pass
# Now let's handle each declaration that shows "Start" or similar
declarations = [
"Data safety",
"Advertising ID",
"Government apps",
"Financial features",
"Health",
"Foreground service",
"Exact alarm",
]
for decl in declarations:
print(f"\n=== Processing: {decl} ===")
# Try to find and click the Start/Manage button next to this section
try:
row = page.locator(f"text={decl}").first
parent = row.locator("..").locator("..")
start_btn = parent.locator("text=/Start|Manage|Update/i").first
start_btn.click()
time.sleep(3)
screenshot(page, f"03_{decl.replace(' ', '_')}")
print(f" Opened {decl} page")
print(f" URL: {page.url}")
except Exception as e:
print(f" Could not open {decl}: {e}")
continue
# Go back to app content for next declaration
page.go_back()
time.sleep(2)
screenshot(page, "99_final")
print(f"\nDone! Check screenshots in {ARTIFACTS_DIR}")
print("Browser left open for manual completion if needed.")
if __name__ == "__main__":
main()