···173173 */
174174 upload: (element: Element | Locator, files: File | File[] | string | string[]) => Promise<void>
175175 /**
176176+ * Copies the selected content.
177177+ * @see {@link https://playwright.dev/docs/api/class-keyboard} Playwright API
178178+ * @see {@link https://webdriver.io/docs/api/browser/keys//} WebdriverIO API
179179+ * @see {@link https://testing-library.com/docs/user-event/clipboard#copy} testing-library API
180180+ */
181181+ copy: () => Promise<void>
182182+ /**
183183+ * Cuts the selected content.
184184+ * @see {@link https://playwright.dev/docs/api/class-keyboard} Playwright API
185185+ * @see {@link https://webdriver.io/docs/api/browser/keys//} WebdriverIO API
186186+ * @see {@link https://testing-library.com/docs/user-event/clipboard#cut} testing-library API
187187+ */
188188+ cut: () => Promise<void>
189189+ /**
190190+ * Pastes the copied or cut content.
191191+ * @see {@link https://playwright.dev/docs/api/class-keyboard} Playwright API
192192+ * @see {@link https://webdriver.io/docs/api/browser/keys//} WebdriverIO API
193193+ * @see {@link https://testing-library.com/docs/user-event/clipboard#paste} testing-library API
194194+ */
195195+ paste: () => Promise<void>
196196+ /**
176197 * Fills an input element with text. This will remove any existing text in the input before typing the new text.
177198 * Uses provider's API under the hood.
178199 * This API is faster than using `userEvent.type` or `userEvent.keyboard`, but it **doesn't support** [user-event `keyboard` syntax](https://testing-library.com/docs/user-event/keyboard) (e.g., `{Shift}`).
+78
docs/guide/browser/interactivity-api.md
···518518519519- [Playwright `frame.dragAndDrop` API](https://playwright.dev/docs/api/class-frame#frame-drag-and-drop)
520520- [WebdriverIO `element.dragAndDrop` API](https://webdriver.io/docs/api/element/dragAndDrop/)
521521+522522+## userEvent.copy
523523+524524+```ts
525525+function copy(): Promise<void>
526526+```
527527+528528+Copy the selected text to the clipboard.
529529+530530+```js
531531+import { page, userEvent } from '@vitest/browser/context'
532532+533533+test('copy and paste', async () => {
534534+ // write to 'source'
535535+ await userEvent.click(page.getByPlaceholder('source'))
536536+ await userEvent.keyboard('hello')
537537+538538+ // select and copy 'source'
539539+ await userEvent.dblClick(page.getByPlaceholder('source'))
540540+ await userEvent.copy()
541541+542542+ // paste to 'target'
543543+ await userEvent.click(page.getByPlaceholder('target'))
544544+ await userEvent.paste()
545545+546546+ await expect.element(page.getByPlaceholder('source')).toHaveTextContent('hello')
547547+ await expect.element(page.getByPlaceholder('target')).toHaveTextContent('hello')
548548+})
549549+```
550550+551551+References:
552552+553553+- [testing-library `copy` API](https://testing-library.com/docs/user-event/convenience/#copy)
554554+555555+## userEvent.cut
556556+557557+```ts
558558+function cut(): Promise<void>
559559+```
560560+561561+Cut the selected text to the clipboard.
562562+563563+```js
564564+import { page, userEvent } from '@vitest/browser/context'
565565+566566+test('copy and paste', async () => {
567567+ // write to 'source'
568568+ await userEvent.click(page.getByPlaceholder('source'))
569569+ await userEvent.keyboard('hello')
570570+571571+ // select and cut 'source'
572572+ await userEvent.dblClick(page.getByPlaceholder('source'))
573573+ await userEvent.cut()
574574+575575+ // paste to 'target'
576576+ await userEvent.click(page.getByPlaceholder('target'))
577577+ await userEvent.paste()
578578+579579+ await expect.element(page.getByPlaceholder('source')).toHaveTextContent('')
580580+ await expect.element(page.getByPlaceholder('target')).toHaveTextContent('hello')
581581+})
582582+```
583583+584584+References:
585585+586586+- [testing-library `cut` API](https://testing-library.com/docs/user-event/clipboard#cut)
587587+588588+## userEvent.paste
589589+590590+```ts
591591+function paste(): Promise<void>
592592+```
593593+594594+Paste the text from the clipboard. See [`userEvent.copy`](#userevent-copy) and [`userEvent.cut`](#userevent-cut) for usage examples.
595595+596596+References:
597597+598598+- [testing-library `paste` API](https://testing-library.com/docs/user-event/clipboard#paste)