MCPcopy
hub / github.com/codeceptjs/CodeceptJS / eachElement

Function eachElement

lib/els.js:39–70  ·  view source on GitHub ↗
(purpose, locator, fn)

Source from the content-addressed store, hash-verified

37}
38
39function eachElement(purpose, locator, fn) {
40 if (!fn) {
41 fn = locator
42 locator = purpose
43 purpose = 'for each element'
44 }
45
46 const step = prepareStep(purpose, locator, fn)
47 if (!step) return
48
49 return executeStep(step, async () => {
50 const els = await step.helper._locate(locator)
51 output.debug(`Found ${els.length} elements for each elements to iterate`)
52
53 const errs = []
54 let i = 0
55 for (const el of els) {
56 try {
57 const wrapped = new WebElement(el, step.helper)
58 await fn(wrapped, i)
59 } catch (err) {
60 output.error(`eachElement: failed operation on element #${i} ${el}`)
61 errs.push(err)
62 }
63 i++
64 }
65
66 if (errs.length) {
67 throw errs[0]
68 }
69 })
70}
71
72function expectElement(locator, fn) {
73 const step = prepareStep('expect element to be', locator, fn)

Callers 1

els_test.jsFile · 0.90

Calls 6

prepareStepFunction · 0.85
executeStepFunction · 0.85
debugMethod · 0.80
pushMethod · 0.80
fnFunction · 0.50
_locateMethod · 0.45

Tested by

no test coverage detected