-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcallWrapper.js
40 lines (32 loc) · 1.11 KB
/
callWrapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const {handledErrors} = require('./interfaceError')
const retryError = 'STALE_ELEMENT_REFERENCE'
async function callWithWrap(that, action, ...rest) {
let driverResp = await action(that.sessionId, ...rest)
const {err, errorType} = handledErrors(driverResp.status)
if(!err) return driverResp.value
if(err && errorType !== retryError) {
err({
sessionId: that.sessionId,
selector: JSON.stringify(that.selector),
additionalMessage: JSON.stringify(driverResp.value),
parentSelector: that.baseElement && JSON.stringify(that.baseElement.selector)
})
} else {
await that.getThisElement(true)
if(typeof rest[0] === 'string') {
rest[0] = that.elementId
}
driverResp = await action(that.sessionId, ...rest)
const {err} = handledErrors(driverResp.status)
if(!err) return driverResp.value
err({
sessionId: that.sessionId,
selector: JSON.stringify(that.selector),
additionalMessage: JSON.stringify(driverResp.value),
parentSelector: that.baseElement && JSON.stringify(that.baseElement.selector)
})
}
}
module.exports = {
callWithWrap
}