Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to puppeteer for regression tests #2891

Closed
rgbkrk opened this issue Oct 2, 2017 · 7 comments
Closed

Switch to puppeteer for regression tests #2891

rgbkrk opened this issue Oct 2, 2017 · 7 comments
Milestone

Comments

@rgbkrk
Copy link
Member

rgbkrk commented Oct 2, 2017

PhantomJS is no longer maintained and there is a solid, stable replacement -- chrome headless. In particular, we'd probably want to use puppeteer which has a fairly similar API to casper.

I've done a tiny amount of instrumentation of jupyter notebook using puppeteer and it has been quite nice. I could make a PR but for now I'll just show what I've got:

// The grand fantastic library
const puppeteer = require("puppeteer");

// My brain is 80% RxJS at this point, you'll see how I use it below
const spawnRx = require("spawn-rx");

// Will use this for coloring output
const chalk = require("chalk");

// Operators for use with the spawned notebook server
require("rxjs/add/operator/filter");
require("rxjs/add/operator/share");
require("rxjs/add/operator/toPromise");
require("rxjs/add/operator/first");

async function main() {
  // We could/should generate this, I'm just setting it here to demonstrate
  const TOKEN = "applesaucemcgee";

  const jupyter$ = spawnRx
    .spawn("jupyter", [
      "notebook",
      "--no-browser",
      `--NotebookApp.token='${TOKEN}'`
    ])
    // we keep one jupyter notebook server running, the share operator
    // allows us to subscribe to this stream multiple times while only launching
    // one server for all N subscriptions
    .share();

  // Log everything from the notebook server, dimming it for readability amongst
  // our own output
  const d1 = jupyter$.subscribe(data => console.log(chalk.dim(data)));

  // Wait for the server to be up by waiting for the "Welcome" banner
  await jupyter$
    .filter(x => /Welcome to Project Jupyter/.test(x))
    .first()
    .toPromise();
  // Note that we could have used the above filtering to get the URL of the
  // notebook server -- port, token, and all

  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  try {
    await page.goto(`http://127.0.0.1:8888/tree?token=${TOKEN}`);
  } catch (error) {
    // In case we can't connect to the notebook server, we should exit early
    console.error(error);
    d1.unsubscribe();
    return;
  }

  // Get the version!
  const version = await page.evaluate(() => {
    return Jupyter.version;
  });
  console.log("Jupyter version: ", version);

  // Take a snap!
  await page.screenshot({ path: "example.png" });

  // Clean up!
  await browser.close();
  d1.unsubscribe();
  console.log("cleaned up nicely");
}

main().catch(e => console.error("Main errored", e));

Terminal output:

screen shot 2017-10-02 at 8 34 09 am

Screenshot that was grabbed using the API above:

example

@blink1073
Copy link
Contributor

magic

@blink1073
Copy link
Contributor

Sweet, also available for use in karma tests.

@rgbkrk
Copy link
Member Author

rgbkrk commented Oct 2, 2017

Gosh I wish we were on karma for classic. I can't recall how that went when @jdfreder did some adaptation. Maybe we bit off too much too soon.

I think I'm going to try to adapt the test suite so it mostly fits in with the current way it runs. I should hopefully have it situated enough that people can tackle converting individual test cases in parallel with me.

@rgbkrk
Copy link
Member Author

rgbkrk commented Oct 8, 2017

I've got a branch for this and I'm currently in progress on it, in case folks are wondering. If you'd like to see where things are at or want to join in, please let me know in the comments below.

Also please like and subscribe. #youtube

@takluyver
Copy link
Member

How's the progress coming along? I think this is still blocking your PR #2884.

@rgbkrk
Copy link
Member Author

rgbkrk commented Dec 15, 2017

I haven't been able to carve out time again for this, though I started on it in #3003.

@jtpio
Copy link
Member

jtpio commented Jun 21, 2023

Closing as Notebook 7 developed on the main branch uses Playwright: https://playwright.dev/

@jtpio jtpio closed this as completed Jun 21, 2023
@jtpio jtpio added this to the Reference milestone Jun 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants