admin管理员组文章数量:1332374
edit: different contexts in Playwright do have separate IndexedDB instances, all is well
I'm writing a web app that used IndexedDB for local storage, and also syncs with a server. In order to test scenarios with multiple clients, I need to have a single test with two contexts that don't share IndexedDB data.
The "Isolation" page on the docs site suggests that browser contexts should be completely isolated, but when I create two contexts like so:
const context1 = await browser.newContext();
const page1 = await context1.newPage();
const context2 = await browser.newContext();
const page2 = await context2.newPage();
page1 and page2 are accessing the same IndexedDB instance.
Is there a way to accomplish this?
edit: different contexts in Playwright do have separate IndexedDB instances, all is well
I'm writing a web app that used IndexedDB for local storage, and also syncs with a server. In order to test scenarios with multiple clients, I need to have a single test with two contexts that don't share IndexedDB data.
The "Isolation" page on the docs site suggests that browser contexts should be completely isolated, but when I create two contexts like so:
const context1 = await browser.newContext();
const page1 = await context1.newPage();
const context2 = await browser.newContext();
const page2 = await context2.newPage();
page1 and page2 are accessing the same IndexedDB instance.
Is there a way to accomplish this?
Share Improve this question edited Nov 24, 2024 at 19:27 Lukas Bergstrom asked Nov 21, 2024 at 7:03 Lukas BergstromLukas Bergstrom 7574 silver badges4 bronze badges 1- This was my mistake - I wasn't properly cleaning out the server backing store, and was re-populating IndexedDB from that. – Lukas Bergstrom Commented Nov 24, 2024 at 19:25
1 Answer
Reset to default 1I think you need to authenticate as two different roles, take a look at Multiple signed in roles, maybe you need to check this scenario: Testing multiple roles together
The key point is that you need to pass a different storageState
to each context
:
import { test } from '@playwright/test';
test('admin and user', async ({ browser }) => {
// adminContext and all pages inside, including adminPage, are signed in as "admin".
const adminContext = await browser.newContext({ storageState: 'playwright/.auth/admin.json' });
const adminPage = await adminContext.newPage();
// userContext and all pages inside, including userPage, are signed in as "user".
const userContext = await browser.newContext({ storageState: 'playwright/.auth/user.json' });
const userPage = await userContext.newPage();
// ... interact with both adminPage and userPage ...
await adminContext.close();
await userContext.close();
});
本文标签: javascriptHow do I create two contexts in a test with separate IndexedDBsStack Overflow
版权声明:本文标题:javascript - How do I create two contexts in a test with separate IndexedDBs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742308110a2450326.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论