diff --git a/cli/console/fill.ts b/cli/console/fill.ts index 21906a34..1cc7bff2 100644 --- a/cli/console/fill.ts +++ b/cli/console/fill.ts @@ -78,8 +78,10 @@ async function resolve(root: Locator, f: FieldDef): Promise { if (f.names?.length) { let g = await find(root, 'radiogroup', f.names); if (g.state === 'none') g = await find(root, 'group', f.names); - if (g.state !== 'ok') return { field: f, ok: false, seen: g.state !== 'none' }; - scope = g.loc; seen = true; + if (g.state === 'ambiguous') return { field: f, ok: false, seen: true }; + // App Store Connect labels "User Access" with a plain heading, not an ARIA group: then the options are looked up + // in the whole dialog (their own names, e.g. "Full Access", are unique there) + if (g.state === 'ok') { scope = g.loc; seen = true; } } const options: Record = {}; let ok = true; @@ -87,7 +89,8 @@ async function resolve(root: Locator, f: FieldDef): Promise { const r = await find(scope, 'radio', names); if (r.state === 'ok') { options[v] = r.loc; seen = true; } else { ok = false; if (r.state === 'ambiguous') seen = true; } } - return { field: f, ok, seen, ...(f.names?.length ? { loc: scope } : {}), options }; + // loc = the group when the page has one; without it (plain heading) each option is highlighted on its own + return { field: f, ok, seen, ...(scope !== root ? { loc: scope } : {}), options }; } /** The accessible name of a control as the page labels it (what the click gate checks). */ @@ -170,7 +173,7 @@ export interface FillStep { * ambiguous field -> fallback (nothing of that section is touched). Certain answers are set, the rest is highlighted * and left empty. Never clicks Next / Save. `answers` carry the values the page gets (fillValue). */ -export async function fillPage(page: Page, def: FormDef, answers: Answer[], done: Set = new Set()): Promise { +export async function fillPage(page: Page, def: FormDef, answers: Answer[], done: Set = new Set(), partial = false): Promise { const byId = new Map(answers.map(a => [a.id, a])); for (const [i, sec] of def.sections.entries()) { if (done.has(i)) continue; @@ -185,16 +188,20 @@ export async function fillPage(page: Page, def: FormDef, answers: Answer[], done for (const f of sec.fields) rs.push(await resolve(root, f)); if (!sec.dialog && !rs.some(r => r.seen)) continue; const missing = rs.filter(r => !r.ok).map(r => r.field.id); - if (missing.length) return { section: i, title: sec.title, filled: [], highlighted: [], missing, fallback: true }; - const filled: string[] = [], highlighted: string[] = []; + // only when no field of the section can be found is it a UI change; otherwise fill what was found and leave the + // missing fields to the owner (reported as "check") + // (a page still loading can also miss a field for a moment: the caller retries before it passes partial = true) + if (missing.length && (!partial || missing.length === rs.length)) return { section: i, title: sec.title, filled: [], highlighted: [], missing, fallback: true }; + const filled: string[] = [], highlighted: string[] = [...missing]; for (const r of rs) { + if (!r.ok) continue; const a = byId.get(r.field.id); if (!a) continue; const set = a.certain && a.value !== null ? await setField(r, a.value) : false; if (set) filled.push(a.id); else { await mark(r); highlighted.push(a.id); } } done.add(i); - return { section: i, title: sec.title, filled, highlighted, missing: [], fallback: false }; + return { section: i, title: sec.title, filled, highlighted, missing, fallback: false }; } return { section: null, filled: [], highlighted: [], missing: [], fallback: false }; } @@ -634,6 +641,9 @@ export async function fillSession(b: ConsoleBrowser, o: FillSessionOpts): Promis // a page still loading can miss a field for a moment: only a miss that lasts (3 rounds, at least 1.5 s) is a UI change if (s.fallback && (++misses < 3 || Date.now() - firstMiss < 1500)) { if (misses === 1) firstMiss = Date.now(); await Bun.sleep(tick); continue; } misses = 0; + // the miss lasts: fill every field that was found, leave the missing ones to the owner (only all-missing is a UI change) + if (s.fallback) { try { s = await fillPage(p, def, pageAnswers, done, true); } catch { await Bun.sleep(tick); continue; } } + if (!s.fallback && s.missing.length) warn(TAG, `${s.title}: could not find ${s.missing.map(id => labels.get(id) ?? id).join(', ')} on the page (the console UI may have changed): fill ${s.missing.length === 1 ? 'it' : 'them'} yourself`); if (s.fallback) { fallback = true; warn(TAG, `the page does not match what storebound expects (${s.missing.join(', ')}): the console UI changed. Nothing more is filled; follow these steps:`); diff --git a/tests/console-fill.test.ts b/tests/console-fill.test.ts index 0c3f3570..9075c5e0 100644 --- a/tests/console-fill.test.ts +++ b/tests/console-fill.test.ts @@ -225,6 +225,29 @@ describe.skipIf(!browser)('engine (headless, modeled pages)', () => { await page.close(); }); + test('User Access under a plain heading (real App Store Connect): the radios are found in the dialog', async () => { + const page = await open('apple-app-record-heading.html'); + const s = await fillPage(page, formDef('apple-app-record', pageAnswers('apple-app-record')), pageAnswers('apple-app-record')); + expect(s.fallback).toBe(false); + expect(s.missing).toEqual([]); + expect(s.filled).toContain('name'); + expect(await clicks(page)).toEqual([]); + await page.close(); + }); + + test('a lasting partial miss fills every field that was found and leaves only the missing one', async () => { + const page = await open('apple-app-record-renamed.html'); + const def = formDef('apple-app-record', pageAnswers('apple-app-record')); + const s = await fillPage(page, def, pageAnswers('apple-app-record'), new Set(), true); + expect(s.fallback).toBe(false); + expect(s.missing).toEqual(['name']); + expect(s.highlighted).toContain('name'); + expect(s.filled).toContain('bundleId'); + expect(await checked(page, 'iOS')).toBe(true); + expect(await clicks(page)).toEqual([]); + await page.close(); + }); + test('a renamed label stops filling and falls back to guidance', async () => { const page = await open('apple-app-record-renamed.html'); const s = await fillPage(page, formDef('apple-app-record', pageAnswers('apple-app-record')), pageAnswers('apple-app-record')); diff --git a/tests/fixtures/console/apple-app-record-heading.html b/tests/fixtures/console/apple-app-record-heading.html new file mode 100644 index 00000000..95966051 --- /dev/null +++ b/tests/fixtures/console/apple-app-record-heading.html @@ -0,0 +1,23 @@ + + +Apps - App Store Connect + +

Apps

+
+

New App

+
Platforms + + +
+

+

+

+

+
User Access
+ +
+ +
+