@@ -27,43 +27,55 @@ async function runTutorial() {
27
27
28
28
const workbenchData = utils . extractWorkbenchData ( studyData [ "data" ] ) ;
29
29
await tutorial . waitForServices ( workbenchData [ "studyId" ] , [ workbenchData [ "nodeIds" ] [ 1 ] , workbenchData [ "nodeIds" ] [ 2 ] ] ) ;
30
+ await tutorial . waitFor ( 2000 ) ;
30
31
31
32
// open jupyterNB
32
33
await tutorial . openNode ( 1 ) ;
33
34
34
35
const iframeHandles = await tutorial . getIframe ( ) ;
35
36
const iframes = [ ] ;
36
- for ( let i = 0 ; i < iframeHandles . length ; i ++ ) {
37
+ for ( let i = 0 ; i < iframeHandles . length ; i ++ ) {
37
38
const frame = await iframeHandles [ i ] . contentFrame ( ) ;
38
39
iframes . push ( frame ) ;
39
40
}
40
41
const nbIframe = iframes . find ( iframe => iframe . _url . endsWith ( "tree?" ) ) ;
41
42
42
43
// inside the iFrame, open the first notebook
43
44
const notebookCBSelector = '#notebook_list > div:nth-child(2) > div > input[type=checkbox]' ;
44
- await nbIframe . waitForSelector ( notebookCBSelector ) ;
45
- await nbIframe . click ( notebookCBSelector ) ;
46
- await tutorial . waitFor ( 2000 ) ;
45
+ await utils . waitAndClick ( nbIframe , notebookCBSelector )
47
46
const notebookViewSelector = "#notebook_toolbar > div.col-sm-8.no-padding > div.dynamic-buttons > button.view-button.btn.btn-default.btn-xs"
48
- await nbIframe . waitForSelector ( notebookViewSelector ) ;
49
- await nbIframe . click ( notebookViewSelector ) ;
50
- await tutorial . waitFor ( 2000 ) ;
51
- await tutorial . takeScreenshot ( "openNotebook" ) ;
52
-
53
- // inside the first notebook, click Run button 5 times
54
- const runNBBtnSelector = '#run_int > button:nth-child(1)' ;
55
- const runNotebookTimes = 5 ;
56
- for ( let i = 0 ; i < runNotebookTimes ; i ++ ) {
57
- await nbIframe . waitForSelector ( runNBBtnSelector ) ;
58
- await nbIframe . click ( runNBBtnSelector ) ;
59
- await tutorial . waitFor ( 3000 ) ;
60
- await tutorial . takeScreenshot ( "pressRunNB_" + ( i + 1 ) ) ;
47
+ await utils . waitAndClick ( nbIframe , notebookViewSelector )
48
+
49
+
50
+ // inside the first notebook, click Run all button
51
+ const runAllButtonSelector = '#run_int > button:nth-child(4)' ;
52
+ await utils . waitAndClick ( nbIframe , runAllButtonSelector ) ;
53
+ await tutorial . takeScreenshot ( "pressRunAllButtonNotebook" ) ;
54
+
55
+ // inside the first notebook, click confirm run all (NOTE: this dialog does not appear in headless mode)
56
+ try {
57
+ const confirmRunAllButtonSelector = 'body > div.modal.fade.in > div > div > div.modal-footer > button.btn.btn-default.btn-sm.btn-danger' ;
58
+ await utils . waitAndClick ( nbIframe , confirmRunAllButtonSelector , 10000 ) ;
59
+ await tutorial . takeScreenshot ( "pressRunNotebookAfterConfirmation" ) ;
60
+ } catch ( err ) {
61
+ console . log ( "The confirmation dialog appears only in --demo mode." ) ;
61
62
}
62
63
63
- // TODO: Better check that the kernel is finished
64
- await tutorial . waitFor ( 3000 ) ;
65
64
66
- console . log ( 'Checking results for the notebook:' ) ;
65
+ // now check that the input contains [4]
66
+ console . log ( 'Waiting for notebook results...' ) ;
67
+ const finishedRunningCheckboxSelector = '#notebook-container > div:nth-child(5) > div.input > div.prompt_container > div.prompt.input_prompt' ;
68
+ // the page scrolls down, so first wait so that it becomes visible
69
+ await nbIframe . waitForSelector ( finishedRunningCheckboxSelector ) ;
70
+ await nbIframe . waitForFunction ( 'document.querySelector("' + finishedRunningCheckboxSelector + '").innerText.match(/\[[0-9]+\]/)' ) ;
71
+ await tutorial . takeScreenshot ( "notebookWaitingForNotebookCompleted" ) ;
72
+ console . log ( '...waiting completed' ) ;
73
+ const element = await nbIframe . $ ( finishedRunningCheckboxSelector ) ;
74
+ const value = await nbIframe . evaluate ( el => el . textContent , element ) ;
75
+ console . log ( 'Results for the notebook cell is:' , value ) ;
76
+ // NOTE: we need to wait here to get the results.
77
+ await tutorial . waitFor ( 10000 ) ;
78
+
67
79
await tutorial . openNodeFiles ( 1 ) ;
68
80
const outFiles = [
69
81
"TheNumberNumber.txt" ,
@@ -77,7 +89,7 @@ async function runTutorial() {
77
89
78
90
const iframeHandles2 = await tutorial . getIframe ( ) ;
79
91
const iframes2 = [ ] ;
80
- for ( let i = 0 ; i < iframeHandles2 . length ; i ++ ) {
92
+ for ( let i = 0 ; i < iframeHandles2 . length ; i ++ ) {
81
93
const frame = await iframeHandles2 [ i ] . contentFrame ( ) ;
82
94
iframes2 . push ( frame ) ;
83
95
}
@@ -89,21 +101,23 @@ async function runTutorial() {
89
101
await jLabIframe . click ( input2outputFileSelector , {
90
102
clickCount : 2
91
103
} ) ;
92
- await tutorial . waitFor ( 2000 ) ;
93
-
94
104
// click Run Menu
95
105
const mainRunMenuBtnSelector = '#jp-MainMenu > ul > li:nth-child(4)' ;
96
- await jLabIframe . waitForSelector ( mainRunMenuBtnSelector ) ;
97
- await jLabIframe . click ( mainRunMenuBtnSelector ) ;
98
- await tutorial . waitFor ( 1000 ) ;
106
+ await utils . waitAndClick ( jLabIframe , mainRunMenuBtnSelector )
99
107
100
108
// click Run All Cells
101
109
const mainRunAllBtnSelector = ' body > div.lm-Widget.p-Widget.lm-Menu.p-Menu.lm-MenuBar-menu.p-MenuBar-menu > ul > li:nth-child(17)' ;
102
- await jLabIframe . waitForSelector ( mainRunAllBtnSelector ) ;
103
- await jLabIframe . click ( mainRunAllBtnSelector ) ;
104
- await tutorial . waitFor ( 6000 ) ;
110
+ await utils . waitAndClick ( jLabIframe , mainRunAllBtnSelector )
111
+
112
+ console . log ( 'Waiting for jupyter lab results...' ) ;
113
+ const labCompletedInputSelector = 'div.lm-Widget.p-Widget.jp-MainAreaWidget.jp-NotebookPanel.jp-Document.jp-Activity > div:nth-child(2) > div:nth-child(3) > div.lm-Widget.p-Widget.lm-Panel.p-Panel.jp-Cell-inputWrapper > div.lm-Widget.p-Widget.jp-InputArea.jp-Cell-inputArea > div.lm-Widget.p-Widget.jp-InputPrompt.jp-InputArea-prompt' ;
114
+ await jLabIframe . waitForFunction ( 'document.querySelector("' + labCompletedInputSelector + '").innerText.match(/\[[0-9]+\]/)' ) ;
115
+ const jLabElement = await jLabIframe . $ ( labCompletedInputSelector ) ;
116
+ const jLabVvalue = await jLabIframe . evaluate ( el => el . textContent , jLabElement ) ;
117
+ console . log ( 'Checking results for the jupyter lab cell:' , jLabVvalue ) ;
105
118
await tutorial . takeScreenshot ( "pressRunJLab" ) ;
106
-
119
+ // wait sufficiently before getting the results
120
+ await tutorial . waitFor ( 10000 ) ;
107
121
console . log ( 'Checking results for the jupyter lab:' ) ;
108
122
await tutorial . openNodeFiles ( 2 ) ;
109
123
const outFiles2 = [
0 commit comments