Skip to content

Commit

Permalink
✅ Add tests for notebook 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jul 19, 2024
1 parent 1a61e29 commit 2fe4047
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
72 changes: 65 additions & 7 deletions js/ui-tests/examples.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import { expect, test, galata } from "@jupyterlab/galata";
import { setTimeout } from "timers/promises";
import * as path from "path";

// request and tmpPath are Playwright fixtures
test("1-Getting-Started", async ({ page, request, tmpPath }) => {
// Import notebook 1
async function openNotebook(page, request, tmpPath, notebookName) {
const content = galata.newContentsHelper(request);
const filename = "1_Getting_Started.ipynb";
const filename = notebookName;
await content.uploadFile(
path.resolve(__dirname, `../../examples/${filename}`),
`${tmpPath}/${filename}`,
Expand All @@ -22,15 +20,75 @@ test("1-Getting-Started", async ({ page, request, tmpPath }) => {
await page.waitForSelector(
"#jp-main-statusbar >> text=Python 3 (ipykernel) | Idle",
);
}

async function uploadFitsFile(page, request, tmpPath, filePath) {
const content = galata.newContentsHelper(request);
const fitsFileName = path.basename(filePath);
await content.uploadFile(
path.resolve(__dirname, filePath),
`${tmpPath}/${fitsFileName}`,
);
}

// request and tmpPath are Playwright fixtures
test("1_Getting_Started", async ({ page, request, tmpPath }) => {
// Import notebook 1
await openNotebook(page, request, tmpPath, "1_Getting_Started.ipynb");
// Execute all cells
await page.notebook.runCellByCell();
// Wait for Aladin to pop
await setTimeout(3000); // 3s
// Scroll to the top of the notebook
page.notebook.getCellLocator(2);
page.mouse.wheel(0, -2000);
const aladinCell = await page.locator("canvas").nth(1);
// Save
await page.notebook.save();
// And check snapshot (maybe we should clip to div jp-main-dock-panel)
expect(await page.screenshot()).toMatchSnapshot();
expect(await aladinCell.screenshot()).toMatchSnapshot();
});

test("2_Base_Commands", async ({ page, request, tmpPath }) => {
await uploadFitsFile(
page,
request,
tmpPath + "/images/",
"../../examples/images/m31.fits",
);
await openNotebook(page, request, tmpPath, "2_Base_Commands.ipynb");

const aladinCell = await page.locator("canvas").nth(1);

for (let i = 1; i < 7; i++) await page.notebook.runCell(i);
await page.waitForTimeout(1000); // 1s
for (let i = 7; i < 17; i++) await page.notebook.runCell(i);

const targetLocator = await page.notebook.getCellLocator(8);
// expect(await targetLocator.textContent()).toContain(
// "<SkyCoord (ICRS): (ra, dec) in deg\n" +
// " (266.41681663, -29.00782497)>",
// );

const fovLocator = await page.notebook.getCellLocator(11);
expect(await fovLocator.textContent()).toContain("2∘00′00′′");

const cooFrameLocator = await page.notebook.getCellLocator(16);
expect(await cooFrameLocator.textContent()).toContain("'ICRSd'");

// Check first snapshot
// await aladinCell.press("ArrowUp");
// await page.notebook.save();
expect(await aladinCell.screenshot()).toMatchSnapshot();

Check failure on line 80 in js/ui-tests/examples.spec.js

View workflow job for this annotation

GitHub Actions / test

examples.spec.js:50:5 › 2_Base_Commands

1) examples.spec.js:50:5 › 2_Base_Commands ─────────────────────────────────────────────────────── Error: locator.screenshot: Test timeout of 60000ms exceeded. Call log: - taking element screenshot - waiting for fonts to load... - fonts loaded - attempting scroll into view action - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #1 - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #2 - waiting 20ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #3 - waiting 100ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #4 - waiting 100ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #5 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #6 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #7 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #8 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #9 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #10 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #11 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #12 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #13 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #14 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #15 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #16 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #17 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #18 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #19 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #20 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #21 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #22 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #23 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, attempt #24 - waiting 500ms - waiting for element to be stable - element is not visible - retrying scroll into view action, a

for (let i = 18; i < 21; i++) await page.notebook.runCell(i);

// Check second snapshot
// await aladinCell.press("ArrowUp");
expect(await aladinCell.screenshot()).toMatchSnapshot();

// add_fits check
await page.notebook.runCell(22);

// Check third snapshot
// await aladinCell.press("ArrowUp");
expect(await aladinCell.screenshot()).toMatchSnapshot();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2fe4047

Please sign in to comment.