Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Getgauge Taiko Attach

From Leeroopedia
Knowledge Sources
Domains Browser_Automation, Form_Interaction
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for programmatically attaching files to file input elements provided by the Taiko library.

Description

The attach() function sets files on an HTML <input type="file"> element using the CDP DOM.setFileInputFiles API, bypassing the native file picker dialog that cannot be controlled through standard automation techniques. It validates that each specified file exists on the filesystem before attempting the attachment, providing clear error messages for missing files.

The function accepts either a single file path string or an array of file paths for multi-file uploads. File paths are resolved relative to the current working directory. The target file input element is specified using the to() helper combined with a fileField() selector.

Usage

Use attach() whenever you need to upload files through a web form: attaching documents, uploading images, submitting CSV data files, or testing file type and size validation by attaching various test fixtures.

Code Reference

Source Location

  • Repository: Taiko
  • File: lib/taiko.js (L1150-1155, public API), lib/actions/attach.js (L13-46, implementation)

Signature

attach(filepath, to, options) -> Promise<void>

Import

const { attach, fileField, to } = require('taiko');

I/O Contract

Inputs

Name Type Required Description
filepath string / string[] Yes Path to the file(s) to attach. A single string for one file, or an array of strings for multiple files. Paths are resolved relative to the current working directory.
to Selector / string Yes The target file input element, specified using the to() helper with a fileField() selector (e.g., to(fileField('Upload'))).
options Object No Configuration options for the attach operation.
options.force boolean No If true, bypasses actionability checks. Default false.

Outputs

Name Type Description
return Promise<void> Resolves when the file(s) have been successfully attached to the file input element. Rejects if the file does not exist or the target element is not found.

Usage Examples

Attach a Single File

// Attach a PDF file to a file input labeled 'Upload'
await attach('resume.pdf', to(fileField('Upload')));

Attach Multiple Files

// Attach multiple files to a multi-file input
await attach(['file1.txt', 'file2.txt'], to(fileField({id: 'files'})));

Attach with Absolute Path

// Use an absolute path to the file
await attach('/home/user/documents/report.pdf', to(fileField('Document')));

Attach to File Field by Attribute

// Find the file input by its name attribute
await attach('photo.jpg', to(fileField({name: 'profile_picture'})));

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment