|
| 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 | + startTimeout, |
| 13 | + enableDemoMode |
| 14 | +} = utils.parseCommandLineArguments(args) |
| 15 | + |
| 16 | +const templateName = "JupyterLabs"; |
| 17 | + |
| 18 | +async function runTutorial() { |
| 19 | + const tutorial = new tutorialBase.TutorialBase(url, templateName, user, pass, newUser, enableDemoMode); |
| 20 | + let studyId |
| 21 | + try { |
| 22 | + await tutorial.start(); |
| 23 | + const studyData = await tutorial.openTemplate(1000); |
| 24 | + studyId = studyData["data"]["uuid"]; |
| 25 | + |
| 26 | + const workbenchData = utils.extractWorkbenchData(studyData["data"]); |
| 27 | + await tutorial.waitForServices( |
| 28 | + workbenchData["studyId"], |
| 29 | + [workbenchData["nodeIds"][1], workbenchData["nodeIds"][2]], |
| 30 | + startTimeout, |
| 31 | + false |
| 32 | + ); |
| 33 | + |
| 34 | + await tutorial.waitFor(2000); |
| 35 | + |
| 36 | + for (let j = 1; j < 3; j++) { |
| 37 | + // open JLab |
| 38 | + await tutorial.openNode(j); |
| 39 | + await tutorial.waitFor(35000); |
| 40 | + |
| 41 | + |
| 42 | + // Run the jlab nbook |
| 43 | + const iframeHandles = await tutorial.getIframe(); |
| 44 | + let iframes2 = []; |
| 45 | + for (let i = 0; i < iframeHandles.length; i++) { |
| 46 | + const frame = await iframeHandles[i].contentFrame(); |
| 47 | + iframes2.push(frame); |
| 48 | + } |
| 49 | + const jLabIframe = iframes2.find(iframe => iframe._url.includes(workbenchData["nodeIds"][j])); |
| 50 | + |
| 51 | + const input2outputFileSelector = '[title~="jl_notebook.ipynb"]'; |
| 52 | + await jLabIframe.waitForSelector(input2outputFileSelector); |
| 53 | + await jLabIframe.click(input2outputFileSelector, { |
| 54 | + clickCount: 2 |
| 55 | + }); |
| 56 | + await tutorial.waitFor(5000); |
| 57 | + // click Run Menu |
| 58 | + const mainRunMenuBtnSelector = '#jp-MainMenu > ul > li:nth-child(4)'; // select the Run Menu |
| 59 | + await utils.waitAndClick(jLabIframe, mainRunMenuBtnSelector) |
| 60 | + |
| 61 | + // click Run All Cells |
| 62 | + const mainRunAllBtnSelector = '#jp-mainmenu-run > ul > li:nth-child(12)'; // select the Run |
| 63 | + await utils.waitAndClick(jLabIframe, mainRunAllBtnSelector) |
| 64 | + |
| 65 | + if (j === 2) { |
| 66 | + await tutorial.waitFor(40000); // we are solving an em problem |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | + const outFiles = [ |
| 71 | + "TheNumber.txt", |
| 72 | + "workspace.zip" |
| 73 | + ]; |
| 74 | + await tutorial.checkNodeOutputs(j, outFiles, true, false); |
| 75 | + } |
| 76 | + } |
| 77 | + catch (err) { |
| 78 | + tutorial.setTutorialFailed(true); |
| 79 | + console.log('Tutorial error: ' + err); |
| 80 | + } |
| 81 | + finally { |
| 82 | + await tutorial.toDashboard() |
| 83 | + await tutorial.removeStudy(studyId, 20000); |
| 84 | + await tutorial.logOut(); |
| 85 | + await tutorial.close(); |
| 86 | + } |
| 87 | + |
| 88 | + if (tutorial.getTutorialFailed()) { |
| 89 | + throw "Tutorial Failed"; |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +runTutorial() |
| 94 | + .catch(error => { |
| 95 | + console.log('Puppeteer error: ' + error); |
| 96 | + process.exit(1); |
| 97 | + }); |
0 commit comments