|
| 1 | +// node jupyters.js [url] [user] [password] [--demo] |
| 2 | + |
| 3 | +const utils = require('../utils/utils'); |
| 4 | +const tutorialBase = require('./tutorialBase'); |
| 5 | + |
| 6 | +const args = process.argv.slice(2); |
| 7 | +const { |
| 8 | + url, |
| 9 | + user, |
| 10 | + pass, |
| 11 | + newUser, |
| 12 | + enableDemoMode |
| 13 | +} = utils.parseCommandLineArguments(args) |
| 14 | + |
| 15 | +const templateName = "Jupyters"; |
| 16 | + |
| 17 | +async function runTutorial() { |
| 18 | + const tutorial = new tutorialBase.TutorialBase(url, user, pass, newUser, templateName, enableDemoMode); |
| 19 | + |
| 20 | + tutorial.init(); |
| 21 | + await tutorial.beforeScript(); |
| 22 | + await tutorial.goTo(); |
| 23 | + |
| 24 | + const needsRegister = await tutorial.registerIfNeeded(); |
| 25 | + if (!needsRegister) { |
| 26 | + await tutorial.login(); |
| 27 | + } |
| 28 | + await tutorial.openTemplate(5000); |
| 29 | + |
| 30 | + // Some time for loading notebook and jupyter lab |
| 31 | + await tutorial.waitFor(30000); |
| 32 | + |
| 33 | + |
| 34 | + // open notebook |
| 35 | + await tutorial.openNode(1); |
| 36 | + |
| 37 | + const iframeHandles = await tutorial.getIframe(); |
| 38 | + // expected two iframes = loading + jupyterNB |
| 39 | + const nbIframe = await iframeHandles[1].contentFrame(); |
| 40 | + |
| 41 | + // inside the iFrame, open the first notebook |
| 42 | + const notebookCBSelector = '#notebook_list > div:nth-child(2) > div > input[type=checkbox]'; |
| 43 | + await nbIframe.waitForSelector(notebookCBSelector); |
| 44 | + await nbIframe.click(notebookCBSelector); |
| 45 | + await tutorial.waitFor(2000); |
| 46 | + const notebookViewSelector = "#notebook_toolbar > div.col-sm-8.no-padding > div.dynamic-buttons > button.view-button.btn.btn-default.btn-xs" |
| 47 | + await nbIframe.waitForSelector(notebookViewSelector); |
| 48 | + await nbIframe.click(notebookViewSelector); |
| 49 | + await tutorial.waitFor(2000); |
| 50 | + await tutorial.takeScreenshot("openNotebook"); |
| 51 | + |
| 52 | + // inside the first notebook, click Run button 4 times |
| 53 | + const runNBBtnSelector = '#run_int > button:nth-child(1)'; |
| 54 | + const runNotebookTimes = 5; |
| 55 | + for (let i=0; i<runNotebookTimes; i++) { |
| 56 | + await nbIframe.waitForSelector(runNBBtnSelector); |
| 57 | + await nbIframe.click(runNBBtnSelector); |
| 58 | + await tutorial.waitFor(3000); |
| 59 | + await tutorial.takeScreenshot("pressRunNB_" + i+1); |
| 60 | + } |
| 61 | + |
| 62 | + await tutorial.retrieve(); |
| 63 | + |
| 64 | + console.log('Checking results for the notebook:'); |
| 65 | + await tutorial.openNodeFiles(1); |
| 66 | + const outFiles = [ |
| 67 | + "TheNumberNumber.txt", |
| 68 | + "notebooks.zip" |
| 69 | + ]; |
| 70 | + await tutorial.checkResults(outFiles.length); |
| 71 | + |
| 72 | + |
| 73 | + // open jupyter lab |
| 74 | + await tutorial.openNode(2); |
| 75 | + |
| 76 | + await tutorial.retrieve(); |
| 77 | + |
| 78 | + const iframeHandles2 = await tutorial.getIframe(); |
| 79 | + // expected three iframes = loading + jupyterNB + jupyterLab |
| 80 | + const jLabIframe = await iframeHandles2[2].contentFrame(); |
| 81 | + |
| 82 | + // inside the iFrame, open the first notebook |
| 83 | + const workFolderSelector = '#filebrowser > div.lm-Widget.p-Widget.jp-DirListing.jp-FileBrowser-listing.jp-DirListing-narrow > ul > li:nth-child(3)'; |
| 84 | + await jLabIframe.waitForSelector(workFolderSelector); |
| 85 | + await jLabIframe.click(workFolderSelector, { |
| 86 | + clickCount: 2 |
| 87 | + }); |
| 88 | + await tutorial.waitFor(2000); |
| 89 | + |
| 90 | + const input2outputFileSelector = '#filebrowser > div.lm-Widget.p-Widget.jp-DirListing.jp-FileBrowser-listing.jp-DirListing-narrow > ul > li:nth-child(1)'; |
| 91 | + await jLabIframe.waitForSelector(input2outputFileSelector); |
| 92 | + await jLabIframe.click(input2outputFileSelector, { |
| 93 | + clickCount: 2 |
| 94 | + }); |
| 95 | + await tutorial.waitFor(2000); |
| 96 | + |
| 97 | + // click Run Menu |
| 98 | + const mainRunMenuBtnSelector = '#jp-MainMenu > ul > li:nth-child(4)'; |
| 99 | + await jLabIframe.waitForSelector(mainRunMenuBtnSelector); |
| 100 | + await jLabIframe.click(mainRunMenuBtnSelector); |
| 101 | + await tutorial.waitFor(1000); |
| 102 | + |
| 103 | + // click Run All Cells |
| 104 | + const mainRunAllBtnSelector = ' body > div.lm-Widget.p-Widget.lm-Menu.p-Menu.lm-MenuBar-menu.p-MenuBar-menu > ul > li:nth-child(17)'; |
| 105 | + await jLabIframe.waitForSelector(mainRunAllBtnSelector); |
| 106 | + await jLabIframe.click(mainRunAllBtnSelector); |
| 107 | + await tutorial.waitFor(6000); |
| 108 | + await tutorial.takeScreenshot("pressRunJLab"); |
| 109 | + |
| 110 | + |
| 111 | + await tutorial.removeStudy(); |
| 112 | + await tutorial.logOut(); |
| 113 | + await tutorial.close(); |
| 114 | +} |
| 115 | + |
| 116 | +runTutorial() |
| 117 | + .catch(error => { |
| 118 | + console.log('Puppeteer error: ' + error); |
| 119 | + process.exit(1); |
| 120 | + }); |
0 commit comments