(purpose, locator, fn)
| 9 | import WebElement from './element/WebElement.js' |
| 10 | |
| 11 | function element(purpose, locator, fn) { |
| 12 | let stepConfig |
| 13 | if (StepConfig.isStepConfig(arguments[arguments.length - 1])) { |
| 14 | stepConfig = arguments[arguments.length - 1] |
| 15 | } |
| 16 | |
| 17 | if (!fn || fn === stepConfig) { |
| 18 | fn = locator |
| 19 | locator = purpose |
| 20 | purpose = 'first element' |
| 21 | } |
| 22 | |
| 23 | const step = prepareStep(purpose, locator, fn) |
| 24 | if (!step) return |
| 25 | |
| 26 | return executeStep( |
| 27 | step, |
| 28 | async () => { |
| 29 | const els = await step.helper._locate(locator) |
| 30 | output.debug(`Found ${els.length} elements, using first element`) |
| 31 | |
| 32 | const wrapped = new WebElement(els[0], step.helper) |
| 33 | return fn(wrapped) |
| 34 | }, |
| 35 | stepConfig, |
| 36 | ) |
| 37 | } |
| 38 | |
| 39 | function eachElement(purpose, locator, fn) { |
| 40 | if (!fn) { |
no test coverage detected