|
1 | 1 | // Copyright (c) Jupyter Development Team.
|
2 | 2 | // Distributed under the terms of the Modified BSD License.
|
3 | 3 |
|
4 |
| -import { test } from '@jupyterlab/galata'; |
| 4 | +import { galata, test } from '@jupyterlab/galata'; |
5 | 5 |
|
6 | 6 | import { expect } from '@playwright/test';
|
7 | 7 |
|
8 | 8 | import * as path from 'path';
|
9 | 9 |
|
10 | 10 | test.describe('Widget Visual Regression', () => {
|
11 |
| - test.beforeEach(async ({ page, tmpPath }) => { |
12 |
| - await page.contents.uploadDirectory( |
| 11 | + test.beforeAll(async ({ baseURL, tmpPath }) => { |
| 12 | + const contents = galata.newContentsHelper(baseURL); |
| 13 | + await contents.uploadDirectory( |
13 | 14 | path.resolve(__dirname, './notebooks'),
|
14 | 15 | tmpPath
|
15 | 16 | );
|
16 |
| - await page.dblclick(`text=${tmpPath}`); |
| 17 | + }); |
| 18 | + |
| 19 | + test.beforeEach(async ({ page, tmpPath }) => { |
| 20 | + await page.filebrowser.openDirectory(tmpPath); |
| 21 | + }); |
| 22 | + |
| 23 | + test.afterAll(async ({ baseURL, tmpPath }) => { |
| 24 | + const contents = galata.newContentsHelper(baseURL); |
| 25 | + await contents.deleteDirectory(tmpPath); |
17 | 26 | });
|
18 | 27 |
|
19 | 28 | test('Run notebook widgets.ipynb and capture cell outputs', async ({
|
20 | 29 | page,
|
| 30 | + tmpPath, |
21 | 31 | }) => {
|
22 | 32 | const notebook = 'widgets.ipynb';
|
23 |
| - await page.notebook.open(notebook); |
24 |
| - expect(await page.notebook.isOpen(notebook)).toBeTruthy(); |
| 33 | + await page.notebook.openByPath(`${tmpPath}/${notebook}`); |
25 | 34 | await page.notebook.activate(notebook);
|
26 |
| - expect(await page.notebook.isActive(notebook)).toBeTruthy(); |
27 |
| - |
28 |
| - let numCellImages = 0; |
29 | 35 |
|
30 | 36 | const getCaptureImageName = (id: number): string => {
|
31 |
| - return `cell-${id}`; |
| 37 | + return `cell-${id}.png`; |
32 | 38 | };
|
33 | 39 |
|
| 40 | + const captures = new Array<Buffer>(); |
| 41 | + let numCellImages = 0; |
| 42 | + |
34 | 43 | await page.notebook.runCellByCell({
|
35 | 44 | onAfterCellRun: async (cellIndex: number) => {
|
36 | 45 | const cell = await page.notebook.getCellOutput(cellIndex);
|
37 | 46 | if (cell) {
|
38 |
| - expect(cell.screenshot()).toMatchSnapshot( |
39 |
| - getCaptureImageName(numCellImages) |
40 |
| - ); |
41 |
| - { |
42 |
| - numCellImages++; |
43 |
| - } |
| 47 | + captures.push(await cell.screenshot()); |
| 48 | + numCellImages++; |
44 | 49 | }
|
45 | 50 | },
|
46 | 51 | });
|
| 52 | + |
| 53 | + await page.notebook.save(); |
| 54 | + |
| 55 | + for (let c = 0; c < numCellImages; ++c) { |
| 56 | + expect(captures[c]).toMatchSnapshot(getCaptureImageName(c)); |
| 57 | + } |
47 | 58 | });
|
48 | 59 | });
|
0 commit comments