diff --git a/ui-tests/tests/timeline-slider.spec.ts b/ui-tests/tests/timeline-slider.spec.ts index 973ea428..330f42e6 100644 --- a/ui-tests/tests/timeline-slider.spec.ts +++ b/ui-tests/tests/timeline-slider.spec.ts @@ -4,39 +4,36 @@ */ import { expect, test } from '@jupyterlab/galata'; +import { Page } from '@playwright/test'; test.describe('Timeline Slider', () => { - test('should not show errors when opening file from path', async ({ page, tmpPath }) => { - await page.notebook.createNew(); - await page.notebook.save(); - await page.notebook.close(); - // Step 1: Click on the "File" menu - await page.click('text=File'); - await page.waitForSelector('.lm-Menu-itemLabel:text("Open from Path…")', { state: 'visible' }); + async function capturePageErrors(page: Page) { + const pageErrors: string[] = []; + page.on('pageerror', (error) => pageErrors.push(error.message)); + return pageErrors; + } - // Step 2: Select "Open from Path..." + async function openNotebook(page: Page, notebookPath: string) { + await page.click('text=File'); await page.click('.lm-Menu-itemLabel:text("Open from Path…")'); + await page.fill( + 'input[placeholder="/path/relative/to/jlab/root"]', + notebookPath + ); + await page.click('.jp-Dialog-buttonLabel:text("Open")'); + await page.waitForSelector('.jp-Notebook', { state: 'visible' }); + } - // Step 3: Enter the path for the notebook - await page.waitForSelector('input[placeholder="/path/relative/to/jlab/root"]'); - await page.fill('input[placeholder="/path/relative/to/jlab/root"]', `${tmpPath}/Untitled.ipynb`); - await page.click('.jp-Dialog-buttonLabel:text("Open")'); + test('should fail if there are console errors', async ({ page, tmpPath }) => { + const pageErrors = await capturePageErrors(page); - await page.waitForSelector('.jp-Notebook', { state: 'visible' }); - - - // Step 6: Assert that no error is thrown - const consoleMessages: any[] = []; - page.on('console', (msg) => { - if (msg.type() === 'error') { - consoleMessages.push(msg.text()); - } - }); - await page.waitForTimeout(1000); + await page.notebook.createNew(); + await page.notebook.save(); + await page.notebook.close(); - // Ensure there are no errors in the console - expect(consoleMessages).toHaveLength(0); + await openNotebook(page, `${tmpPath}/Untitled.ipynb`); + expect(pageErrors).toHaveLength(0); }); });