codeceptjs 4.0.0-rc.10 → 4.0.0-rc.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/mcp-server.js +32 -5
- package/lib/ai.js +3 -2
- package/lib/assertions.js +18 -0
- package/lib/codecept.js +6 -6
- package/lib/command/check.js +2 -0
- package/lib/command/dryRun.js +2 -3
- package/lib/command/generate.js +2 -0
- package/lib/command/gherkin/snippets.js +5 -4
- package/lib/command/init.js +1 -0
- package/lib/command/run-multiple.js +2 -0
- package/lib/command/run-workers.js +1 -0
- package/lib/command/run.js +1 -1
- package/lib/command/workers/runTests.js +10 -10
- package/lib/container.js +63 -13
- package/lib/effects.js +17 -0
- package/lib/element/WebElement.js +128 -0
- package/lib/globals.js +22 -10
- package/lib/heal.js +4 -3
- package/lib/helper/ApiDataFactory.js +2 -1
- package/lib/helper/FileSystem.js +3 -2
- package/lib/helper/GraphQLDataFactory.js +2 -1
- package/lib/helper/Playwright.js +22 -17
- package/lib/helper/Puppeteer.js +20 -6
- package/lib/helper/WebDriver.js +12 -2
- package/lib/helper/errors/NonFocusedType.js +8 -0
- package/lib/helper/extras/Download.js +45 -0
- package/lib/helper/extras/focusCheck.js +43 -0
- package/lib/helper/extras/richTextEditor.js +115 -0
- package/lib/history.js +3 -2
- package/lib/listener/config.js +6 -4
- package/lib/listener/emptyRun.js +2 -1
- package/lib/listener/helpers.js +4 -1
- package/lib/listener/mocha.js +2 -1
- package/lib/listener/pageobjects.js +43 -0
- package/lib/listener/result.js +3 -2
- package/lib/locator.js +112 -0
- package/lib/mocha/cli.js +4 -2
- package/lib/mocha/factory.js +2 -1
- package/lib/mocha/scenarioConfig.js +2 -1
- package/lib/mocha/ui.js +5 -6
- package/lib/plugin/aiTrace.js +4 -3
- package/lib/plugin/analyze.js +1 -1
- package/lib/plugin/auth.js +3 -3
- package/lib/plugin/pageInfo.js +2 -1
- package/lib/plugin/pauseOn.js +167 -0
- package/lib/plugin/screenshotOnFail.js +3 -4
- package/lib/plugin/stepByStepReport.js +5 -4
- package/lib/rerun.js +2 -1
- package/lib/result.js +2 -1
- package/lib/step/base.js +3 -2
- package/lib/step/record.js +1 -1
- package/lib/store.js +72 -3
- package/lib/translation.js +2 -1
- package/lib/utils/mask_data.js +2 -1
- package/lib/utils.js +4 -3
- package/lib/workers.js +2 -0
- package/package.json +5 -3
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import store from '../../store.js'
|
|
2
|
+
import NonFocusedType from '../errors/NonFocusedType.js'
|
|
3
|
+
|
|
4
|
+
const MODIFIER_PATTERN = /^(control|ctrl|meta|cmd|command|commandorcontrol|ctrlorcommand)/i
|
|
5
|
+
const EDITING_KEYS = new Set(['a', 'c', 'x', 'v', 'z', 'y'])
|
|
6
|
+
|
|
7
|
+
async function isNoElementFocused(helper) {
|
|
8
|
+
return helper.executeScript(() => {
|
|
9
|
+
const ae = document.activeElement
|
|
10
|
+
return !ae || ae === document.documentElement || (ae === document.body && !ae.isContentEditable)
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function checkFocusBeforeType(helper) {
|
|
15
|
+
if (!helper.options.strict && !store.debugMode) return
|
|
16
|
+
if (!await isNoElementFocused(helper)) return
|
|
17
|
+
|
|
18
|
+
const message = 'No element is in focus. Use I.click() or I.focus() to activate an element before typing.'
|
|
19
|
+
if (helper.options.strict) throw new NonFocusedType(message)
|
|
20
|
+
helper.debugSection('Warning', message)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function checkFocusBeforePressKey(helper, originalKey) {
|
|
24
|
+
if (!helper.options.strict && !store.debugMode) return
|
|
25
|
+
if (!Array.isArray(originalKey)) return
|
|
26
|
+
|
|
27
|
+
let hasCtrlOrMeta = false
|
|
28
|
+
let actionKey = null
|
|
29
|
+
for (const k of originalKey) {
|
|
30
|
+
if (MODIFIER_PATTERN.test(k)) {
|
|
31
|
+
hasCtrlOrMeta = true
|
|
32
|
+
} else {
|
|
33
|
+
actionKey = k
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!hasCtrlOrMeta || !actionKey || !EDITING_KEYS.has(actionKey.toLowerCase())) return
|
|
37
|
+
|
|
38
|
+
if (!await isNoElementFocused(helper)) return
|
|
39
|
+
|
|
40
|
+
const message = `No element is in focus. Key combination with "${originalKey.join('+')}" may not work as expected. Use I.click() or I.focus() first.`
|
|
41
|
+
if (helper.options.strict) throw new NonFocusedType(message)
|
|
42
|
+
helper.debugSection('Warning', message)
|
|
43
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import WebElement from '../../element/WebElement.js'
|
|
2
|
+
|
|
3
|
+
const MARKER = 'data-codeceptjs-rte-target'
|
|
4
|
+
|
|
5
|
+
const EDITOR = {
|
|
6
|
+
STANDARD: 'standard',
|
|
7
|
+
IFRAME: 'iframe',
|
|
8
|
+
CONTENTEDITABLE: 'contenteditable',
|
|
9
|
+
HIDDEN_TEXTAREA: 'hidden-textarea',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function detectAndMark(el, opts) {
|
|
13
|
+
const marker = opts.marker
|
|
14
|
+
const kinds = opts.kinds
|
|
15
|
+
const CE = '[contenteditable="true"], [contenteditable=""]'
|
|
16
|
+
const MAX_HIDDEN_ASCENT = 3
|
|
17
|
+
|
|
18
|
+
function mark(kind, target) {
|
|
19
|
+
document.querySelectorAll('[' + marker + ']').forEach(n => n.removeAttribute(marker))
|
|
20
|
+
if (target && target.nodeType === 1) target.setAttribute(marker, '1')
|
|
21
|
+
return kind
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!el || el.nodeType !== 1) return mark(kinds.STANDARD, el)
|
|
25
|
+
|
|
26
|
+
const tag = el.tagName
|
|
27
|
+
if (tag === 'IFRAME') return mark(kinds.IFRAME, el)
|
|
28
|
+
if (el.isContentEditable) return mark(kinds.CONTENTEDITABLE, el)
|
|
29
|
+
|
|
30
|
+
const canSearchDescendants = tag !== 'INPUT' && tag !== 'TEXTAREA'
|
|
31
|
+
if (canSearchDescendants) {
|
|
32
|
+
const iframe = el.querySelector('iframe')
|
|
33
|
+
if (iframe) return mark(kinds.IFRAME, iframe)
|
|
34
|
+
const ce = el.querySelector(CE)
|
|
35
|
+
if (ce) return mark(kinds.CONTENTEDITABLE, ce)
|
|
36
|
+
const textarea = el.querySelector('textarea')
|
|
37
|
+
if (textarea) return mark(kinds.HIDDEN_TEXTAREA, textarea)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const style = window.getComputedStyle(el)
|
|
41
|
+
const isHidden =
|
|
42
|
+
el.offsetParent === null ||
|
|
43
|
+
(el.offsetWidth === 0 && el.offsetHeight === 0) ||
|
|
44
|
+
style.display === 'none' ||
|
|
45
|
+
style.visibility === 'hidden'
|
|
46
|
+
if (!isHidden) return mark(kinds.STANDARD, el)
|
|
47
|
+
|
|
48
|
+
const isFormHidden = tag === 'INPUT' && el.type === 'hidden'
|
|
49
|
+
if (isFormHidden) return mark(kinds.STANDARD, el)
|
|
50
|
+
|
|
51
|
+
let scope = el.parentElement
|
|
52
|
+
for (let depth = 0; scope && depth < MAX_HIDDEN_ASCENT; depth++, scope = scope.parentElement) {
|
|
53
|
+
const iframeNear = scope.querySelector('iframe')
|
|
54
|
+
if (iframeNear) return mark(kinds.IFRAME, iframeNear)
|
|
55
|
+
const ceNear = scope.querySelector(CE)
|
|
56
|
+
if (ceNear) return mark(kinds.CONTENTEDITABLE, ceNear)
|
|
57
|
+
const textareaNear = [...scope.querySelectorAll('textarea')].find(t => t !== el)
|
|
58
|
+
if (textareaNear) return mark(kinds.HIDDEN_TEXTAREA, textareaNear)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return mark(kinds.STANDARD, el)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function selectAllInEditable(el) {
|
|
65
|
+
const doc = el.ownerDocument
|
|
66
|
+
const win = doc.defaultView
|
|
67
|
+
el.focus()
|
|
68
|
+
const range = doc.createRange()
|
|
69
|
+
range.selectNodeContents(el)
|
|
70
|
+
const sel = win.getSelection()
|
|
71
|
+
sel.removeAllRanges()
|
|
72
|
+
sel.addRange(range)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function unmarkAll(marker) {
|
|
76
|
+
document.querySelectorAll('[' + marker + ']').forEach(n => n.removeAttribute(marker))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function findMarked(helper) {
|
|
80
|
+
const root = helper.page || helper.browser
|
|
81
|
+
const raw = await root.$('[' + MARKER + ']')
|
|
82
|
+
return new WebElement(raw, helper)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function clearMarker(helper) {
|
|
86
|
+
if (helper.page) return helper.page.evaluate(unmarkAll, MARKER)
|
|
87
|
+
return helper.executeScript(unmarkAll, MARKER)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function fillRichEditor(helper, el, value) {
|
|
91
|
+
const source = el instanceof WebElement ? el : new WebElement(el, helper)
|
|
92
|
+
const kind = await source.evaluate(detectAndMark, { marker: MARKER, kinds: EDITOR })
|
|
93
|
+
if (kind === EDITOR.STANDARD) return false
|
|
94
|
+
|
|
95
|
+
const target = await findMarked(helper)
|
|
96
|
+
const delay = helper.options.pressKeyDelay
|
|
97
|
+
|
|
98
|
+
if (kind === EDITOR.IFRAME) {
|
|
99
|
+
await target.inIframe(async body => {
|
|
100
|
+
await body.evaluate(selectAllInEditable)
|
|
101
|
+
await body.typeText(value, { delay })
|
|
102
|
+
})
|
|
103
|
+
} else if (kind === EDITOR.HIDDEN_TEXTAREA) {
|
|
104
|
+
await target.focus()
|
|
105
|
+
await target.selectAllAndDelete()
|
|
106
|
+
await target.typeText(value, { delay })
|
|
107
|
+
} else if (kind === EDITOR.CONTENTEDITABLE) {
|
|
108
|
+
await target.click()
|
|
109
|
+
await target.evaluate(selectAllInEditable)
|
|
110
|
+
await target.typeText(value, { delay })
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
await clearMarker(helper)
|
|
114
|
+
return true
|
|
115
|
+
}
|
package/lib/history.js
CHANGED
|
@@ -2,6 +2,7 @@ import colors from 'chalk'
|
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import path from 'path'
|
|
4
4
|
import output from './output.js'
|
|
5
|
+
import store from './store.js'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* REPL history records REPL commands and stores them in
|
|
@@ -9,8 +10,8 @@ import output from './output.js'
|
|
|
9
10
|
*/
|
|
10
11
|
class ReplHistory {
|
|
11
12
|
constructor() {
|
|
12
|
-
if (
|
|
13
|
-
this.historyFile = path.join(
|
|
13
|
+
if (store.outputDir) {
|
|
14
|
+
this.historyFile = path.join(store.outputDir, 'cli-history')
|
|
14
15
|
}
|
|
15
16
|
this.commands = []
|
|
16
17
|
}
|
package/lib/listener/config.js
CHANGED
|
@@ -2,16 +2,18 @@ import event from '../event.js'
|
|
|
2
2
|
import recorder from '../recorder.js'
|
|
3
3
|
import { deepMerge, deepClone, ucfirst } from '../utils.js'
|
|
4
4
|
import output from '../output.js'
|
|
5
|
+
import container from '../container.js'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Enable Helpers to listen to test events
|
|
8
9
|
*/
|
|
10
|
+
let initialized = false
|
|
11
|
+
|
|
9
12
|
export default function () {
|
|
10
|
-
|
|
11
|
-
if (global.__codeceptConfigListenerInitialized) {
|
|
13
|
+
if (initialized) {
|
|
12
14
|
return
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
initialized = true
|
|
15
17
|
|
|
16
18
|
enableDynamicConfigFor('suite')
|
|
17
19
|
enableDynamicConfigFor('test')
|
|
@@ -20,7 +22,7 @@ export default function () {
|
|
|
20
22
|
event.dispatcher.on(event[type].before, (context = {}) => {
|
|
21
23
|
// Get helpers dynamically at runtime, not at initialization time
|
|
22
24
|
// This ensures we get the actual helper instances, not placeholders
|
|
23
|
-
const helpers =
|
|
25
|
+
const helpers = container.helpers()
|
|
24
26
|
|
|
25
27
|
function updateHelperConfig(helper, config) {
|
|
26
28
|
// Guard against undefined or invalid helpers
|
package/lib/listener/emptyRun.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import figures from 'figures'
|
|
2
2
|
import event from '../event.js'
|
|
3
3
|
import output from '../output.js'
|
|
4
|
+
import container from '../container.js'
|
|
4
5
|
import { searchWithFusejs } from '../utils.js'
|
|
5
6
|
|
|
6
7
|
export default function () {
|
|
@@ -12,7 +13,7 @@ export default function () {
|
|
|
12
13
|
|
|
13
14
|
event.dispatcher.on(event.all.result, () => {
|
|
14
15
|
if (isEmptyRun) {
|
|
15
|
-
const mocha =
|
|
16
|
+
const mocha = container.mocha()
|
|
16
17
|
|
|
17
18
|
if (mocha.options.grep) {
|
|
18
19
|
output.print()
|
package/lib/listener/helpers.js
CHANGED
|
@@ -3,11 +3,12 @@ import event from '../event.js'
|
|
|
3
3
|
import recorder from '../recorder.js'
|
|
4
4
|
import store from '../store.js'
|
|
5
5
|
import output from '../output.js'
|
|
6
|
+
import container from '../container.js'
|
|
6
7
|
/**
|
|
7
8
|
* Enable Helpers to listen to test events
|
|
8
9
|
*/
|
|
9
10
|
export default function () {
|
|
10
|
-
const helpers =
|
|
11
|
+
const helpers = container.helpers()
|
|
11
12
|
|
|
12
13
|
const runHelpersHook = (hook, param) => {
|
|
13
14
|
if (store.dryRun) return
|
|
@@ -29,11 +30,13 @@ export default function () {
|
|
|
29
30
|
event.dispatcher.on(event.suite.before, suite => {
|
|
30
31
|
// if (suite.parent) return; // only for root suite
|
|
31
32
|
runAsyncHelpersHook('_beforeSuite', suite, true)
|
|
33
|
+
recorder.catch()
|
|
32
34
|
})
|
|
33
35
|
|
|
34
36
|
event.dispatcher.on(event.suite.after, suite => {
|
|
35
37
|
// if (suite.parent) return; // only for root suite
|
|
36
38
|
runAsyncHelpersHook('_afterSuite', suite, true)
|
|
39
|
+
recorder.catch()
|
|
37
40
|
})
|
|
38
41
|
|
|
39
42
|
event.dispatcher.on(event.test.started, test => {
|
package/lib/listener/mocha.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import event from '../event.js'
|
|
2
|
+
import container from '../container.js'
|
|
2
3
|
|
|
3
4
|
export default function () {
|
|
4
5
|
let mocha
|
|
5
6
|
|
|
6
7
|
event.dispatcher.on(event.all.before, () => {
|
|
7
|
-
mocha =
|
|
8
|
+
mocha = container.mocha()
|
|
8
9
|
})
|
|
9
10
|
|
|
10
11
|
event.dispatcher.on(event.test.passed, test => {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import event from '../event.js'
|
|
2
|
+
import recorder from '../recorder.js'
|
|
3
|
+
import store from '../store.js'
|
|
4
|
+
import container from '../container.js'
|
|
5
|
+
import { resetBeforeCalledSet, getBeforeCalledSet } from '../container.js'
|
|
6
|
+
|
|
7
|
+
export default function () {
|
|
8
|
+
const runAsyncSupportHook = (hook, param, force) => {
|
|
9
|
+
if (store.dryRun) return
|
|
10
|
+
const support = container.supportObjects()
|
|
11
|
+
Object.keys(support).forEach(key => {
|
|
12
|
+
if (key === 'I') return
|
|
13
|
+
const obj = support[key]
|
|
14
|
+
if (!obj || typeof obj !== 'object' || !obj[hook]) return
|
|
15
|
+
recorder.add(`pageobject ${key}.${hook}()`, () => obj[hook](param), force, false)
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
event.dispatcher.on(event.test.started, () => {
|
|
20
|
+
resetBeforeCalledSet()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
event.dispatcher.on(event.test.after, () => {
|
|
24
|
+
if (store.dryRun) return
|
|
25
|
+
const support = container.supportObjects()
|
|
26
|
+
const called = getBeforeCalledSet()
|
|
27
|
+
called.forEach(name => {
|
|
28
|
+
const obj = support[name]
|
|
29
|
+
if (obj && obj._after) {
|
|
30
|
+
recorder.add(`pageobject ${name}._after()`, () => obj._after(), true, false)
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
recorder.catchWithoutStop(() => {})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
event.dispatcher.on(event.suite.after, suite => {
|
|
37
|
+
runAsyncSupportHook('_afterSuite', suite, true)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
event.dispatcher.on(event.suite.before, suite => {
|
|
41
|
+
runAsyncSupportHook('_beforeSuite', suite, true)
|
|
42
|
+
})
|
|
43
|
+
}
|
package/lib/listener/result.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import event from '../event.js'
|
|
2
|
+
import container from '../container.js'
|
|
2
3
|
|
|
3
4
|
export default function () {
|
|
4
5
|
event.dispatcher.on(event.hook.failed, err => {
|
|
5
|
-
|
|
6
|
+
container.result().addStats({ failedHooks: 1 })
|
|
6
7
|
})
|
|
7
8
|
|
|
8
9
|
event.dispatcher.on(event.test.before, test => {
|
|
9
|
-
|
|
10
|
+
container.result().addTest(test)
|
|
10
11
|
})
|
|
11
12
|
}
|
package/lib/locator.js
CHANGED
|
@@ -381,9 +381,121 @@ class Locator {
|
|
|
381
381
|
return new Locator({ xpath })
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
+
/**
|
|
385
|
+
* Find an element with all of the provided CSS classes (word-exact match).
|
|
386
|
+
* Accepts variadic class names; all must be present.
|
|
387
|
+
*
|
|
388
|
+
* Example:
|
|
389
|
+
* locate('button').withClass('btn-primary', 'btn-lg')
|
|
390
|
+
*
|
|
391
|
+
* @param {...string} classes
|
|
392
|
+
* @returns {Locator}
|
|
393
|
+
*/
|
|
394
|
+
withClass(...classes) {
|
|
395
|
+
if (!classes.length) return this
|
|
396
|
+
const predicates = classes.map(c => `contains(concat(' ', normalize-space(@class), ' '), ' ${c} ')`)
|
|
397
|
+
const xpath = sprintf('%s[%s]', this.toXPath(), predicates.join(' and '))
|
|
398
|
+
return new Locator({ xpath })
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Find an element with none of the provided CSS classes.
|
|
403
|
+
*
|
|
404
|
+
* Example:
|
|
405
|
+
* locate('tr').withoutClass('deleted')
|
|
406
|
+
*
|
|
407
|
+
* @param {...string} classes
|
|
408
|
+
* @returns {Locator}
|
|
409
|
+
*/
|
|
410
|
+
withoutClass(...classes) {
|
|
411
|
+
if (!classes.length) return this
|
|
412
|
+
const predicates = classes.map(c => `not(contains(concat(' ', normalize-space(@class), ' '), ' ${c} '))`)
|
|
413
|
+
const xpath = sprintf('%s[%s]', this.toXPath(), predicates.join(' and '))
|
|
414
|
+
return new Locator({ xpath })
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Find an element that does NOT contain the provided text.
|
|
419
|
+
* @param {string} text
|
|
420
|
+
* @returns {Locator}
|
|
421
|
+
*/
|
|
422
|
+
withoutText(text) {
|
|
423
|
+
text = xpathLocator.literal(text)
|
|
424
|
+
const xpath = sprintf('%s[%s]', this.toXPath(), `not(contains(., ${text}))`)
|
|
425
|
+
return new Locator({ xpath })
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Find an element that does NOT have any of the provided attribute/value pairs.
|
|
430
|
+
* @param {Object.<string, string>} attributes
|
|
431
|
+
* @returns {Locator}
|
|
432
|
+
*/
|
|
433
|
+
withoutAttr(attributes) {
|
|
434
|
+
const operands = []
|
|
435
|
+
for (const attr of Object.keys(attributes)) {
|
|
436
|
+
operands.push(`not(@${attr} = ${xpathLocator.literal(attributes[attr])})`)
|
|
437
|
+
}
|
|
438
|
+
const xpath = sprintf('%s[%s]', this.toXPath(), operands.join(' and '))
|
|
439
|
+
return new Locator({ xpath })
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Find an element that has no direct child matching the provided locator.
|
|
444
|
+
* @param {CodeceptJS.LocatorOrString} locator
|
|
445
|
+
* @returns {Locator}
|
|
446
|
+
*/
|
|
447
|
+
withoutChild(locator) {
|
|
448
|
+
const xpath = sprintf('%s[not(./child::%s)]', this.toXPath(), convertToSubSelector(locator))
|
|
449
|
+
return new Locator({ xpath })
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Find an element that has no descendant matching the provided locator.
|
|
454
|
+
*
|
|
455
|
+
* Example:
|
|
456
|
+
* locate('button').withoutDescendant('svg')
|
|
457
|
+
*
|
|
458
|
+
* @param {CodeceptJS.LocatorOrString} locator
|
|
459
|
+
* @returns {Locator}
|
|
460
|
+
*/
|
|
461
|
+
withoutDescendant(locator) {
|
|
462
|
+
const xpath = sprintf('%s[not(./descendant::%s)]', this.toXPath(), convertToSubSelector(locator))
|
|
463
|
+
return new Locator({ xpath })
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Append a raw XPath predicate. Escape hatch for expressions not covered by the DSL.
|
|
468
|
+
* Argument is inserted as-is inside `[ ]`; quoting/escaping is the caller's responsibility.
|
|
469
|
+
*
|
|
470
|
+
* Example:
|
|
471
|
+
* locate('input').and('@type="text" or @type="email"')
|
|
472
|
+
*
|
|
473
|
+
* @param {string} xpathExpression
|
|
474
|
+
* @returns {Locator}
|
|
475
|
+
*/
|
|
476
|
+
and(xpathExpression) {
|
|
477
|
+
const xpath = sprintf('%s[%s]', this.toXPath(), xpathExpression)
|
|
478
|
+
return new Locator({ xpath })
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Append a negated raw XPath predicate: `[not(expr)]`.
|
|
483
|
+
*
|
|
484
|
+
* Example:
|
|
485
|
+
* locate('button').andNot('.//svg') // button without a descendant svg
|
|
486
|
+
*
|
|
487
|
+
* @param {string} xpathExpression
|
|
488
|
+
* @returns {Locator}
|
|
489
|
+
*/
|
|
490
|
+
andNot(xpathExpression) {
|
|
491
|
+
const xpath = sprintf('%s[not(%s)]', this.toXPath(), xpathExpression)
|
|
492
|
+
return new Locator({ xpath })
|
|
493
|
+
}
|
|
494
|
+
|
|
384
495
|
/**
|
|
385
496
|
* @param {String} text
|
|
386
497
|
* @returns {Locator}
|
|
498
|
+
* @deprecated Use {@link Locator#withClass} for word-exact class matching, or {@link Locator#withAttrContains} for substring matching.
|
|
387
499
|
*/
|
|
388
500
|
withClassAttr(text) {
|
|
389
501
|
const xpath = sprintf('%s[%s]', this.toXPath(), `contains(@class, '${text}')`)
|
package/lib/mocha/cli.js
CHANGED
|
@@ -8,6 +8,7 @@ import { dirname, join } from 'path'
|
|
|
8
8
|
import event from '../event.js'
|
|
9
9
|
import AssertionFailedError from '../assert/error.js'
|
|
10
10
|
import output from '../output.js'
|
|
11
|
+
import store from '../store.js'
|
|
11
12
|
import test, { cloneTest } from './test.js'
|
|
12
13
|
import { fixErrorStack } from '../utils/typescript.js'
|
|
13
14
|
|
|
@@ -41,7 +42,7 @@ class Cli extends Base {
|
|
|
41
42
|
if (opts.verbose) level = 3
|
|
42
43
|
output.level(level)
|
|
43
44
|
output.print(`CodeceptJS v${codeceptVersion} ${output.standWithUkraine()}`)
|
|
44
|
-
output.print(`Using test root "${
|
|
45
|
+
output.print(`Using test root "${store.codeceptDir}"`)
|
|
45
46
|
|
|
46
47
|
const showSteps = level >= 1
|
|
47
48
|
|
|
@@ -213,6 +214,7 @@ class Cli extends Base {
|
|
|
213
214
|
}
|
|
214
215
|
|
|
215
216
|
// append step traces
|
|
217
|
+
const Container = await getContainer()
|
|
216
218
|
this.failures = this.failures.map(test => {
|
|
217
219
|
// we will change the stack trace, so we need to clone the test
|
|
218
220
|
const err = test.err
|
|
@@ -275,7 +277,7 @@ class Cli extends Base {
|
|
|
275
277
|
}
|
|
276
278
|
|
|
277
279
|
try {
|
|
278
|
-
const fileMapping =
|
|
280
|
+
const fileMapping = Container?.tsFileMapping?.()
|
|
279
281
|
if (fileMapping) {
|
|
280
282
|
fixErrorStack(err, fileMapping)
|
|
281
283
|
}
|
package/lib/mocha/factory.js
CHANGED
|
@@ -8,6 +8,7 @@ import output from '../output.js'
|
|
|
8
8
|
import scenarioUiFunction from './ui.js'
|
|
9
9
|
import { initMochaGlobals } from '../globals.js'
|
|
10
10
|
import { fixErrorStack } from '../utils/typescript.js'
|
|
11
|
+
import container from '../container.js'
|
|
11
12
|
|
|
12
13
|
const __filename = fileURLToPath(import.meta.url)
|
|
13
14
|
const __dirname = fsPath.dirname(__filename)
|
|
@@ -35,7 +36,7 @@ class MochaFactory {
|
|
|
35
36
|
// Handle ECONNREFUSED without dynamic import for now
|
|
36
37
|
err = new Error('Connection refused: ' + err.toString())
|
|
37
38
|
}
|
|
38
|
-
const fileMapping =
|
|
39
|
+
const fileMapping = container?.tsFileMapping?.()
|
|
39
40
|
if (fileMapping) {
|
|
40
41
|
fixErrorStack(err, fileMapping)
|
|
41
42
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isAsyncFunction } from '../utils.js'
|
|
2
|
+
import store from '../store.js'
|
|
2
3
|
|
|
3
4
|
/** @class */
|
|
4
5
|
class ScenarioConfig {
|
|
@@ -40,7 +41,7 @@ class ScenarioConfig {
|
|
|
40
41
|
* @returns {this}
|
|
41
42
|
*/
|
|
42
43
|
retry(retries) {
|
|
43
|
-
if (
|
|
44
|
+
if (store.scenarioOnly) retries = -retries
|
|
44
45
|
this.test.retries(retries)
|
|
45
46
|
return this
|
|
46
47
|
}
|
package/lib/mocha/ui.js
CHANGED
|
@@ -9,13 +9,12 @@ import { HookConfig, AfterSuiteHook, AfterHook, BeforeSuiteHook, BeforeHook } fr
|
|
|
9
9
|
import { initMochaGlobals } from '../globals.js'
|
|
10
10
|
import common from 'mocha/lib/interfaces/common.js'
|
|
11
11
|
import container from '../container.js'
|
|
12
|
+
import store from '../store.js'
|
|
12
13
|
|
|
13
14
|
const setContextTranslation = context => {
|
|
14
|
-
|
|
15
|
-
const containerToUse = global.container || container
|
|
16
|
-
if (!containerToUse) return
|
|
15
|
+
if (!container) return
|
|
17
16
|
|
|
18
|
-
const translation =
|
|
17
|
+
const translation = container.translation?.() || container.translation
|
|
19
18
|
const contexts = translation?.value?.('contexts')
|
|
20
19
|
|
|
21
20
|
if (contexts) {
|
|
@@ -119,7 +118,7 @@ export default function (suite) {
|
|
|
119
118
|
context.Feature.only = function (title, opts) {
|
|
120
119
|
const reString = `^${escapeRe(`${title}:`)}`
|
|
121
120
|
mocha.grep(new RegExp(reString))
|
|
122
|
-
|
|
121
|
+
store.featureOnly = true
|
|
123
122
|
return context.Feature(title, opts)
|
|
124
123
|
}
|
|
125
124
|
|
|
@@ -171,7 +170,7 @@ export default function (suite) {
|
|
|
171
170
|
context.Scenario.only = function (title, opts, fn) {
|
|
172
171
|
const reString = `^${escapeRe(`${suites[0].title}: ${title}`.replace(/( \| {.+})?$/g, ''))}`
|
|
173
172
|
mocha.grep(new RegExp(reString))
|
|
174
|
-
|
|
173
|
+
store.scenarioOnly = true
|
|
175
174
|
return addScenario(title, opts, fn)
|
|
176
175
|
}
|
|
177
176
|
|
package/lib/plugin/aiTrace.js
CHANGED
|
@@ -4,6 +4,7 @@ import { mkdirp } from 'mkdirp'
|
|
|
4
4
|
import path from 'path'
|
|
5
5
|
import { fileURLToPath } from 'url'
|
|
6
6
|
|
|
7
|
+
import store from '../store.js'
|
|
7
8
|
import Container from '../container.js'
|
|
8
9
|
import recorder from '../recorder.js'
|
|
9
10
|
import event from '../event.js'
|
|
@@ -16,7 +17,7 @@ const supportedHelpers = Container.STANDARD_ACTING_HELPERS
|
|
|
16
17
|
const defaultConfig = {
|
|
17
18
|
deleteSuccessful: false,
|
|
18
19
|
fullPageScreenshots: false,
|
|
19
|
-
output:
|
|
20
|
+
output: store.outputDir,
|
|
20
21
|
captureHTML: true,
|
|
21
22
|
captureARIA: true,
|
|
22
23
|
captureBrowserLogs: true,
|
|
@@ -84,7 +85,7 @@ export default function (config) {
|
|
|
84
85
|
let testFailed = false
|
|
85
86
|
let firstFailedStepSaved = false
|
|
86
87
|
|
|
87
|
-
const reportDir = config.output ? path.resolve(
|
|
88
|
+
const reportDir = config.output ? path.resolve(store.codeceptDir, config.output) : defaultConfig.output
|
|
88
89
|
|
|
89
90
|
if (config.captureDebugOutput) {
|
|
90
91
|
const originalDebug = output.debug
|
|
@@ -437,7 +438,7 @@ export default function (config) {
|
|
|
437
438
|
const traceFile = path.join(dir, 'trace.md')
|
|
438
439
|
fs.writeFileSync(traceFile, markdown)
|
|
439
440
|
|
|
440
|
-
output.print(
|
|
441
|
+
output.print(`Trace Saved: file://${traceFile}`)
|
|
441
442
|
|
|
442
443
|
if (!test.artifacts) test.artifacts = {}
|
|
443
444
|
test.artifacts.aiTrace = traceFile
|
package/lib/plugin/analyze.js
CHANGED
package/lib/plugin/auth.js
CHANGED
|
@@ -321,7 +321,7 @@ export default function (config) {
|
|
|
321
321
|
}
|
|
322
322
|
if (config.saveToFile) {
|
|
323
323
|
output.debug(`Saved user session into file for ${name}`)
|
|
324
|
-
fs.writeFileSync(path.join(
|
|
324
|
+
fs.writeFileSync(path.join(store.outputDir, `${name}_session.json`), JSON.stringify(cookies))
|
|
325
325
|
}
|
|
326
326
|
store[`${name}_session`] = cookies
|
|
327
327
|
}
|
|
@@ -377,7 +377,7 @@ export default function (config) {
|
|
|
377
377
|
}
|
|
378
378
|
|
|
379
379
|
if (!config.saveToFile) return
|
|
380
|
-
const cookieFile = path.join(
|
|
380
|
+
const cookieFile = path.join(store.outputDir, `${name}_session.json`)
|
|
381
381
|
|
|
382
382
|
if (!fileExists(cookieFile)) {
|
|
383
383
|
return
|
|
@@ -412,7 +412,7 @@ export default function (config) {
|
|
|
412
412
|
|
|
413
413
|
function loadCookiesFromFile(config) {
|
|
414
414
|
for (const name in config.users) {
|
|
415
|
-
const fileName = path.join(
|
|
415
|
+
const fileName = path.join(store.outputDir, `${name}_session.json`)
|
|
416
416
|
if (!fileExists(fileName)) continue
|
|
417
417
|
const data = fs.readFileSync(fileName).toString()
|
|
418
418
|
try {
|
package/lib/plugin/pageInfo.js
CHANGED
|
@@ -6,6 +6,7 @@ import recorder from '../recorder.js'
|
|
|
6
6
|
import event from '../event.js'
|
|
7
7
|
import { scanForErrorMessages } from '../html.js'
|
|
8
8
|
import { output } from '../index.js'
|
|
9
|
+
import store from '../store.js'
|
|
9
10
|
import { humanizeString, ucfirst } from '../utils.js'
|
|
10
11
|
import { testToFileName } from '../mocha/test.js'
|
|
11
12
|
const defaultConfig = {
|
|
@@ -92,7 +93,7 @@ export default function (config = {}) {
|
|
|
92
93
|
recorder.add('Save page info', () => {
|
|
93
94
|
test.addNote('pageInfo', pageStateToMarkdown(pageState))
|
|
94
95
|
|
|
95
|
-
const pageStateFileName = path.join(
|
|
96
|
+
const pageStateFileName = path.join(store.outputDir, `${testToFileName(test)}.pageInfo.md`)
|
|
96
97
|
fs.writeFileSync(pageStateFileName, pageStateToMarkdown(pageState))
|
|
97
98
|
test.artifacts.pageInfo = pageStateFileName
|
|
98
99
|
return pageState
|