Using Galata JupyterLab UI Test Framework With Token / Password Enabled sites

The JupyterLab Galata testing framework seems to rely on testing against unauthenticated sites using a custom JupyterLab config:
jupyterlab/galata at master · jupyterlab/jupyterlab · GitHub

(I note that you can actually run the test against an arbitrary URL / port by setting the TARGET_URL environment variable (eg export TARGET_URL=http://127.0.0.1:8877).

The Galata framework appears to rewrite the playwright goto command to jump through the hoops of waiting for the JupyterLab UI to load:

Setting a test script to try to test the login entry using Galata, before running the rest of the Galata tests then just hangs on the login screen:

await page.goto('http://127.0.0.1:8877/login')
// Galata just hangs here...?

await page.type('input[name="password"]', 'test');
await page.click('text=Enter');

My use case is wanting to test a deployment container which has an authentication step, so I’m not really in a position to rewrite the JupyterLab config script.

(I also note that galata generates video records of the tests. This could easily be co-opted to generate tutorial / walkthrough videos of using JupyterLab, including the login step.)

So my question is: can I configure Galata in such a way that I can include a login step?

PS are there any easy to understand Galata docs / tutorials out there?

1 Like

Cribbing from the jupyterlite repo, I wondered about something like:

import { expect } from '@jupyterlab/galata';
import { test as base } from '@jupyterlab/galata';
const test = base.extend({
  waitForApplication: async ({ baseURL }, use, testInfo) => {
    const waitIsReady = async (page): Promise<void> => {
      await page.waitForSelector('#password_input');
      await page.type('input[name="password"]', 'test');
      await page.click('#login_submit');
     // then have a check that Lab is loaded?
    };
    await use(waitIsReady);
  },
}); 

but this also seems to get stuck before the password entry step?

@psychemedia you will need to override the page to use your own goto in that case. If waitIsReady is not working, the login page does not define the window.jupyterapp global variable expected when goto is triggered (and required to hook galata helpers).

See: jupyterlab/jupyterlabpage.ts at d32ab02c17033482f2ec9f5156f69851e01e3ea7 · jupyterlab/jupyterlab · GitHub

Ah, ok, thanks… Presumably there is no way to override waitForAppStarted. I guess I need to do a simpler, native playwright script to get me through the auth, then invoke the galata script?

It’s a shame that galata can’t be used all the way through - it could be quite a handy tool, eg for test end-user distributions, producing videos, demos, etc.

But if a login hack step is required, so be it …