reportportal / agent-js-playwright

Agent to integrate Playwright with ReportPortal.
https://www.npmjs.com/package/@reportportal/agent-js-playwright
Apache License 2.0
33 stars 14 forks source link

Attachment (screenshot) not being added to report portal #158

Open noopurmath3 opened 2 days ago

noopurmath3 commented 2 days ago

Hello,

I am trying to add screenshot to reportportal report using testinfo.attach. However, I only see the log message for the attachment even though the screenshot is captured and present at the mentioned path and the attachment is never attached to the report. Refer screenshot below: reportportal

This is how my playwright.config.ts looks like:

import { defineConfig, devices } from '@playwright/test';
const RPconfig = {
  apiKey: `xxx`,
  endpoint: 'internal reportportal instance',
  project: 'test',
  launch: 'test',
  uploadTrace: 'true',
  attributes: [
    {
      key: 'agent',
      value: 'playwright',
    },
  ],
  description: 'test',
  restClientConfig: {
    timeout: 0,
    agent: {
      rejectUnauthorized: false,
    },
  },
};

export default defineConfig({
  testDir: './tests',
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 1 : undefined,
  reporter: [['@reportportal/agent-js-playwright', RPconfig]],
  use: {
    trace: 'on-first-retry',
  },
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },

    {
      name: 'firefox',
      use: { ...devices['Desktop Firefox'] },
    },

    {
      name: 'webkit',
      use: { ...devices['Desktop Safari'] },
    },
  ],
});

And this is the test fie:

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

test('has title', async ({ page }) => {
  await page.goto('https://playwright.dev/');

  // Expect a title "to contain" a substring.
  await expect(page).toHaveTitle(/Playwright/);
});

test('get started link', async ({ page }) => {
  await page.goto('https://playwright.dev/');

  // Click the get started link.
  await page.getByRole('link', { name: 'Get started' }).click();

  // Expects page to have a heading with the name of Installation.
  await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});

test('screenshot test', async ({ page }, testInfo) => {
  await page.goto('https://playwright.dev');

  // Capture a screenshot and attach it
  const screenshot = await page.screenshot({ path: `./test-results/screenshots/${testInfo.title}.png` });
  await testInfo.attach('screenshot', { body: screenshot, contentType: 'image/png' });
});

Please let me know if I am missing anything here

AmsterGet commented 2 days ago

Hello @noopurmath3 ! I ran your test case with the provided config and it works on my side. Tested with @playwright/test version 1.47.2, @reportportportal/agent-js-playwright version 5.1.11, Node.js 20.15, OS Windows 11. Could you please share your setup?