79598654

Date: 2025-04-29 14:49:21
Score: 0.5
Natty:
Report link

Here is my working example, with its help I think it will be possible to adapt

import { test, expect } from '@playwright/test';
import * as fs from 'fs';

test('Drag and drop file into drop-zone', async ({ page, browserName }) => {
  test.skip(browserName === 'webkit', 'It does not work in WebKit');

  await page.goto('/app');

  const buffer = fs.readFileSync('tests/fixtures/example_file.jpg');

  // Prepare the DataTransfer with a file
  const dataTransfer = await page.evaluateHandle(async (data) => {
    const dt = new DataTransfer();
    const byteArray = Uint8Array.from(atob(data), char => char.charCodeAt(0));
    const file = new File([byteArray], 'example_file.jpg', { type: 'image/jpeg' });
    dt.items.add(file);
    return dt;
  }, buffer.toString('base64'));

  // Dispatch drop event to the drop zone
  await page.dispatchEvent('#drop-zone', 'drop', { dataTransfer });

  // Add your assertions here
});

This link was very helpful in solving this issue.

Reasons:
  • Blacklisted phrase (1): This link
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Yaroslav Khabarov