* {{> attachFile }} *
(locator, pathToFile, context = null)
| 2344 | * |
| 2345 | */ |
| 2346 | async attachFile(locator, pathToFile, context = null) { |
| 2347 | const file = path.join(store.codeceptDir, pathToFile) |
| 2348 | |
| 2349 | if (!fileExists(file)) { |
| 2350 | throw new Error(`File at ${file} can not be found on local system`) |
| 2351 | } |
| 2352 | const els = await findFields.call(this, locator, context) |
| 2353 | if (els.length) { |
| 2354 | const el = selectElement(els, locator, this) |
| 2355 | const tag = await el.evaluate(el => el.tagName) |
| 2356 | const type = await el.evaluate(el => el.type) |
| 2357 | if (tag === 'INPUT' && type === 'file') { |
| 2358 | await el.setInputFiles(file) |
| 2359 | return this._waitForAction() |
| 2360 | } |
| 2361 | } |
| 2362 | |
| 2363 | const targetEls = els.length ? els : await this._locate(locator) |
| 2364 | assertElementExists(targetEls, locator, 'Element') |
| 2365 | const el = selectElement(targetEls, locator, this) |
| 2366 | const fileData = { |
| 2367 | base64Content: base64EncodeFile(file), |
| 2368 | fileName: path.basename(file), |
| 2369 | mimeType: getMimeType(path.basename(file)), |
| 2370 | } |
| 2371 | await el.evaluate(dropFile, fileData) |
| 2372 | return this._waitForAction() |
| 2373 | } |
| 2374 | |
| 2375 | /** |
| 2376 | * {{> selectOption }} |
nothing calls this directly
no test coverage detected