Skip to content

feat: Add apiURL config option for API testing [WIP] #35765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

StevenBoutcher
Copy link

@StevenBoutcher StevenBoutcher commented Apr 27, 2025

feat: Add apiURL config option for API testing

Feature Request Source:

https://github.com/microsoft/playwright/issues/23738?ref=playwrightsolutions.com

Description

This PR introduces a new configuration option called apiURL that allows users to specify a separate URL for API requests. This is particularly useful for projects where the frontend and API endpoints have different base URLs.

Motivation

When conducting tests that involve both UI and API interactions, users often need to target different base URLs. Previously, they had to use only baseURL which was shared for both page navigation and API requests, or manually prepend URLs for API calls.

With this change, users can now configure:

  • baseURL for page navigation
  • apiURL for API requests using the request fixture

Implementation details

  • Added apiURL to PlaywrightTestOptions and PlaywrightWorkerOptions interfaces
  • Created an apiURL fixture with undefined as the default value (making it optional)
  • Modified the request fixture to use apiURL for the baseURL parameter when creating a new context
  • Added documentation explaining the new option

Example usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: {
    // Used for page.goto() and other UI navigation
    baseURL: 'http://localhost:3000',
    
    // Used for API requests via the request fixture
    apiURL: 'http://localhost:3000/api',
  }
});

Related docs

Documentation has been updated in api-testing-js.md to explain the new option and its relationship with baseURL.

@StevenBoutcher StevenBoutcher force-pushed the optional-apiurl-config branch from fcd76f8 to 69115f8 Compare April 27, 2025 15:11

This comment has been minimized.

This comment has been minimized.

@StevenBoutcher StevenBoutcher changed the title feat: Add apiUrl config option for API testing [WIP] feat: Add apiURL config option for API testing [WIP] Apr 27, 2025

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

Test results for "tests 1"

10 failed
❌ [playwright-test] › playwright.fetch.spec.ts:35:5 › should use baseURL in request fixture @macos-latest-node18-1
❌ [playwright-test] › playwright.spec.ts:749:5 › should use actionTimeout for APIRequestContext @macos-latest-node18-1
❌ [playwright-test] › playwright.fetch.spec.ts:35:5 › should use baseURL in request fixture @ubuntu-latest-node18-1
❌ [playwright-test] › playwright.spec.ts:749:5 › should use actionTimeout for APIRequestContext @ubuntu-latest-node18-1
❌ [playwright-test] › playwright.fetch.spec.ts:35:5 › should use baseURL in request fixture @ubuntu-latest-node20-1
❌ [playwright-test] › playwright.spec.ts:749:5 › should use actionTimeout for APIRequestContext @ubuntu-latest-node20-1
❌ [playwright-test] › playwright.fetch.spec.ts:35:5 › should use baseURL in request fixture @ubuntu-latest-node22-1
❌ [playwright-test] › playwright.spec.ts:749:5 › should use actionTimeout for APIRequestContext @ubuntu-latest-node22-1
❌ [playwright-test] › playwright.fetch.spec.ts:35:5 › should use baseURL in request fixture @windows-latest-node18-1
❌ [playwright-test] › playwright.spec.ts:749:5 › should use actionTimeout for APIRequestContext @windows-latest-node18-1

6 flaky ⚠️ [chromium-library] › library/chromium/oopif.spec.ts:284:3 › should click @chromium-ubuntu-22.04-node20
⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:986:7 › cli codegen › should not throw csp directive violation errors @firefox-ubuntu-22.04-node18
⚠️ [firefox-page] › page/page-evaluate.spec.ts:424:3 › should throw for too deep reference chain @firefox-ubuntu-22.04-node18
⚠️ [webkit-library] › library/browsercontext-device.spec.ts:45:5 › device › should scroll to click @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-set-input-files.spec.ts:38:5 › should upload a folder @webkit-ubuntu-22.04-node18
⚠️ [playwright-test] › ui-mode-test-watch.spec.ts:145:5 › should watch all @windows-latest-node18-1

39075 passed, 803 skipped
✔️✔️✔️

Merge workflow run.

@StevenBoutcher StevenBoutcher deleted the optional-apiurl-config branch April 27, 2025 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant