From f59c1edf161a1bc44d103da705911f4a991d2b95 Mon Sep 17 00:00:00 2001 From: Paul Fitzpatrick Date: Mon, 27 Mar 2023 11:54:02 -0400 Subject: [PATCH] (core) start migrating old tests to work with newer selenium Summary: We have an important batch of old browser tests that depend on a pseudo-promise manager selenium's node client used to have. That manager was dropped in v4 (see changelog https://github.com/SeleniumHQ/selenium/blob/trunk/javascript/node/selenium-webdriver/CHANGES.md). I tried porting some wholesale to our newer style of writing tests, and it is a bit of a bear (and would also be hard work to review). So instead I tried something else: remapping the `webdriverjq` implementation to work with mocha-webdriver. This works pretty well. Some API differences are hard to reconcile, but so far most test code just needs async/await changes to port, meaning a lot less thinking, and probably easier to review overall. The important property of the ports tests is that they no longer import or require `selenium-webdriver`. mocha-webdriver depends on selenium-webdriver, but a newer version. I haven't tried dealing with types, since that doesn't matter much - these tests aren't under active development, they are just important for preventing regressions. Follow up work would be porting the remainder of the tests which, while a slog, I'm hoping is no longer a quagmire. Once the tests are ported, I'd propose moving them to `core`. Test Plan: Test porting Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3825 --- test/nbrowser/gristUtils.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/nbrowser/gristUtils.ts b/test/nbrowser/gristUtils.ts index e6366bd1..d7a80764 100644 --- a/test/nbrowser/gristUtils.ts +++ b/test/nbrowser/gristUtils.ts @@ -358,8 +358,17 @@ export async function getVisibleGridCellsFast(colOrOptions: any, rowNums?: numbe export async function getVisibleDetailCells(col: number|string, rows: number[], section?: string): Promise; export async function getVisibleDetailCells(options: IColSelect): Promise; export async function getVisibleDetailCells( - colOrOptions: number|string|IColSelect, _rowNums?: number[], _section?: string + colOrOptions: number|string|IColSelect|IColsSelect, _rowNums?: number[], _section?: string ): Promise { + + if (typeof colOrOptions === 'object' && 'cols' in colOrOptions) { + const {rowNums, section, mapper} = colOrOptions; // tslint:disable-line:no-shadowed-variable + const columns = await Promise.all(colOrOptions.cols.map((oneCol) => + getVisibleDetailCells({col: oneCol, rowNums, section, mapper}))); + // This zips column-wise data into a flat row-wise array of values. + return ([] as T[]).concat(...rowNums.map((r, i) => columns.map((c) => c[i]))); + } + const {col, rowNums, section, mapper = el => el.getText()}: IColSelect = ( typeof colOrOptions === 'object' ? colOrOptions : { col: colOrOptions, rowNums: _rowNums!, section: _section} @@ -483,12 +492,13 @@ export async function getCardCount(): Promise { * Return the .column-name element for the specified column, which may be specified by full name * or index, and may include a section (or will use the active section by default). */ -export function getColumnHeader(colOptions: IColHeader): WebElementPromise { +export function getColumnHeader(colOrColOptions: string|IColHeader): WebElementPromise { + const colOptions = typeof colOrColOptions === 'string' ? {col: colOrColOptions} : colOrColOptions; const {col, section} = colOptions; const sectionElem = section ? getSection(section) : driver.findWait('.active_section', 4000); return new WebElementPromise(driver, typeof col === 'number' ? sectionElem.find(`.column_name:nth-child(${col + 1})`) : - sectionElem.findContent('.column_name', exactMatch(col))); + sectionElem.findContent('.column_name .kf_elabel_text', exactMatch(col)).findClosest('.column_name')); } export async function getColumnNames() {