Issue 1:
Your question

I used this https://playwright.dev/java/docs/test-snapshots function

Can I somehow change the directory for saving screenshots?

Issue 2:
System info

Playwright Version: v1.36.1

Operating System: linux

Browser: [All]

Other info:

Source code

I provided exact source code that allows reproducing the issue locally.

Link to the GitHub repository with the repro

or

Config file

// playwright.config.ts
// @ts-check
const { defineConfig, devices } = require('@playwright/test');

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
/* screenshots on failure */
screenshot: 'only-on-failure',

//video: 'on'
},

/* Configure projects for major browsers */
projects: [

{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

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

},

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

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ..devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});

Test file (self-contained)

test_1.spec.js

// @ts-check
const { test, expect } = require('@playwright/test');

/** @type {import('@playwright/test').Page} */
let page;

test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
await page.goto("https://bing.com");
});

test.afterAll(async () => {
//await page.close();
});

test('Async test 1', async () => {
await page.goto('https://playwright.dev/community/welcome');
let heading = page.getByRole('heading', { name: 'Welcome' });
await expect(heading).toBeVisible();

});

test('Async test 2', async () => {
await page.goto('https://playwright.dev/docs/api/class-playwright');
let heading = page.getByRole('heading', { name: 'Playwright Library' });
await expect(heading).toBeVisible();
});

test('Steps are executed synchronously', async () => {
await test.step('Step 1', async () => {
await page.goto('https://playwright.dev/');
});

await test.step('Step 2', async () => {
await page.getByText('Get Started').click();
});

await test.step('Step 3', async () => {
let heading = page.getByRole('heading', { name: 'Installation' });
await expect(heading).toBeVisible();
});

});

test('Async test 3', async ({playwright}) => {

let html = `<html>
<head>
<title>tets</title>
<script>
function loop() {
document.getElementById('one').innerText = 'start';
for(let i=0;i<500000;i++) {
setTimeout(() => {
document.getElementById('one').innerText = i +' '+ Date.now() +' '+ crypto.randomUUID();
}, 50);

}
}
</script>
</head>
<body onload="loop()">
<h1 id='one'>pass</h1>

</body>
</html>`;
await page.setContent(html);
let heading = page.getByRole('heading');
await expect(heading).toHaveText('fail');

//await test.step('', async () => {
//});

});

test_2.spec.js

// @ts-check
const { test, expect } = require('@playwright/test');

/** @type {import('@playwright/test').Page} */
let page;

test.beforeAll(async ({ browser }) => {

page = await browser.newPage();
await page.goto("https://example.com");

});

test.afterAll(async () => {
//await page.close();
});

test('Async test 1', async () => {
await page.goto('https://example.com/community/welcome');
let heading = page.getByRole('heading', { name: 'Welcome' });
await expect(heading).toBeVisible();

});

test('Async test 2', async () => {
await page.goto('https://example.com/docs/api/class-playwright');
let heading = page.getByRole('heading', { name: 'Playwright Library' });
await expect(heading).toBeVisible();
});

test('Steps are executed synchronously', async () => {
await test.step('Step 1', async () => {
await page.goto('https://example.com/');
});

await test.step('Step 2', async () => {
await page.getByText('Get Started').click();
});

await test.step('Step 3', async () => {
let heading = page.getByRole('heading', { name: 'Installation' });
await expect(heading).toBeVisible();
});

});

test('Async test 3', async ({playwright}) => {

let html = `<html>
<head>
<title>tets</title>
<script>
function loop() {
document.getElementById('one').innerText = 'start';
for(let i=0;i<500000;i++) {
setTimeout(() => {
document.getElementById('one').innerText = i +' '+ Date.now() +' '+ crypto.randomUUID();
}, 50);

}
}
</script>
</head>
<body onload="loop()">
<h1 id='one'>pass</h1>

</body>
</html>`;
await page.setContent(html);
let heading = page.getByRole('heading');
await expect(heading).toHaveText('fail');

//await test.step('', async () => {
//});

});

Steps

Run the tests

Review test_2.spec.js failures

Expected

With the exception of "Async test 3" Only screenshots with example domain should be attached.

Actual

Usecase consists of config set to grab screenshots on failure and two test files of which one is failing all the tests. Even if tests are fully isolated , some of the screenshots show playwright.dev site instead of example.com

https://playwright.dev/docs/browser-contexts reads:

Isolation

Tests written with Playwright execute in isolated clean-slate environments called browser contexts. This isolation model improves reproducibility and prevents cascading test failures.

What is Test Isolation?

Test Isolation is when each test is completely isolated from another test.