test: update user context tests checking the number of user contexts (#11877)

This commit is contained in:
Julian Descottes 2024-02-08 11:52:05 +01:00 committed by GitHub
parent 4b52841979
commit 3b43b1fa07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 10 deletions

View File

@ -1476,8 +1476,7 @@
"testIdPattern": "[browsercontext.spec] BrowserContext should create new incognito context",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "Fails because test assumes there is 1 user context initially, Firefox has 5"
"expectations": ["PASS"]
},
{
"testIdPattern": "[browsercontext.spec] BrowserContext should fire target events",
@ -1496,8 +1495,7 @@
"testIdPattern": "[browsercontext.spec] BrowserContext should have default context",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "Fails because test assumes there is 1 user context initially, Firefox has 5"
"expectations": ["PASS"]
},
{
"testIdPattern": "[browsercontext.spec] BrowserContext should timeout waiting for a non-existent target",

View File

@ -18,9 +18,13 @@ describe('BrowserContext', function () {
const {browser} = await getTestState({
skipContextCreation: true,
});
expect(browser.browserContexts()).toHaveLength(1);
const defaultContext = browser.browserContexts()[0]!;
expect(defaultContext!.isIncognito()).toBe(false);
expect(browser.browserContexts().length).toBeGreaterThanOrEqual(1);
const defaultContext = browser.browserContexts().find(context => {
return !context.isIncognito();
});
expect(defaultContext).toBeDefined();
let error!: Error;
await defaultContext!.close().catch(error_ => {
return (error = error_);
@ -33,13 +37,14 @@ describe('BrowserContext', function () {
skipContextCreation: true,
});
expect(browser.browserContexts()).toHaveLength(1);
const contextCount = browser.browserContexts().length;
expect(contextCount).toBeGreaterThanOrEqual(1);
const context = await browser.createBrowserContext();
expect(context.isIncognito()).toBe(true);
expect(browser.browserContexts()).toHaveLength(2);
expect(browser.browserContexts()).toHaveLength(contextCount + 1);
expect(browser.browserContexts().indexOf(context) !== -1).toBe(true);
await context.close();
expect(browser.browserContexts()).toHaveLength(1);
expect(browser.browserContexts()).toHaveLength(contextCount);
});
it('should close all belonging targets once closing context', async () => {
const {browser} = await getTestState({