-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_shared.js
More file actions
72 lines (66 loc) · 2.22 KB
/
Copy path_shared.js
File metadata and controls
72 lines (66 loc) · 2.22 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
/**
* Shared utilities for Play Console adapters.
*/
/** Build the base URL for a specific app in Play Console. */
export function appUrl(devId, appId, section, accIdx = 0) {
return `https://play.google.com/console/u/${accIdx}/developers/${devId}/app/${appId}/${section}`;
}
/**
* Wait for Angular + Play Console to finish loading.
* Play Console is an Angular SPA — we need the main content area to be present.
*/
export async function waitForPlayConsole(page, timeoutMs = 15000) {
// Wait for the Angular app shell to render
await page.waitForFunction(
() => {
const host = document.querySelector('gpc-root, app-root, .console-root');
return host !== null && !document.querySelector('.loading-overlay, gpc-loading-overlay');
},
{ timeout: timeoutMs }
);
// Extra settle time for Angular zone to stabilize
await page.waitForTimeout(1000);
}
/**
* Click the primary Save button in Play Console.
* Tries multiple selector patterns used across different PC pages.
*/
export async function clickSave(page) {
const saveSelectors = [
'button[data-testid="save-button"]',
'button.save-button',
'gpc-button[type="save"] button',
'button:has-text("Save")',
'.action-bar button[color="primary"]',
'mat-toolbar button[color="primary"]',
];
for (const selector of saveSelectors) {
try {
const btn = await page.$(selector);
if (btn) {
const isDisabled = await btn.evaluate(el => el.disabled || el.getAttribute('aria-disabled') === 'true');
if (!isDisabled) {
await btn.click();
await page.waitForTimeout(1500);
return true;
}
}
} catch {
// try next
}
}
// Fallback: evaluate-based click on visible Save button
const clicked = await page.evaluate(() => {
const buttons = Array.from(document.querySelectorAll('button'));
const saveBtn = buttons.find(b =>
(b.textContent?.trim() === 'Save' || b.textContent?.trim() === '保存') &&
!b.disabled &&
b.offsetParent !== null
);
if (saveBtn) { saveBtn.click(); return true; }
return false;
});
if (!clicked) throw new Error('Could not find Save button on the page');
await page.waitForTimeout(1500);
return true;
}