async (page) => { // Open the desired local app, direct HF app, or enclosing Space page first. await page.getByRole('tab', {name:'Compare', exact:true}).waitFor({timeout:10000}).catch(() => {}); const app = page.url().includes('huggingface.co/') ? page.frames().find(frame => frame.url().includes('.hf.space')) : page.mainFrame(); if (!app) throw Error('Space application frame not found'); await app.getByRole('tab', {name:'Compare', exact:true}).click(); const panel = () => app.locator('[role="tabpanel"]:visible'); let button = 'Compare'; const prefix = page.url().includes('127.0.0.1') ? 'local-live' : 'hosted'; async function analyze(count, expected) { await panel().getByRole('button', {name:button, exact:true}).click(); await app.waitForFunction(({count, expected}) => { const frames = Array.from(Array.from(document.querySelectorAll('iframe[id^="vis-"]')).filter(f => f.getBoundingClientRect().height > 0)); return frames.length === count && frames.every(f => f.contentWindow.visualizerDiagnostics?.stage === 'ready' && f.contentDocument.querySelector('#vis svg')?.textContent.includes(expected)); }, {count, expected}, {timeout:60000}); return app.evaluate(() => Array.from(Array.from(document.querySelectorAll('iframe[id^="vis-"]')).filter(f => f.getBoundingClientRect().height > 0), f => ({id:f.id, parserURL:f.contentWindow.visualizerDiagnostics.parserURL, text:f.contentDocument.querySelector('#vis svg').textContent, entities:f.contentWindow.visualizerDiagnostics.data.entities.length, height:f.getBoundingClientRect().height, contentHeight:f.contentDocument.documentElement.scrollHeight}))); } await panel().getByRole('textbox', {name:'Sentence', exact:true}).fill('They buy and sell books.'); const english = await analyze(2, 'They'); const appearance = await app.locator('#vis-model-a').contentFrame().locator('#vis svg').evaluate(svg => ({ background: getComputedStyle(svg.querySelector('.background0')).fill, wordFont: getComputedStyle(svg.querySelector('text')).fontFamily, tagFont: getComputedStyle(svg.querySelector('.span text')).fontFamily, arcFont: getComputedStyle(svg.querySelector('.arcs text')).fontFamily })); const uiFont = await app.locator('.gradio-container').evaluate(el => getComputedStyle(el).fontFamily); if (appearance.background !== 'rgb(255, 255, 255)' || !appearance.wordFont.includes('Liberation Sans') || !appearance.tagFont.includes('PT Sans Caption') || !appearance.arcFont.includes('PT Sans Caption')) throw Error('Incorrect tree background or fonts'); const uiFontLoaded = await app.evaluate(async () => { await document.fonts.ready; return Array.from(document.fonts).some(font => font.family.replace(/['"]/g, '') === 'Source Sans Pro' && font.status === 'loaded'); }); if (!uiFontLoaded) throw Error('Source Sans Pro did not load in the UI'); if (!uiFont.startsWith('"Source Sans Pro"')) throw Error('Incorrect UI font: ' + uiFont); for (const extension of ['svg', 'png']) { const pending = page.waitForEvent('download'); await app.locator('#vis-model-a').contentFrame().getByRole('button', {name:'Download ' + extension.toUpperCase()}).click(); const download = await pending; await download.saveAs('output/playwright/' + prefix + '.' + extension); } await app.getByRole('tab', {name:'Parse', exact:true}).click(); button = 'Parse'; const single = await analyze(1, 'They'); await app.getByRole('tab', {name:'Compare', exact:true}).click(); button = 'Compare'; await panel().getByRole('listbox', {name:'Language', exact:true}).click(); await app.getByRole('option', {name:'German', exact:true}).click(); await app.waitForFunction(() => document.querySelector('input[aria-label="First UDPipe parser"]').value.includes('german-hdt-ud-2.17-251125')); await panel().getByRole('textbox', {name:'Sentence', exact:true}).fill('Bücher überzeugen.'); const german = await analyze(2, 'Bücher'); await panel().getByRole('textbox', {name:'Sentence', exact:true}).fill('Bücher überzeugen uns.'); const repeat = await analyze(2, 'uns'); await page.screenshot({path:'output/playwright/' + prefix + '-page.png', fullPage:true}); if ([...english, ...single, ...german, ...repeat].some(f => !f.parserURL.includes('@e46fe3cb6b1a02190c17c1b792f1f1ded42ddd2f/'))) throw Error('Wrong parser revision'); return {url:page.url(), appearance, uiFont, uiFontLoaded, english, single, german, repeat}; }