@@ -6,7 +6,7 @@ import type { Telemetry } from '../helpers/telemetry';
66import { beforeTests , afterTests , afterTest } from '../helpers/compass' ;
77import type { Compass } from '../helpers/compass' ;
88import * as Selectors from '../helpers/selectors' ;
9- import type { Element } from 'webdriverio' ;
9+ import type { Element , ElementArray } from 'webdriverio' ;
1010import { createNumbersCollection } from '../helpers/insert-data' ;
1111
1212const { expect } = chai ;
@@ -16,19 +16,31 @@ interface RecentQuery {
1616}
1717
1818async function getRecentQueries (
19- browser : CompassBrowser
19+ browser : CompassBrowser ,
20+ expectQueries = false
2021) : Promise < RecentQuery [ ] > {
2122 const history = await browser . $ ( Selectors . QueryBarHistory ) ;
2223 if ( ! ( await history . isDisplayed ( ) ) ) {
2324 await browser . clickVisible ( Selectors . QueryBarHistoryButton ) ;
2425 await history . waitForDisplayed ( ) ;
2526 }
2627
27- const queryTags = await browser . $$ (
28- '[data-testid="query-history-query-attributes"]'
29- ) ;
28+ let queryTags ;
29+ await browser . waitUntil ( async ( ) => {
30+ queryTags = await browser . $$ (
31+ '[data-testid="query-history-query-attributes"]'
32+ ) ;
33+ // Usually we expect to find some recents and the most common failure is
34+ // that we read out the queries before they are rendered.
35+ if ( expectQueries ) {
36+ // Keep going until we find something or timeout if we never do
37+ return queryTags . length > 0 ;
38+ }
39+ return true ;
40+ } ) ;
41+
3042 return Promise . all (
31- queryTags . map ( async ( queryTag ) => {
43+ ( queryTags as unknown as ElementArray ) . map ( async ( queryTag ) => {
3244 const attributeTags = await queryTag . $$ (
3345 '[data-testid="query-history-query-attribute"]'
3446 ) ;
@@ -138,7 +150,7 @@ describe('Collection documents tab', function () {
138150 used_regex : false ,
139151 } ) ;
140152
141- const queries = await getRecentQueries ( browser ) ;
153+ const queries = await getRecentQueries ( browser , true ) ;
142154 expect ( queries ) . to . deep . include . members ( [ { Filter : '{\n i: 5\n}' } ] ) ;
143155 } ) ;
144156
@@ -168,7 +180,7 @@ describe('Collection documents tab', function () {
168180 used_regex : false ,
169181 } ) ;
170182
171- const queries = await getRecentQueries ( browser ) ;
183+ const queries = await getRecentQueries ( browser , true ) ;
172184 expect ( queries ) . to . deep . include . members ( [
173185 {
174186 Filter : '{\n i: {\n $gt: 5\n }\n}' ,
@@ -215,7 +227,7 @@ describe('Collection documents tab', function () {
215227 const displayText = await documentListActionBarMessageElement . getText ( ) ;
216228 expect ( displayText ) . to . equal ( '1 – 1 of 1' ) ;
217229
218- const queries = await getRecentQueries ( browser ) ;
230+ const queries = await getRecentQueries ( browser , true ) ;
219231 expect ( queries ) . to . deep . include . members ( [
220232 {
221233 Filter : "{\n $where: 'function() { return sleep(10000) || true; }'\n}" ,
0 commit comments