Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: inherit apiRequestContext timeout from actionTimeout (#23481)
Max Schmittaf893a101965
diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.tsindex bb90938546..ad40c2782c 100644--- a/packages/playwright-test/src/index.ts+++ b/packages/playwright-test/src/index.ts@@ -260,6 +260,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({}(playwright.request as any)._defaultContextOptions = { ..._combinedContextOptions };(playwright.request as any)._defaultContextOptions.tracesDir = path.join(_artifactsDir(), 'traces');+ (playwright.request as any)._defaultContextOptions.timeout = actionTimeout || 0;await use();(playwright.request as any)._defaultContextOptions = undefined;for (const browserType of [playwright.chromium, playwright.firefox, playwright.webkit]) {diff --git a/tests/playwright-test/playwright.spec.ts b/tests/playwright-test/playwright.spec.tsindex e8423aa4d6..7d31237c48 100644--- a/tests/playwright-test/playwright.spec.ts+++ b/tests/playwright-test/playwright.spec.ts@@ -767,3 +767,58 @@ test('fulfill with return path of the entry', async ({ runInlineTest }) => {expect(result.exitCode).toBe(0);expect(result.passed).toBe(1);});++test('should use actionTimeout for APIRequestContext', async ({ runInlineTest, server }) => {+ server.setRoute('/stall', (req, res) => {});+ const result = await runInlineTest({+ 'playwright.config.js': `+ module.exports = {+ use: {+ actionTimeout: 1111,+ baseURL: '${server.PREFIX}',+ }+ };+ `,+ 'a.test.ts': `+ import { test, expect } from '@playwright/test';+ test('default APIRequestContext fixture', async ({ request }) => {+ await expect(request.get('/stall')).rejects.toThrow('apiRequestContext.get: Request timed out after 1111ms');+ });+ test('newly created APIRequestContext without options', async ({ playwright }) => {+ const apiRequestContext = await playwright.request.newContext();+ await expect(apiRequestContext.get('/stall')).rejects.toThrow('apiRequestContext.get: Request timed out after 1111ms');+ });+ test('newly created APIRequestContext with options', async ({ playwright }) => {+ const apiRequestContextWithOptions = await playwright.request.newContext({ httpCredentials: { username: 'user', password: 'pass' } });+ await expect(apiRequestContextWithOptions.get('/stall')).rejects.toThrow('apiRequestContext.get: Request timed out after 1111ms');+ });+ `,+ }, { workers: 1 });+ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(3);+});++test('should cancel apiRequests if test will timeout', async ({ runInlineTest, server }) => {+ server.setRoute('/stall', (req, res) => {});+ const result = await runInlineTest({+ 'playwright.config.js': `+ module.exports = {+ timeout: 1000,+ use: {+ baseURL: '${server.PREFIX}',+ }+ };+ `,+ 'a.test.ts': `+ import { test, expect } from '@playwright/test';+ test('pass', async ({ request }) => {+ await request.get('/stall')+ });+ `,+ }, { workers: 1 });+ expect(result.exitCode).toBe(1);+ expect(result.passed).toBe(0);+ expect(result.failed).toBe(1);+ expect(result.output).toContain('apiRequestContext.get: Request context disposed.');+ expect(result.output).toContain('Test timeout of 1000ms exceeded.');+});