Closed hsiaalex closed 1 month ago
My test.spec takes some screenshots, I would like to use the same outputFolder to keep everything together.
I'm not sure I understand this. HTML reporter will always copy all the resources to under its folder for sharing. Your feature title does not seem to be related to the feature description though.
I have this code in my playwright.config.ts
const currentDateTime = new Date();
const adjustedDateTime = new Date(currentDateTime - currentDateTime.getTimezoneOffset() * 60 * 1000).toISOString().replace(/[:.]/g, "_").slice(0, -1);
const outputFolder = `./playwright-report/${adjustedDateTime}`;
export default defineConfig({
reporter: [["html", { outputFolder }]],
// project configs
});
In my test.spec.ts
I have
await page.screenshot({ path: `${testInfo.project.name}.png` });
I want to use outputFolder
from playwright.config.ts
so my test.spec.ts
could be:
await page.screenshot({ path: `${outputFolder}/${testInfo.project.name}.png` });
I want to use
outputFolder
fromplaywright.config.ts
so mytest.spec.ts
could be:await page.screenshot({ path: `${outputFolder}/${testInfo.project.name}.png` });
I wouldn't recommend that. You are putting files inside the html report's directory. Html reporter assumes ownership of its output directory, so it could easily remove any files there. I believe it already does that today.
On your question about passing values from config to test file, you can export/import as with any javascript file:
// playwright.config.ts
export const someValue = 'value';
// example.spec.ts
import { someValue } from '../playwright.config';
Let me know whether that helps.
On your question about passing values from config to test file, you can export/import as with any javascript file:
// playwright.config.ts export const someValue = 'value';
// example.spec.ts import { someValue } from '../playwright.config';
Let me know whether that helps.
I tried this shortly after posting my question, it worked (test.spec.ts could import outputFolder) but HTML reporter wasn't outputting. I'll have to take another look, but I might just use a different directory so my screenshots don't get removed accidentally (by HTML reporter) - or I might use test.attach to include (copies of) the screenshots in the HTML report.
Closing as per above. To recap:
test.info().attach()
instead.
🚀 Feature Request
Based on https://github.com/microsoft/playwright/issues/19010#issuecomment-1325555092 I am adjusting the HTML reporter output path so I can keep copies of previous test runs.
My
test.spec
takes some screenshots, I would like to use the sameoutputFolder
to keep everything together.Example
playwright-report/ ├── outputFolder/ │ ├── index.html │ ├── screenshot.png │ └── trace.zip └── another outputFolder/
Motivation
Define some variables in
playwright.config
that can be used anywhere else. In this example, I want to organize everything from the run into the sameoutputFolder
.