November 11th, 2024

Improved

Generic Attachments for Playwright Tests

You can attach arbitrary files and content directly to your Playwright tests, making it easier to capture relevant data for review and improved collaboration with your team. With the recent update to Currents you can browse and download arbitrary test attachments.

The attachments will be securely uploaded and stored in Currents cloud storage.

  • Requires @currents/playwright 1.6.0+

  • No extra charge and not limitation to volume

  • Subject to your plan’s retention policy

This change unlocks further improvements to Currents platforms that are based on parsing attachments associated with the tests. A few examples:

  • Markdown file for test documentation and notes

  • Lighthouse reports to track accessibility and web vitals

  • Mermaid for charts and diagrams

How to Attach Files to Playwright Tests

Use the following syntax to add attachments to your test:

test('example test with attachment', async ({ page }, testInfo) => {
  // Your test steps
  // ..
  // Attach an MD file
  testInfo.attachments.push({
    name: "mdFile",
    payload: {
      path: "./files/test.md",
    }
  });
});

If you want to embed custom content directly, use:

test('example test with custom content', async ({ page }, testInfo) => { 
  // Your test steps 
  // Attach custom content 
  const logContent = 'Example log content'; 
  testInfo.attachments.push({ 
    name: 'log', 
    body: Buffer.from(logContent), 
    contentType: 'text/plain',
  });
});