mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
test: storageState from config key (#18581)
This commit is contained in:
parent
3a24e88e61
commit
a9c15a25f8
@ -184,7 +184,6 @@ test('should load context storageState from storage', async ({ runInlineTest, se
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should load storageState specified in the project config from storage', async ({ runInlineTest, server }) => {
|
test('should load storageState specified in the project config from storage', async ({ runInlineTest, server }) => {
|
||||||
test.fixme();
|
|
||||||
server.setRoute('/setcookie.html', (req, res) => {
|
server.setRoute('/setcookie.html', (req, res) => {
|
||||||
res.setHeader('Set-Cookie', ['a=v1']);
|
res.setHeader('Set-Cookie', ['a=v1']);
|
||||||
res.end();
|
res.end();
|
||||||
@ -205,8 +204,53 @@ test('should load storageState specified in the project config from storage', as
|
|||||||
`,
|
`,
|
||||||
'storage.setup.ts': `
|
'storage.setup.ts': `
|
||||||
const { test, expect } = pwt;
|
const { test, expect } = pwt;
|
||||||
test.use({
|
test.reset({
|
||||||
storageState: undefined
|
storageState: 'default'
|
||||||
|
})
|
||||||
|
test('should save storageState', async ({ page, context, storage }, testInfo) => {
|
||||||
|
expect(await storage.get('stateInStorage')).toBe(undefined);
|
||||||
|
await page.goto('${server.PREFIX}/setcookie.html');
|
||||||
|
const state = await page.context().storageState();
|
||||||
|
await storage.set('stateInStorage', state);
|
||||||
|
console.log('project setup state = ' + state);
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
'a.test.ts': `
|
||||||
|
const { test } = pwt;
|
||||||
|
test('should get data from setup', async ({ page, storage }, testInfo) => {
|
||||||
|
await page.goto('${server.EMPTY_PAGE}');
|
||||||
|
const cookies = await page.evaluate(() => document.cookie);
|
||||||
|
expect(cookies).toBe('a=v1');
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
}, { workers: 1 });
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.passed).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should load storageState specified in the global config from storage', async ({ runInlineTest, server }) => {
|
||||||
|
server.setRoute('/setcookie.html', (req, res) => {
|
||||||
|
res.setHeader('Set-Cookie', ['a=v1']);
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'playwright.config.js': `
|
||||||
|
module.exports = {
|
||||||
|
use: {
|
||||||
|
storageState: 'stateInStorage',
|
||||||
|
},
|
||||||
|
projects: [
|
||||||
|
{
|
||||||
|
name: 'p1',
|
||||||
|
setup: /.*storage.setup.ts/,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
`,
|
||||||
|
'storage.setup.ts': `
|
||||||
|
const { test, expect } = pwt;
|
||||||
|
test.reset({
|
||||||
|
storageState: 'default'
|
||||||
})
|
})
|
||||||
test('should save storageState', async ({ page, context, storage }, testInfo) => {
|
test('should save storageState', async ({ page, context, storage }, testInfo) => {
|
||||||
expect(await storage.get('stateInStorage')).toBe(undefined);
|
expect(await storage.get('stateInStorage')).toBe(undefined);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user