* @param {CodeceptJS.LocatorOrString} locator * @param {string} [defaultType]
(locator, defaultType = '')
| 13 | * @param {string} [defaultType] |
| 14 | */ |
| 15 | constructor(locator, defaultType = '') { |
| 16 | this.type = null |
| 17 | if (!locator) return |
| 18 | |
| 19 | this.output = null |
| 20 | |
| 21 | /** |
| 22 | * @private |
| 23 | * @type {boolean} |
| 24 | */ |
| 25 | this.strict = false |
| 26 | |
| 27 | if (typeof locator === 'object') { |
| 28 | if (locator.constructor.name === 'Locator') { |
| 29 | Object.assign(this, locator) |
| 30 | return |
| 31 | } |
| 32 | |
| 33 | this.locator = locator |
| 34 | this.type = Object.keys(locator)[0] |
| 35 | this.value = locator[this.type] |
| 36 | this.strict = true |
| 37 | |
| 38 | Locator.filters.forEach(f => f(locator, this)) |
| 39 | |
| 40 | return |
| 41 | } |
| 42 | |
| 43 | // Try to parse JSON strings that look like objects |
| 44 | if (this.parsedJsonAsString(locator)) { |
| 45 | return |
| 46 | } |
| 47 | |
| 48 | this.type = defaultType || 'fuzzy' |
| 49 | this.output = locator |
| 50 | this.value = locator |
| 51 | |
| 52 | if (isCSS(locator)) { |
| 53 | this.type = 'css' |
| 54 | } |
| 55 | if (isXPath(locator)) { |
| 56 | this.type = 'xpath' |
| 57 | } |
| 58 | if (isShadow(locator)) { |
| 59 | this.type = 'shadow' |
| 60 | } |
| 61 | |
| 62 | Locator.filters.forEach(f => f(locator, this)) |
| 63 | } |
| 64 | |
| 65 | simplify() { |
| 66 | if (this.isNull()) return null |
nothing calls this directly
no test coverage detected