@@ -240,7 +240,20 @@ export class CompleterScenario
240240 tokens . push ( 't' ) ;
241241 text = tokens . join ( '\n' ) ;
242242 }
243- await insertText ( this . jupyterApp , text ) ;
243+ if ( this . useNotebook && this . options . setup . setupCell ) {
244+ await insertText ( this . jupyterApp , this . options . setup . setupCell ) ;
245+ await page . waitForSelector (
246+ '.jp-Notebook-ExecutionIndicator[data-status="idle"]' ,
247+ { state : 'attached' }
248+ ) ;
249+ await this . jupyterApp . commands . execute (
250+ 'notebook:run-cell-and-insert-below'
251+ ) ;
252+ await insertText ( this . jupyterApp , text ) ;
253+ await this . jupyterApp . commands . execute ( 'notebook:enter-edit-mode' ) ;
254+ } else {
255+ await insertText ( this . jupyterApp , text ) ;
256+ }
244257
245258 if ( ! this . useNotebook ) {
246259 // Scroll down a little bit to avoid out of view bug
@@ -268,8 +281,16 @@ export class CompleterScenario
268281 if ( this . useNotebook ) {
269282 // TODO enter a specific cell, not the first cell?
270283 const handle = new ElementHandle ( this . widget ! . node ) ;
271- const editor = await handle . $ ( '.jp-Editor textarea' ) ;
272- await editor ! . focus ( ) ;
284+ const editorSelector = document . querySelector ( '.cm-content' )
285+ ? '.cm-content'
286+ : 'textarea' ;
287+ const editor = this . options ! . setup . setupCell
288+ ? await handle . $ ( `.jp-Cell:nth-child(2) .jp-Editor ${ editorSelector } ` )
289+ : await handle . $ ( `.jp-Editor ${ editorSelector } ` ) ;
290+ if ( ! editor ) {
291+ throw Error ( 'Setup failed: cell editor could not be located' ) ;
292+ }
293+ await editor . focus ( ) ;
273294 }
274295 await layoutReady ( ) ;
275296 await page . press ( 'Tab' ) ;
0 commit comments