playwright
playwright copied to clipboard
[Feature]: add apiEndpoint to playwright.config.ts (similar to baseUrl)
Let us know what functionality you'd like to see in Playwright and what your use case is. Do you think others might benefit from this as well? Yes
From time to time, we like to test our API as well with Playwright. Sometimes the format is different from the baseUrl, that's why an apiEndpoint
might be beneficial. Of course, there are some workarounds, but they are less neath than how baseUrl works. (and apiEndpoint
should work)
My example: (is configured as baseUrl)
Web application URL: https://practicesoftwaretesting.com
API endpoint: https://api.practicesoftwaretesting.com
The various API request function should try to get the value of apiEndpoint
first and then append what is left.. ( similar to .goto()
)
Responds with a thumbs up if you like this addition.
Just to clarify, specifying baseURL does not work for you because you want another base URL for API requests than for page navigations?
import { test, expect } from '@playwright/test';
test.use({
baseURL: 'https://playwright.dev/'
})
test('test', async ({ request }) => {
const response = await request.get('/docs/intro')
expect(response).toBeOK();
})
That's correct! it would be very neath if we can set it in playwright.config.ts
also, In case we like to combine page navigations with API requests.
Not exactly what you asked but do you think any of this would be an workaround?
- using a environment variable
- using a constant but you would have to import it when you want it
- something similar to this issue, using fixtures to create an apiBaseURL
- https://github.com/microsoft/playwright/discussions/23699#discussioncomment-6170857
yes, I tried them all..
but it would be a very nice solution if this can be part of playwright.config.ts
(I think)
As a workaround you can create an option fixture apiBaseURL
and assign that to a value different from baseURL
, here is a sample project that does it:
https://github.com/yury-s/bug-23738
Thanks @yury-s is the workaround the way to go? or would this 'extra' property be part of the default playwright config?
No immediate plans to implement it. If the issue gets enough upvotes we may add it to the default config in the future.
It would be awesome to get it, but now I’m using external fixture with additional config.json where I put the port. Can’t wait to see it possible in default config! :)
Wysyłane z aplikacji Outlook dla systemu iOShttps://aka.ms/o0ukef
Od: Yury Semikhatsky @.> Wysłane: Wednesday, August 23, 2023 10:10:28 PM Do: microsoft/playwright @.> DW: Gedeon Kucharski @.>; Manual @.> Temat: Re: [microsoft/playwright] [Feature]: add apiEndpoint to playwright.config.ts (similar to baseUrl) (Issue #23738)
No immediate plans to implement it. If the issue gets enough upvotes we may add it to the default config in the future.
— Reply to this email directly, view it on GitHubhttps://github.com/microsoft/playwright/issues/23738#issuecomment-1690570376, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A63QOYD2TPZPLDDOANWMMQTXWZPTJANCNFSM6AAAAAAZIGJ4NU. You are receiving this because you are subscribed to this thread.Message ID: @.***>
Just chiming in to say that I would also love to have an apiURL
option in the base playwright config instead of needing to use workarounds. Thanks!
In my case, I need more than only two base urls, so maybe it could be a useful a host:string[] | undefined
instead of baseURL: string | undefined
.