-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbyStrategy.js
28 lines (24 loc) · 964 Bytes
/
byStrategy.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
function elementConstructorArgs(context, strategy, args) {
const [selector] = args
args.shift()
const argLength = args.length
const subCall = args[argLength - 2]
const baseElement = args[argLength - 1] || context
return {
selector: {using: strategy, value: selector},
subCall,
baseElement
}
}
function initElement(context, ElementInstance) {
const element = (...args) => new ElementInstance(elementConstructorArgs(context, 'css selector', args))
// find element options
element.css = (...args) => new ElementInstance(elementConstructorArgs(context, 'css', args))
element.xpath = (...args) => new ElementInstance(elementConstructorArgs(context, 'xpath', args))
element.id = (...args) => new ElementInstance(elementConstructorArgs(context, 'id', args))
element.accessibilityId = (...args) => new ElementInstance(elementConstructorArgs(context, 'accessibility id', args))
return element
}
module.exports = {
initElement
}