@ -456,32 +456,34 @@ export async function rightClick(cell: WebElement) {
* grid view or field name for detail view .
* grid view or field name for detail view .
* /
* /
export async function getCursorPosition() {
export async function getCursorPosition() {
const section = await driver . findWait ( '.active_section' , 4000 ) ;
return await retryOnStale ( async ( ) = > {
const cursor = await section . findWait ( '.active_cursor' , 1000 ) ;
const section = await driver . findWait ( '.active_section' , 4000 ) ;
// Query assuming the cursor is in a GridView and a DetailView, then use whichever query data
const cursor = await section . findWait ( '.active_cursor' , 1000 ) ;
// works out.
// Query assuming the cursor is in a GridView and a DetailView, then use whichever query data
const [ colIndex , rowIndex , rowNum , colName ] = await Promise . all ( [
// works out.
catchNoSuchElem ( ( ) = > cursor . findClosest ( '.field' ) . index ( ) ) ,
const [ colIndex , rowIndex , rowNum , colName ] = await Promise . all ( [
catchNoSuchElem ( ( ) = > cursor . findClosest ( '.gridview_row' ) . index ( ) ) ,
catchNoSuchElem ( ( ) = > cursor . findClosest ( '.field' ) . index ( ) ) ,
catchNoSuchElem ( ( ) = > cursor . findClosest ( '.g_record_detail' ) . find ( '.detail_row_num' ) . getText ( ) ) ,
catchNoSuchElem ( ( ) = > cursor . findClosest ( '.gridview_row' ) . index ( ) ) ,
catchNoSuchElem ( ( ) = > cursor . findClosest ( '.g_record_detail_el' )
catchNoSuchElem ( ( ) = > cursor . findClosest ( '.g_record_detail' ) . find ( '.detail_row_num' ) . getText ( ) ) ,
. find ( '.g_record_detail_label' ) . getText ( ) )
catchNoSuchElem ( ( ) = > cursor . findClosest ( '.g_record_detail_el' )
] ) ;
. find ( '.g_record_detail_label' ) . getText ( ) )
if ( rowNum && colName ) {
] ) ;
// This must be a detail view, and we just got the info we need.
if ( rowNum && colName ) {
return { rowNum : parseInt ( rowNum , 10 ) , col : colName } ;
// This must be a detail view, and we just got the info we need.
} else {
return { rowNum : parseInt ( rowNum , 10 ) , col : colName } ;
// We might be on a single card record
} else {
const counter = await section . findAll ( ".grist-single-record__menu__count" ) ;
// We might be on a single card record
if ( counter . length ) {
const counter = await section . findAll ( ".grist-single-record__menu__count" ) ;
const cardRow = ( await counter [ 0 ] . getText ( ) ) . split ( ' OF ' ) [ 0 ] ;
if ( counter . length ) {
return { rowNum : parseInt ( cardRow ) , col : colName } ;
const cardRow = ( await counter [ 0 ] . getText ( ) ) . split ( ' OF ' ) [ 0 ] ;
return { rowNum : parseInt ( cardRow ) , col : colName } ;
}
// Otherwise, it's a grid view, and we need to use indices to look up the info.
const gridRows = await section . findAll ( '.gridview_data_row_num' ) ;
const gridRowNum = await gridRows [ rowIndex ] . getText ( ) ;
return { rowNum : parseInt ( gridRowNum , 10 ) , col : colIndex } ;
}
}
// Otherwise, it's a grid view, and we need to use indices to look up the info.
} ) ;
const gridRows = await section . findAll ( '.gridview_data_row_num' ) ;
const gridRowNum = await gridRows [ rowIndex ] . getText ( ) ;
return { rowNum : parseInt ( gridRowNum , 10 ) , col : colIndex } ;
}
}
}
/ * *
/ * *
@ -496,6 +498,15 @@ async function catchNoSuchElem(query: () => any) {
}
}
}
}
async function retryOnStale < T > ( query : ( ) = > Promise < T > ) : Promise < T > {
try {
return await query ( ) ;
} catch ( err ) {
if ( err instanceof error . StaleElementReferenceError ) { return await query ( ) ; }
throw err ;
}
}
/ * *
/ * *
* Type keys in the currently active cell , then hit Enter to save , and wait for the server .
* Type keys in the currently active cell , then hit Enter to save , and wait for the server .