playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Question] Is there a way to return an api request response time?

Open BekaOkromchedlidze opened this issue 3 years ago • 13 comments

I am using the request fixture for API testing and I am just wondering is there a way to find what the api response time was?

BekaOkromchedlidze avatar Dec 21 '22 11:12 BekaOkromchedlidze

I don't think we have a feature like this. But request API is not done through the browser, so we don't have access to the detailed timing anyways.

pavelfeldman avatar Dec 22 '22 01:12 pavelfeldman

Did you see this info? Maybe it can helps you https://playwright.dev/docs/api/class-request#request-timing

klepik1990 avatar Dec 22 '22 08:12 klepik1990

@pavelfeldman I think this would be a very nice feature to have for api testing. It would be used to test performance sanity to make sure we get a response in an acceptable time.

@klepik1990 this is for the page fixture. We don't have this option for the request fixture

BekaOkromchedlidze avatar Dec 22 '22 08:12 BekaOkromchedlidze

It's not completely accurate, but you can do something like:

const requestDate = new Date();

// your request: await request ...

const responseDate = new Date();

console.log(responseDate - requestDate);

I agree that this feature will be very useful 😄

brunojbarros avatar Feb 23 '23 14:02 brunojbarros

+1

srieas avatar Mar 14 '23 13:03 srieas

i agree this feature should be implemented in request fixture , as we need to do the performance of the api

fayasfb avatar Sep 06 '23 08:09 fayasfb

Another workaround is to use testStep.duration: https://playwright.dev/docs/api/class-teststep#test-step-duration

brunojbarros avatar Sep 25 '23 19:09 brunojbarros

Feature ought to be integrated within the request fixture.

shashwatahalder01 avatar Dec 02 '23 13:12 shashwatahalder01

Hey folks! Could you share a little more about your usecases? Specifically I'm curious about the granularity of timing you need. Do you care about the full roundtrip time, or also about time to first byte or time taken by a potential TLS handshake?

Skn0tt avatar Sep 13 '24 06:09 Skn0tt

Hey folks! Could you share a little more about your usecases? Specifically I'm curious about the granularity of timing you need. Do you care about the full roundtrip time, or also about time to first byte or time taken by a potential TLS handshake?

It would be ideal to have something similar to what k6 has: https://grafana.com/docs/k6/latest/examples/get-timings-for-an-http-metric/

At least just the duration.

brunojbarros avatar Sep 13 '24 14:09 brunojbarros

@brunojbarros thanks for getting back to me. I'm curious, are you performing load testing? Could you share a little bit more about your usecase?

Skn0tt avatar Sep 27 '24 12:09 Skn0tt

@brunojbarros thanks for getting back to me. I'm curious, are you performing load testing? Could you share a little bit more about your usecase?

Not really.

Currently, we do not have robust performance testing with any tool, but we want to know how APIs perform under low load (we have over 500 API tests with 8 workers), so we take the opportunity to find out when we run automated tests expecting that the time stays under a second.

brunojbarros avatar Sep 27 '24 16:09 brunojbarros

Alright, thanks! Playwright doesn't have elaborate performance testing tooling currently, but I think in your specific case you could write a wrapper method on top of APIRequestContext#fetch that records the time before and after the request and then do soft assertion on the duration.

Skn0tt avatar Oct 02 '24 08:10 Skn0tt

Why was this issue closed?

Thank you for your involvement. This issue was closed due to limited engagement (upvotes/activity), lack of recent activity, and insufficient actionability. To maintain a manageable database, we prioritize issues based on these factors.

If you have additional information not present in this issue that you think will help prioritizing it, please open a new issue and reference this one. More support or clarity on its necessity may prompt a review. Your understanding and cooperation are appreciated.

pavelfeldman avatar Sep 08 '25 18:09 pavelfeldman