Skip to content
This repository was archived by the owner on Oct 13, 2022. It is now read-only.

Commit a2f2a83

Browse files
committed
feat: better logging
1 parent db8079e commit a2f2a83

File tree

1 file changed

+52
-13
lines changed

1 file changed

+52
-13
lines changed

src/index.js

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,59 @@ const xpath = (selector) => {
2424
const isBoolean = (xpathResult) => xpathResult.resultType === XPathResult.BOOLEAN_TYPE
2525
const booleanResult = (xpathResult) => xpathResult.booleanValue
2626

27-
Cypress.log({
28-
name: 'xpath',
29-
message: selector,
30-
consoleProps () {
31-
return {
32-
'XPath': selector,
33-
}
34-
},
35-
})
36-
3727
let nodes = []
3828
const document = cy.state('window').document
3929
let iterator = document.evaluate(selector, document)
4030

4131
if (isNumber(iterator)) {
42-
return numberResult(iterator)
32+
const result = numberResult(iterator)
33+
Cypress.log({
34+
name: 'xpath',
35+
message: selector,
36+
$el: nodes,
37+
consoleProps () {
38+
return {
39+
'XPath': selector,
40+
type: 'number',
41+
result
42+
}
43+
},
44+
})
45+
return result
4346
}
4447

4548
if (isString(iterator)) {
46-
return stringResult(iterator)
49+
const result = stringResult(iterator)
50+
Cypress.log({
51+
name: 'xpath',
52+
message: selector,
53+
$el: nodes,
54+
consoleProps () {
55+
return {
56+
'XPath': selector,
57+
type: 'string',
58+
result
59+
}
60+
},
61+
})
62+
return result
4763
}
4864

4965
if (isBoolean(iterator)) {
50-
return booleanResult(iterator)
66+
const result = booleanResult(iterator)
67+
Cypress.log({
68+
name: 'xpath',
69+
message: selector,
70+
$el: nodes,
71+
consoleProps () {
72+
return {
73+
'XPath': selector,
74+
type: 'boolean',
75+
result
76+
}
77+
},
78+
})
79+
return result
5180
}
5281

5382
try {
@@ -64,6 +93,16 @@ const xpath = (selector) => {
6493
}
6594

6695
// TODO set found elements on the command log?
96+
Cypress.log({
97+
name: 'xpath',
98+
message: selector,
99+
$el: nodes,
100+
consoleProps () {
101+
return {
102+
'XPath': selector,
103+
}
104+
},
105+
})
67106

68107
return Cypress.$(nodes)
69108
}

0 commit comments

Comments
 (0)