@@ -28,9 +28,9 @@ export function setButtonsInShadowRoot(val: boolean) {
28
28
buttonsInShadowRoot = val ;
29
29
}
30
30
31
- function convertPath ( path : string ) : Array < PathPart > {
31
+ function convertPath ( path : string ) : string {
32
32
let parts = path . split ( / \/ / ) . filter ( ( v ) => ! ! v ) ;
33
- let res : Array < PathPart > = [ ] ;
33
+ let res = [ ] ;
34
34
for ( let part of parts ) {
35
35
let components = part . split ( / \[ | ] / ) . filter ( ( v ) => ! ! v ) ;
36
36
let tagName = components [ 0 ] ;
@@ -44,54 +44,29 @@ function convertPath(path: string): Array<PathPart> {
44
44
} else {
45
45
index = 1 ;
46
46
}
47
- res . push ( { tagName, index } ) ;
47
+ res . push ( ` ${ tagName } :nth-of-type( ${ index } )` ) ;
48
48
}
49
- return res ;
49
+ return res . join ( " " ) ;
50
50
}
51
51
52
- async function shadowRoot ( driver : WebDriver , selector : string ) : Promise < WebElement > {
53
- const el = await driver . findElement ( By . css ( selector ) ) ;
54
- return driver . executeScript ( `return arguments[0].shadowRoot` , el ) ;
52
+ export async function findById ( driver : WebDriver , id : string , isInButtonArea : boolean ) : Promise < WebElement >
53
+ {
54
+ let root = mainRoot ( driver , isInButtonArea ) ;
55
+ if ( config . LOG_DEBUG ) console . log ( "findById selector " , `${ root } .querySelector('#${ id } ')` ) ;
56
+ return await ( driver . executeScript ( `return ${ root } .querySelector('#${ id } ')` ) as Promise < WebElement > )
55
57
}
56
58
57
59
// Fake findByXPath for simple XPath expressions to allow usage with shadow dom
58
60
export async function findByXPath ( driver : WebDriver , path : string , isInButtonArea : boolean ) : Promise < WebElement > {
59
- let root = await mainRoot ( driver , isInButtonArea ) ;
60
61
let paths = convertPath ( path ) ;
61
- let n = root ;
62
+ let root = mainRoot ( driver , isInButtonArea ) ;
62
63
try {
63
- for ( let p of paths ) {
64
- let elem ;
65
- if ( useRowShadowRoot && p . tagName === "tr" ) {
66
- try {
67
- const shadowHost = await shadowRoot ( driver , `benchmark-row:nth-of-type(${ p . index } )` ) ;
68
- elem = await shadowHost . findElement ( By . tagName ( "tr" ) ) ;
69
- if ( elem === null ) {
70
- return null ;
71
- }
72
- } catch ( err ) {
73
- return null ;
74
- }
75
- } else {
76
- let elems = await n . findElements ( By . css ( p . tagName + ":nth-of-type(" + p . index + ")" ) ) ;
77
- if ( elems == null || elems . length == 0 ) {
78
- return null ;
79
- }
80
- elem = elems [ 0 ] ;
81
- }
82
-
83
- n = elem ;
84
- }
64
+ if ( config . LOG_DEBUG ) console . log ( "findByXPath: selector = " , `return ${ root } .querySelector('${ paths } ')` ) ;
65
+ return await driver . executeScript ( `return ${ root } .querySelector('${ paths } ')` )
85
66
} catch ( e ) {
86
67
//can happen for StaleElementReferenceError
87
68
return null ;
88
69
}
89
- return n ;
90
- }
91
-
92
- function elemNull ( v : any ) {
93
- console . log ( "*** ELEMENT WAS NULL" ) ;
94
- return false ;
95
70
}
96
71
97
72
function waitForCondition ( driver : WebDriver ) {
@@ -107,6 +82,7 @@ export async function testTextContains(driver: WebDriver, xpath: string, text: s
107
82
`testTextContains ${ xpath } ${ text } ` ,
108
83
async function ( driver ) {
109
84
try {
85
+ if ( config . LOG_DEBUG ) console . log ( "testTextContains" , xpath ) ;
110
86
let elem = await findByXPath ( driver , xpath , isInButtonArea ) ;
111
87
if ( elem == null ) return false ;
112
88
let v = await elem . getText ( ) ;
@@ -119,8 +95,8 @@ export async function testTextContains(driver: WebDriver, xpath: string, text: s
119
95
) ;
120
96
}
121
97
122
- export function testTextNotContained ( driver : WebDriver , xpath : string , text : string , timeout = config . TIMEOUT , isInButtonArea : boolean ) {
123
- return waitForCondition ( driver ) (
98
+ export async function testTextNotContained ( driver : WebDriver , xpath : string , text : string , timeout = config . TIMEOUT , isInButtonArea : boolean ) {
99
+ return await waitForCondition ( driver ) (
124
100
`testTextNotContained ${ xpath } ${ text } ` ,
125
101
async function ( driver ) {
126
102
try {
@@ -136,8 +112,8 @@ export function testTextNotContained(driver: WebDriver, xpath: string, text: str
136
112
) ;
137
113
}
138
114
139
- export function testClassContains ( driver : WebDriver , xpath : string , text : string , timeout = config . TIMEOUT , isInButtonArea : boolean ) {
140
- return waitForCondition ( driver ) (
115
+ export async function testClassContains ( driver : WebDriver , xpath : string , text : string , timeout = config . TIMEOUT , isInButtonArea : boolean ) {
116
+ return await waitForCondition ( driver ) (
141
117
`testClassContains ${ xpath } ${ text } ` ,
142
118
async function ( driver ) {
143
119
try {
@@ -153,8 +129,8 @@ export function testClassContains(driver: WebDriver, xpath: string, text: string
153
129
) ;
154
130
}
155
131
156
- export function testElementLocatedByXpath ( driver : WebDriver , xpath : string , timeout = config . TIMEOUT , isInButtonArea : boolean ) {
157
- return waitForCondition ( driver ) (
132
+ export async function testElementLocatedByXpath ( driver : WebDriver , xpath : string , timeout = config . TIMEOUT , isInButtonArea : boolean ) {
133
+ return await waitForCondition ( driver ) (
158
134
`testElementLocatedByXpath ${ xpath } ` ,
159
135
async function ( driver ) {
160
136
try {
@@ -168,12 +144,13 @@ export function testElementLocatedByXpath(driver: WebDriver, xpath: string, time
168
144
) ;
169
145
}
170
146
171
- export function testElementNotLocatedByXPath ( driver : WebDriver , xpath : string , timeout = config . TIMEOUT , isInButtonArea : boolean ) {
172
- return waitForCondition ( driver ) (
147
+ export async function testElementNotLocatedByXPath ( driver : WebDriver , xpath : string , timeout = config . TIMEOUT , isInButtonArea : boolean ) {
148
+ return await waitForCondition ( driver ) (
173
149
`testElementNotLocatedByXPath ${ xpath } ` ,
174
150
async function ( driver ) {
175
151
try {
176
152
let elem = await findByXPath ( driver , xpath , isInButtonArea ) ;
153
+ if ( config . LOG_DEBUG ) console . log ( "testElementNotLocatedByXPath" , xpath , elem ) ;
177
154
return elem ? false : true ;
178
155
} catch ( err ) {
179
156
console . log ( "ignoring error in testElementNotLocatedByXPath for xpath = " + xpath , err . toString ( ) . split ( "\n" ) [ 0 ] ) ;
@@ -183,14 +160,15 @@ export function testElementNotLocatedByXPath(driver: WebDriver, xpath: string, t
183
160
) ;
184
161
}
185
162
186
- export function testElementLocatedById ( driver : WebDriver , id : string , timeout = config . TIMEOUT , isInButtonArea : boolean ) {
187
- return waitForCondition ( driver ) (
163
+ export async function testElementLocatedById ( driver : WebDriver , id : string , timeout = config . TIMEOUT , isInButtonArea : boolean ) {
164
+ return await waitForCondition ( driver ) (
188
165
`testElementLocatedById ${ id } ` ,
189
166
async function ( driver ) {
190
167
try {
191
- let elem = await mainRoot ( driver , isInButtonArea ) ;
192
- elem = await elem . findElement ( By . id ( id ) ) ;
193
- return true ;
168
+ let root = mainRoot ( driver , isInButtonArea ) ;
169
+ if ( config . LOG_DEBUG ) console . log ( "testElementLocatedById selector " , `return ${ root } .querySelector('#${ id } ')` ) ;
170
+ let elem = await driver . executeScript ( `return ${ root } .querySelector('#${ id } ')` )
171
+ return ! ! elem ;
194
172
} catch ( err ) {
195
173
// console.log("ignoring error in testElementLocatedById for id = "+id,err.toString().split("\n")[0]);
196
174
}
@@ -212,16 +190,16 @@ export async function retry<T>(retryCount: number, driver: WebDriver, fun: (driv
212
190
213
191
// Stale element prevention. For aurelia even after a testElementLocatedById clickElementById for the same id can fail
214
192
// No idea how that can be explained
215
- export function clickElementById ( driver : WebDriver , id : string , isInButtonArea : boolean ) {
216
- return retry ( 5 , driver , async function ( driver ) {
217
- let elem = await mainRoot ( driver , isInButtonArea ) ;
218
- elem = await elem . findElement ( By . id ( id ) ) ;
193
+ export async function clickElementById ( driver : WebDriver , id : string , isInButtonArea : boolean ) {
194
+ return await retry ( 5 , driver , async function ( driver ) {
195
+ let elem = await findById ( driver , id , isInButtonArea ) ;
196
+ if ( config . LOG_DEBUG ) console . log ( "clickElementById: " , elem ) ;
219
197
await elem . click ( ) ;
220
198
} ) ;
221
199
}
222
200
223
- export function clickElementByXPath ( driver : WebDriver , xpath : string , isInButtonArea : boolean ) {
224
- return retry ( 5 , driver , async function ( driver , count ) {
201
+ export async function clickElementByXPath ( driver : WebDriver , xpath : string , isInButtonArea : boolean ) {
202
+ return await retry ( 5 , driver , async function ( driver , count ) {
225
203
if ( count > 1 && config . LOG_DETAILS ) console . log ( "clickElementByXPath " , xpath , " attempt #" , count ) ;
226
204
let elem = await findByXPath ( driver , xpath , isInButtonArea ) ;
227
205
await elem . click ( ) ;
@@ -238,15 +216,15 @@ export async function getTextByXPath(driver: WebDriver, xpath: string, isInButto
238
216
} ) ;
239
217
}
240
218
241
- export async function mainRoot ( driver : WebDriver , isInButtonArea : boolean ) : Promise < WebElement > {
219
+ export function mainRoot ( driver : WebDriver , isInButtonArea : boolean ) : string {
242
220
if ( useShadowRoot ) {
243
221
if ( ! buttonsInShadowRoot && isInButtonArea ) {
244
- return await driver . findElement ( By . tagName ( " body" ) ) ;
222
+ return "document.querySelector(' body')" ;
245
223
} else {
246
- return shadowRoot ( driver , shadowRootName ) ;
224
+ return `document.querySelector(' ${ shadowRootName } ').shadowRoot`
247
225
}
248
226
} else {
249
- return driver . findElement ( By . tagName ( " body" ) ) ;
227
+ return "document.querySelector(' body')"
250
228
}
251
229
}
252
230
@@ -259,6 +237,7 @@ export function buildDriver(benchmarkOptions: BenchmarkDriverOptions): WebDriver
259
237
let args = [
260
238
"--js-flags=--expose-gc" ,
261
239
"--enable-precise-memory-info" ,
240
+ "--flag-switches-begin" , "--enable-zero-copy" , "--enable-features=RawDraw" , "--flag-switches-end" ,
262
241
// "--enable-gpu-rasterization",
263
242
"--no-first-run" ,
264
243
"--disable-background-networking" ,
0 commit comments