codeceptjs 3.7.0-beta.1 → 3.7.0-beta.10

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.
Files changed (73) hide show
  1. package/README.md +9 -10
  2. package/bin/codecept.js +7 -0
  3. package/lib/actor.js +46 -92
  4. package/lib/ai.js +130 -121
  5. package/lib/codecept.js +2 -2
  6. package/lib/command/check.js +186 -0
  7. package/lib/command/definitions.js +3 -1
  8. package/lib/command/interactive.js +1 -1
  9. package/lib/command/run-workers.js +2 -54
  10. package/lib/command/workers/runTests.js +64 -225
  11. package/lib/container.js +27 -0
  12. package/lib/effects.js +218 -0
  13. package/lib/els.js +87 -106
  14. package/lib/event.js +18 -17
  15. package/lib/heal.js +10 -0
  16. package/lib/helper/AI.js +2 -1
  17. package/lib/helper/Appium.js +31 -22
  18. package/lib/helper/Playwright.js +22 -1
  19. package/lib/helper/Puppeteer.js +5 -0
  20. package/lib/helper/WebDriver.js +29 -8
  21. package/lib/listener/emptyRun.js +2 -5
  22. package/lib/listener/exit.js +5 -8
  23. package/lib/listener/globalTimeout.js +66 -10
  24. package/lib/listener/result.js +12 -0
  25. package/lib/listener/steps.js +3 -6
  26. package/lib/listener/store.js +9 -1
  27. package/lib/mocha/asyncWrapper.js +15 -3
  28. package/lib/mocha/cli.js +79 -28
  29. package/lib/mocha/featureConfig.js +13 -0
  30. package/lib/mocha/hooks.js +32 -3
  31. package/lib/mocha/inject.js +5 -0
  32. package/lib/mocha/scenarioConfig.js +11 -0
  33. package/lib/mocha/suite.js +27 -1
  34. package/lib/mocha/test.js +102 -3
  35. package/lib/mocha/types.d.ts +11 -0
  36. package/lib/output.js +75 -73
  37. package/lib/pause.js +3 -10
  38. package/lib/plugin/analyze.js +349 -0
  39. package/lib/plugin/autoDelay.js +2 -2
  40. package/lib/plugin/commentStep.js +5 -0
  41. package/lib/plugin/customReporter.js +52 -0
  42. package/lib/plugin/heal.js +30 -0
  43. package/lib/plugin/pageInfo.js +140 -0
  44. package/lib/plugin/retryTo.js +18 -118
  45. package/lib/plugin/screenshotOnFail.js +12 -17
  46. package/lib/plugin/standardActingHelpers.js +4 -1
  47. package/lib/plugin/stepByStepReport.js +6 -5
  48. package/lib/plugin/stepTimeout.js +1 -1
  49. package/lib/plugin/tryTo.js +17 -107
  50. package/lib/recorder.js +5 -5
  51. package/lib/rerun.js +43 -42
  52. package/lib/result.js +161 -0
  53. package/lib/step/base.js +228 -0
  54. package/lib/step/config.js +50 -0
  55. package/lib/step/func.js +46 -0
  56. package/lib/step/helper.js +50 -0
  57. package/lib/step/meta.js +99 -0
  58. package/lib/step/record.js +74 -0
  59. package/lib/step/retry.js +11 -0
  60. package/lib/step/section.js +55 -0
  61. package/lib/step.js +20 -347
  62. package/lib/steps.js +50 -0
  63. package/lib/store.js +4 -0
  64. package/lib/timeout.js +66 -0
  65. package/lib/utils.js +93 -0
  66. package/lib/within.js +2 -2
  67. package/lib/workers.js +29 -49
  68. package/package.json +23 -20
  69. package/typings/index.d.ts +5 -4
  70. package/typings/promiseBasedTypes.d.ts +617 -7
  71. package/typings/types.d.ts +663 -34
  72. package/lib/listener/artifacts.js +0 -19
  73. package/lib/plugin/debugErrors.js +0 -67
@@ -0,0 +1,349 @@
1
+ const debug = require('debug')('codeceptjs:analyze')
2
+ const { isMainThread } = require('node:worker_threads')
3
+ const { arrowRight } = require('figures')
4
+ const container = require('../container')
5
+ const ai = require('../ai')
6
+ const colors = require('chalk')
7
+ const ora = require('ora-classic')
8
+ const event = require('../event')
9
+ const output = require('../output')
10
+ const { ansiRegExp, base64EncodeFile, markdownToAnsi } = require('../utils')
11
+
12
+ const MAX_DATA_LENGTH = 5000
13
+
14
+ const defaultConfig = {
15
+ clusterize: 5,
16
+ analyze: 2,
17
+ vision: false,
18
+ categories: [
19
+ 'Browser connection error / browser crash',
20
+ 'Network errors (server error, timeout, etc)',
21
+ 'HTML / page elements (not found, not visible, etc)',
22
+ 'Navigation errors (404, etc)',
23
+ 'Code errors (syntax error, JS errors, etc)',
24
+ 'Library & framework errors (CodeceptJS internal errors, user-defined libraries, etc)',
25
+ 'Data errors (password incorrect, no options in select, invalid format, etc)',
26
+ 'Assertion failures',
27
+ 'Other errors',
28
+ ],
29
+ prompts: {
30
+ clusterize: (tests, config) => {
31
+ const serializedFailedTests = tests
32
+ .map((test, index) => {
33
+ if (!test || !test.err) return
34
+ return `
35
+ #${index + 1}: ${serializeTest(test)}
36
+ ${serializeError(test.err).slice(0, MAX_DATA_LENGTH / tests.length)}`.trim()
37
+ })
38
+ .join('\n\n--------\n\n')
39
+
40
+ const messages = [
41
+ {
42
+ role: 'user',
43
+ content: `
44
+ I am test analyst analyzing failed tests in CodeceptJS testing framework.
45
+
46
+ Please analyze the following failed tests and classify them into groups by their cause.
47
+ If there is no groups detected, say: "No common groups found".
48
+
49
+ Provide a short description of the group and a list of failed tests that belong to this group.
50
+ Use percent sign to indicate the percentage of failed tests in the group if this percentage is greater than 30%.
51
+
52
+ Here are failed tests:
53
+
54
+ ${serializedFailedTests}
55
+
56
+ Common categories of failures by order of priority:
57
+
58
+ ${config.categories.join('\n- ')}
59
+
60
+ If there is no groups of tests, say: "No patterns found"
61
+ Preserve error messages but cut them if they are too long.
62
+ Respond clearly and directly, without introductory words or phrases like ‘Of course,’ ‘Here is the answer,’ etc.
63
+ Do not list more than 3 errors in the group.
64
+ If you identify that all tests in the group have the same tag, add this tag to the group report, otherwise ignore TAG section.
65
+ If you identify that all tests in the group have the same suite, add this suite to the group report, otherwise ignore SUITE section.
66
+ Pick different emojis for each group.
67
+ Order groups by the number of tests in the group.
68
+ If group has one test, skip that group.
69
+
70
+ Provide list of groups in following format:
71
+
72
+ _______________________________
73
+
74
+ ## Group <group_number> <emoji>
75
+
76
+ * SUMMARY <summary_of_errors>
77
+ * CATEGORY <category_of_failure>
78
+ * ERROR <error_message_1>, <error_message_2>, ...
79
+ * STEP <step_of_failure> (use CodeceptJS format I.click(), I.see(), etc; if all failures happend on the same step)
80
+ * SUITE <suite_title>, <suite_title> (if SUITE is present, and if all tests in the group have the same suite or suites)
81
+ * TAG <tag> (if TAG is present, and if all tests in the group have the same tag)
82
+ * AFFECTED TESTS (<total number of tests>):
83
+ x <test1 title>
84
+ x <test2 title>
85
+ x <test3 title>
86
+ x ...
87
+ `,
88
+ },
89
+ {
90
+ role: 'assistant',
91
+ content: `## '
92
+ `,
93
+ },
94
+ ]
95
+ return messages
96
+ },
97
+ analyze: (test, config) => {
98
+ const testMessage = serializeTest(test)
99
+ const errorMessage = serializeError(test.err)
100
+
101
+ const messages = [
102
+ {
103
+ role: 'user',
104
+ content: [
105
+ {
106
+ type: 'text',
107
+ text: `
108
+ I am qa engineer analyzing failed tests in CodeceptJS testing framework.
109
+ Please analyze the following failed test and error its error and explain it.
110
+
111
+ Pick one of the categories of failures and explain it.
112
+
113
+ Categories of failures in order of priority:
114
+
115
+ ${config.categories.join('\n- ')}
116
+
117
+ Here is the test and error:
118
+
119
+ ------- TEST -------
120
+ ${testMessage}
121
+
122
+ ------- ERROR -------
123
+ ${errorMessage}
124
+
125
+ ------ INSTRUCTIONS ------
126
+
127
+ Do not get to details, be concise.
128
+ If there is failed step, just write it in STEPS section.
129
+ If you have suggestions for the test, write them in SUMMARY section.
130
+ Do not be too technical in SUMMARY section.
131
+ Inside SUMMARY write exact values, if you have suggestions, explain which information you used to suggest.
132
+ Be concise, each section should not take more than one sentence.
133
+
134
+ Response format:
135
+
136
+ * SUMMARY <explanation_of_failure>
137
+ * ERROR <error_message_1>, <error_message_2>, ...
138
+ * CATEGORY <category_of_failure>
139
+ * STEPS <step_of_failure>
140
+
141
+ Do not add any other sections or explanations. Only CATEGORY, SUMMARY, STEPS.
142
+ ${config.vision ? 'Also a screenshot of the page is attached to the prompt.' : ''}
143
+ `,
144
+ },
145
+ ],
146
+ },
147
+ ]
148
+
149
+ if (config.vision && test.artifacts.screenshot) {
150
+ debug('Adding screenshot to prompt')
151
+ messages[0].content.push({
152
+ type: 'image_url',
153
+ image_url: {
154
+ url: 'data:image/png;base64,' + base64EncodeFile(test.artifacts.screenshot),
155
+ },
156
+ })
157
+ }
158
+
159
+ return messages
160
+ },
161
+ },
162
+ }
163
+
164
+ /**
165
+ *
166
+ * @param {*} config
167
+ * @returns
168
+ */
169
+ module.exports = function (config = {}) {
170
+ config = Object.assign(defaultConfig, config)
171
+
172
+ event.dispatcher.on(event.workers.before, () => {
173
+ if (!ai.isEnabled) return
174
+ console.log('Enabled AI analysis')
175
+ })
176
+
177
+ event.dispatcher.on(event.all.result, async result => {
178
+ if (!isMainThread) return // run only on main thread
179
+ if (!ai.isEnabled) {
180
+ console.log('AI is disabled, no analysis will be performed. Run tests with --ai flag to enable it.')
181
+ return
182
+ }
183
+
184
+ printReport(result)
185
+ })
186
+
187
+ event.dispatcher.on(event.workers.result, async result => {
188
+ if (!result.hasFailed) {
189
+ console.log('Everything is fine, skipping AI analysis')
190
+ return
191
+ }
192
+
193
+ if (!ai.isEnabled) {
194
+ console.log('AI is disabled, no analysis will be performed. Run tests with --ai flag to enable it.')
195
+ return
196
+ }
197
+
198
+ printReport(result)
199
+ })
200
+
201
+ async function printReport(result) {
202
+ const failedTestsAndErrors = result.tests.filter(t => t.err)
203
+
204
+ if (!failedTestsAndErrors.length) return
205
+
206
+ debug(failedTestsAndErrors.map(t => serializeTest(t) + '\n' + serializeError(t.err)))
207
+
208
+ try {
209
+ if (failedTestsAndErrors.length >= config.clusterize) {
210
+ const response = await clusterize(failedTestsAndErrors)
211
+ printHeader()
212
+ console.log(response)
213
+ return
214
+ }
215
+
216
+ output.plugin('analyze', `Analyzing first ${config.analyze} failed tests...`)
217
+
218
+ // we pick only unique errors to not repeat answers
219
+ const uniqueErrors = failedTestsAndErrors.filter((item, index, array) => {
220
+ return array.findIndex(t => t.err?.message === item.err?.message) === index
221
+ })
222
+
223
+ for (let i = 0; i < config.analyze; i++) {
224
+ if (!uniqueErrors[i]) break
225
+
226
+ const response = await analyze(uniqueErrors[i])
227
+ if (!response) {
228
+ break
229
+ }
230
+
231
+ printHeader()
232
+ console.log()
233
+ console.log('--------------------------------')
234
+ console.log(arrowRight, colors.bold.white(uniqueErrors[i].fullTitle()), config.vision ? '👀' : '')
235
+ console.log()
236
+ console.log()
237
+ console.log(response)
238
+ console.log()
239
+ }
240
+ } catch (err) {
241
+ console.error('Error analyzing failed tests', err)
242
+ }
243
+
244
+ if (!Object.keys(container.plugins()).includes('pageInfo')) {
245
+ console.log('To improve analysis, enable pageInfo plugin to get more context for failed tests.')
246
+ }
247
+ }
248
+
249
+ let hasPrintedHeader = false
250
+
251
+ function printHeader() {
252
+ if (!hasPrintedHeader) {
253
+ console.log()
254
+ console.log(colors.bold.white('🪄 AI REPORT:'))
255
+ hasPrintedHeader = true
256
+ }
257
+ }
258
+
259
+ async function clusterize(failedTestsAndErrors) {
260
+ const spinner = ora('Clusterizing failures...').start()
261
+ const prompt = config.prompts.clusterize(failedTestsAndErrors, config)
262
+ try {
263
+ const response = await ai.createCompletion(prompt)
264
+ spinner.stop()
265
+ return formatResponse(response)
266
+ } catch (err) {
267
+ spinner.stop()
268
+ console.error('Error clusterizing failures', err.message)
269
+ }
270
+ }
271
+
272
+ async function analyze(failedTestAndError) {
273
+ const spinner = ora('Analyzing failure...').start()
274
+ const prompt = config.prompts.analyze(failedTestAndError, config)
275
+ try {
276
+ const response = await ai.createCompletion(prompt)
277
+ spinner.stop()
278
+ return formatResponse(response)
279
+ } catch (err) {
280
+ spinner.stop()
281
+ console.error('Error analyzing failure:', err.message)
282
+ }
283
+ }
284
+ }
285
+
286
+ function serializeError(error) {
287
+ if (typeof error === 'string') {
288
+ return error
289
+ }
290
+
291
+ if (!error) return
292
+
293
+ let errorMessage = 'ERROR: ' + error.message
294
+
295
+ if (error.inspect) {
296
+ errorMessage = 'ERROR: ' + error.inspect()
297
+ }
298
+
299
+ if (error.stack) {
300
+ errorMessage +=
301
+ '\n' +
302
+ error.stack
303
+ .replace(global.codecept_dir || '', '.')
304
+ .split('\n')
305
+ .map(line => line.replace(ansiRegExp(), ''))
306
+ .slice(0, 5)
307
+ .join('\n')
308
+ }
309
+ if (error.steps) {
310
+ errorMessage += '\n STEPS: ' + error.steps.map(s => s.toCode()).join('\n')
311
+ }
312
+ return errorMessage
313
+ }
314
+
315
+ function serializeTest(test) {
316
+ if (!test.uid) return
317
+
318
+ let testMessage = 'TEST TITLE: ' + test.title
319
+
320
+ if (test.suite) {
321
+ testMessage += '\n SUITE: ' + test.suite.title
322
+ }
323
+ if (test.parent) {
324
+ testMessage += '\n SUITE: ' + test.parent.title
325
+ }
326
+
327
+ if (test.steps?.length) {
328
+ const failedSteps = test.steps
329
+ if (failedSteps.length) testMessage += '\n STEP: ' + failedSteps.map(s => s.toCode()).join('; ')
330
+ }
331
+
332
+ const pageInfo = test.notes.find(n => n.type === 'pageInfo')
333
+ if (pageInfo) {
334
+ testMessage += '\n PAGE INFO: ' + pageInfo.text
335
+ }
336
+
337
+ return testMessage
338
+ }
339
+
340
+ function formatResponse(response) {
341
+ if (!response.startsWith('##')) response = '## ' + response
342
+ return response
343
+ .split('\n')
344
+ .map(line => line.trim())
345
+ .filter(line => !/^[A-Z\s]+$/.test(line))
346
+ .map(line => markdownToAnsi(line))
347
+ .map(line => line.replace(/^x /gm, ` ${colors.red.bold('x')} `))
348
+ .join('\n')
349
+ }
@@ -2,8 +2,8 @@ const Container = require('../container')
2
2
  const store = require('../store')
3
3
  const recorder = require('../recorder')
4
4
  const event = require('../event')
5
- const log = require('../output').log
6
- const supportedHelpers = require('./standardActingHelpers').slice()
5
+ const { log } = require('../output')
6
+ const standardActingHelpers = Container.STANDARD_ACTING_HELPERS
7
7
 
8
8
  const methodsToDelay = ['click', 'fillField', 'checkOption', 'pressKey', 'doubleClick', 'rightClick']
9
9
 
@@ -7,6 +7,8 @@ let currentCommentStep
7
7
  const defaultGlobalName = '__'
8
8
 
9
9
  /**
10
+ * @deprecated
11
+ *
10
12
  * Add descriptive nested steps for your tests:
11
13
  *
12
14
  * ```js
@@ -100,6 +102,9 @@ const defaultGlobalName = '__'
100
102
  * ```
101
103
  */
102
104
  module.exports = function (config) {
105
+ console.log('commentStep is deprecated, disable it and use Section instead')
106
+ console.log('const { Section: __ } = require("codeceptjs/steps")')
107
+
103
108
  event.dispatcher.on(event.test.started, () => {
104
109
  currentCommentStep = null
105
110
  })
@@ -0,0 +1,52 @@
1
+ const event = require('../event')
2
+
3
+ /**
4
+ * Sample custom reporter for CodeceptJS.
5
+ */
6
+ module.exports = function (config) {
7
+ event.dispatcher.on(event.hook.finished, hook => {
8
+ if (config.onHookFinished) {
9
+ config.onHookFinished(hook)
10
+ }
11
+ })
12
+
13
+ event.dispatcher.on(event.test.before, test => {
14
+ if (config.onTestBefore) {
15
+ config.onTestBefore(test)
16
+ }
17
+ })
18
+
19
+ event.dispatcher.on(event.test.failed, (test, err) => {
20
+ if (config.onTestFailed) {
21
+ config.onTestFailed(test, err)
22
+ }
23
+ })
24
+
25
+ event.dispatcher.on(event.test.passed, test => {
26
+ if (config.onTestPassed) {
27
+ config.onTestPassed(test)
28
+ }
29
+ })
30
+
31
+ event.dispatcher.on(event.test.skipped, test => {
32
+ if (config.onTestSkipped) {
33
+ config.onTestSkipped(test)
34
+ }
35
+ })
36
+
37
+ event.dispatcher.on(event.test.finished, test => {
38
+ if (config.onTestFinished) {
39
+ config.onTestFinished(test)
40
+ }
41
+ })
42
+
43
+ event.dispatcher.on(event.all.result, result => {
44
+ if (config.onResult) {
45
+ config.onResult(result)
46
+ }
47
+
48
+ if (config.save) {
49
+ result.save()
50
+ }
51
+ })
52
+ }
@@ -5,6 +5,7 @@ const event = require('../event')
5
5
  const output = require('../output')
6
6
  const heal = require('../heal')
7
7
  const store = require('../store')
8
+ const container = require('../container')
8
9
 
9
10
  const defaultConfig = {
10
11
  healLimit: 2,
@@ -115,4 +116,33 @@ module.exports = function (config = {}) {
115
116
  i++
116
117
  }
117
118
  })
119
+
120
+ event.dispatcher.on(event.workers.result, result => {
121
+ const { print } = output
122
+
123
+ const healedTests = Object.values(result.tests)
124
+ .flat()
125
+ .filter(test => test.notes.some(note => note.type === 'heal'))
126
+ if (!healedTests.length) return
127
+
128
+ setTimeout(() => {
129
+ print('')
130
+ print('===================')
131
+ print(colors.bold.green('Self-Healing Report:'))
132
+
133
+ print('')
134
+ print('Suggested changes:')
135
+ print('')
136
+
137
+ healedTests.forEach(test => {
138
+ print(`${colors.bold.magenta(test.title)}`)
139
+ test.notes
140
+ .filter(note => note.type === 'heal')
141
+ .forEach(note => {
142
+ print(note.text)
143
+ print('')
144
+ })
145
+ })
146
+ }, 0)
147
+ })
118
148
  }
@@ -0,0 +1,140 @@
1
+ const path = require('path')
2
+ const fs = require('fs')
3
+ const Container = require('../container')
4
+ const recorder = require('../recorder')
5
+ const event = require('../event')
6
+ const supportedHelpers = Container.STANDARD_ACTING_HELPERS
7
+ const { scanForErrorMessages } = require('../html')
8
+ const { output } = require('..')
9
+ const { humanizeString, ucfirst } = require('../utils')
10
+ const { testToFileName } = require('../mocha/test')
11
+ const defaultConfig = {
12
+ errorClasses: ['error', 'warning', 'alert', 'danger'],
13
+ browserLogs: ['error'],
14
+ }
15
+
16
+ /**
17
+ * Collects information from web page after each failed test and adds it to the test as an artifact.
18
+ * It is suggested to enable this plugin if you run tests on CI and you need to debug failed tests.
19
+ * This plugin can be paired with `analyze` plugin to provide more context.
20
+ *
21
+ * It collects URL, HTML errors (by classes), and browser logs.
22
+ *
23
+ * Enable this plugin in config:
24
+ *
25
+ * ```js
26
+ * plugins: {
27
+ * pageInfo: {
28
+ * enabled: true,
29
+ * }
30
+ * ```
31
+ *
32
+ * Additional config options:
33
+ *
34
+ * * `errorClasses` - list of classes to search for errors (default: `['error', 'warning', 'alert', 'danger']`)
35
+ * * `browserLogs` - list of types of errors to search for in browser logs (default: `['error']`)
36
+ *
37
+ */
38
+ module.exports = function (config = {}) {
39
+ const helpers = Container.helpers()
40
+ let helper
41
+
42
+ config = Object.assign(defaultConfig, config)
43
+
44
+ for (const helperName of supportedHelpers) {
45
+ if (Object.keys(helpers).indexOf(helperName) > -1) {
46
+ helper = helpers[helperName]
47
+ }
48
+ }
49
+
50
+ if (!helper) return // no helpers for screenshot
51
+
52
+ event.dispatcher.on(event.test.failed, test => {
53
+ const pageState = {}
54
+
55
+ recorder.add('URL of failed test', async () => {
56
+ try {
57
+ const url = await helper.grabCurrentUrl()
58
+ pageState.url = url
59
+ } catch (err) {
60
+ // not really needed
61
+ }
62
+ })
63
+ recorder.add('HTML snapshot failed test', async () => {
64
+ try {
65
+ const html = await helper.grabHTMLFrom('body')
66
+
67
+ if (!html) return
68
+
69
+ const errors = scanForErrorMessages(html, config.errorClasses)
70
+ if (errors.length) {
71
+ output.debug('Detected errors in HTML code')
72
+ errors.forEach(error => output.debug(error))
73
+ pageState.htmlErrors = errors
74
+ }
75
+ } catch (err) {
76
+ // not really needed
77
+ }
78
+ })
79
+
80
+ recorder.add('Browser logs for failed test', async () => {
81
+ try {
82
+ const logs = await helper.grabBrowserLogs()
83
+
84
+ if (!logs) return
85
+
86
+ pageState.browserErrors = getBrowserErrors(logs, config.browserLogs)
87
+ } catch (err) {
88
+ // not really needed
89
+ }
90
+ })
91
+
92
+ recorder.add('Save page info', () => {
93
+ test.addNote('pageInfo', pageStateToMarkdown(pageState))
94
+
95
+ const pageStateFileName = path.join(global.output_dir, `${testToFileName(test)}.pageInfo.md`)
96
+ fs.writeFileSync(pageStateFileName, pageStateToMarkdown(pageState))
97
+ test.artifacts.pageInfo = pageStateFileName
98
+ return pageState
99
+ })
100
+ })
101
+ }
102
+
103
+ function pageStateToMarkdown(pageState) {
104
+ let markdown = ''
105
+
106
+ for (const [key, value] of Object.entries(pageState)) {
107
+ if (!value) continue
108
+ let result = ''
109
+
110
+ if (Array.isArray(value)) {
111
+ result = value.map(v => `- ${JSON.stringify(v, null, 2)}`).join('\n')
112
+ } else if (typeof value === 'string') {
113
+ result = `${value}`
114
+ } else {
115
+ result = JSON.stringify(value, null, 2)
116
+ }
117
+
118
+ if (!result.trim()) continue
119
+
120
+ markdown += `### ${ucfirst(humanizeString(key))}\n\n`
121
+ markdown += result
122
+ markdown += '\n\n'
123
+ }
124
+
125
+ return markdown
126
+ }
127
+
128
+ function getBrowserErrors(logs, type = ['error']) {
129
+ // Playwright & WebDriver console messages
130
+ let errors = logs
131
+ .map(log => {
132
+ if (typeof log === 'string') return log
133
+ if (!log.type) return null
134
+ return { type: log.type(), text: log.text() }
135
+ })
136
+ .filter(l => l && (typeof l === 'string' || type.includes(l.type)))
137
+ .map(l => (typeof l === 'string' ? l : l.text))
138
+
139
+ return errors
140
+ }