Browse Source

Use Playwright and Test All Browsers

Afshin T. Darian 4 years ago
parent
commit
484c46db63

+ 4 - 0
.github/workflows/linuxtests.yml

@@ -50,6 +50,9 @@ jobs:
         with:
           node-version: '12.x'
 
+      - name: Setup firefox
+        uses: browser-actions/setup-firefox@latest
+
       - name: Cache pip on Linux
         uses: actions/cache@v2
         if: startsWith(runner.os, 'Linux')
@@ -89,6 +92,7 @@ jobs:
       - name: Run test ${{ matrix.group }}
         env:
           GROUP: ${{ matrix.group }}
+          JLAB_BROWSER_TYPE: firefox
         run: |
           bash ./scripts/ci_script.sh
 

+ 71 - 0
.github/workflows/macostests.yml

@@ -0,0 +1,71 @@
+name: macOS Tests
+
+on: [push, pull_request]
+
+jobs:
+  macostests:
+    name: macOS
+    strategy:
+      matrix:
+        group: [integrity, python, usage, usage2]
+        python: [3.8]
+      fail-fast: false
+    timeout-minutes: 30
+    runs-on: macos-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: Set up Python
+        uses: actions/setup-python@v1
+        with:
+          python-version: ${{ matrix.python }}
+
+      - name: Set up Node
+        uses: actions/setup-node@v1
+        with:
+          node-version: '12.x'
+
+      - name: Setup firefox
+        uses: browser-actions/setup-firefox@latest
+
+      - name: Cache pip on Linux
+        uses: actions/cache@v2
+        if: startsWith(runner.os, 'Linux')
+        with:
+          path: ~/.cache/pip
+          key: ${{ runner.os }}-pip-${{ matrix.python }}-${{ hashFiles('**/requirements.txt', 'setup.py') }}
+          restore-keys: |
+            ${{ runner.os }}-pip-${{ matrix.python }}
+
+      - name: Get yarn cache directory path
+        id: yarn-cache-dir-path
+        run: echo "::set-output name=dir::$(yarn cache dir)"
+      - name: Cache yarn
+        uses: actions/cache@v2
+        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
+        with:
+          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
+          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
+          restore-keys: |
+            ${{ runner.os }}-yarn-
+
+      - name: Cache checked links build
+        uses: actions/cache@v2
+        if: ${{ matrix.group == 'linkcheck' }}
+        with:
+          path: ~/.cache/pytest-link-check
+          key: ${{ runner.os }}-linkcheck-${{ hashFiles('**/*.rst') }}-changelog
+          restore-keys: |
+            ${{ runner.os }}-linkcheck-
+
+      - name: Install dependencies
+        env:
+          GROUP: ${{ matrix.group }}
+        run: |
+          bash ./scripts/ci_install.sh
+
+      - name: Run test ${{ matrix.group }}
+        env:
+          GROUP: ${{ matrix.group }}
+          JLAB_BROWSER_TYPE: webkit
+        run: |
+          bash ./scripts/ci_script.sh

+ 25 - 11
jupyterlab/chrome-test.js → jupyterlab/browser-test.js

@@ -1,9 +1,11 @@
-const puppeteer = require('puppeteer');
+const playwright = require('playwright');
 const inspect = require('util').inspect;
 const path = require('path');
 const fs = require('fs');
 
 const URL = process.argv[2];
+const BROWSER_VAR = 'JLAB_BROWSER_TYPE';
+const BROWSER = process.env[BROWSER_VAR] || 'chromium';
 const OUTPUT_VAR = 'JLAB_BROWSER_CHECK_OUTPUT';
 const OUTPUT = process.env[OUTPUT_VAR];
 
@@ -20,14 +22,18 @@ if (OUTPUT) {
 
 async function main() {
   /* eslint-disable no-console */
-  console.info('Starting Chrome Headless');
+  console.info(`Starting headless ${BROWSER}...`);
 
-  const browser = await puppeteer.launch({
-    headless: true,
-    dumpio: !!OUTPUT,
-    args: ['--no-sandbox']
+  const pwBrowser = playwright[BROWSER];
+  const browser = await pwBrowser.launch({
+    logger: {
+      isEnabled: () => !!OUTPUT,
+      log: (name, severity, message, args) => console.log(name, message)
+    }
   });
-  const page = await browser.newPage();
+
+  const context = await browser.newContext();
+  const page = await context.newPage();
 
   async function screenshot() {
     if (!OUTPUT) {
@@ -51,18 +57,26 @@ async function main() {
   // Wait for the local file to redirect on notebook >= 6.0
   await page.waitForNavigation();
 
+  console.log('Waiting for page content..');
   const html = await page.content();
   if (inspect(html).indexOf('jupyter-config-data') === -1) {
     console.error('Error loading JupyterLab page:');
     console.error(html);
   }
 
-  const el = await page.waitForSelector('#browserTest', { timeout: 100000 });
+  console.log('Waiting for #main selector...');
+  await page.waitForSelector('#main', { timeout: 100000 });
+
+  console.log('Waiting for #browserTest selector...');
+  const el = await page.waitForSelector('#browserTest', {
+    timeout: 100000,
+    state: 'attached'
+  });
   console.log('Waiting for application to start...');
   let testError = null;
 
   try {
-    await page.waitForSelector('.completed');
+    await page.waitForSelector('.completed', { state: 'attached' });
   } catch (e) {
     testError = e;
   }
@@ -82,7 +96,7 @@ async function main() {
   if (testError) {
     throw testError;
   }
-  console.info('Chrome test complete');
+  console.info('Browser test complete');
 }
 
 // Stop the process if an error is raised in the async function.
@@ -90,4 +104,4 @@ process.on('unhandledRejection', up => {
   throw up;
 });
 
-main();
+void main();

+ 11 - 10
jupyterlab/browser_check.py

@@ -152,9 +152,9 @@ async def run_browser(url):
         if not osp.exists(target):
             os.makedirs(osp.join(target))
         await run_async_process(["jlpm", "init", "-y"], cwd=target)
-        await run_async_process(["jlpm", "add", "puppeteer@^7"], cwd=target)
-    shutil.copy(osp.join(here, 'chrome-test.js'), osp.join(target, 'chrome-test.js'))
-    await run_async_process(["node", "chrome-test.js", url], cwd=target)
+        await run_async_process(["jlpm", "add", "playwright@^1.9.2"], cwd=target)
+    shutil.copy(osp.join(here, 'browser-test.js'), osp.join(target, 'browser-test.js'))
+    await run_async_process(["node", "browser-test.js", url], cwd=target)
 
 
 def run_browser_sync(url):
@@ -164,9 +164,9 @@ def run_browser_sync(url):
     if not osp.exists(osp.join(target, 'node_modules')):
         os.makedirs(target)
         subprocess.call(["jlpm", "init", "-y"], cwd=target)
-        subprocess.call(["jlpm", "add", "puppeteer@^7"], cwd=target)
-    shutil.copy(osp.join(here, 'chrome-test.js'), osp.join(target, 'chrome-test.js'))
-    return subprocess.check_call(["node", "chrome-test.js", url], cwd=target)
+        subprocess.call(["jlpm", "add", "playwright@^1.9.2"], cwd=target)
+    shutil.copy(osp.join(here, 'browser-test.js'), osp.join(target, 'browser-test.js'))
+    return subprocess.check_call(["node", "browser-test.js", url], cwd=target)
 
 class BrowserApp(LabApp):
     """An app the launches JupyterLab and waits for it to start up, checking for
@@ -228,10 +228,11 @@ def _jupyter_server_extension_paths():
 
 
 if __name__ == '__main__':
-    skip_option = "--no-chrome-test"
-    if skip_option in sys.argv:
-        BrowserApp.test_browser = False
-        sys.argv.remove(skip_option)
+    skip_options = ["--no-browser-test", "--no-chrome-test"]
+    for option in skip_options:
+        if option in sys.argv:
+            BrowserApp.test_browser = False
+            sys.argv.remove(option)
 
     if "--notebook" in sys.argv:
         from notebook.notebookapp import NotebookApp

+ 2 - 2
scripts/ci_script.sh

@@ -432,7 +432,7 @@ if [[ $GROUP == nonode ]]; then
     virtualenv -p $(which python3) test_install
     ./test_install/bin/pip install -v --pre --no-cache-dir --no-deps jupyterlab --no-index --find-links=dist  # Install latest jupyterlab
     ./test_install/bin/pip install jupyterlab  # Install jupyterlab dependencies
-    ./test_install/bin/python -m jupyterlab.browser_check --no-chrome-test
+    ./test_install/bin/python -m jupyterlab.browser_check --no-browser-test
 
     # Make sure we can start and kill the lab server
     ./test_install/bin/jupyter lab --no-browser &
@@ -446,5 +446,5 @@ if [[ $GROUP == nonode ]]; then
     # Make sure we can install the tarball
     virtualenv -p $(which python3) test_sdist
     ./test_sdist/bin/pip install dist/*.tar.gz
-    ./test_sdist/bin/python -m jupyterlab.browser_check --no-chrome-test
+    ./test_sdist/bin/python -m jupyterlab.browser_check --no-browser-test
 fi