[Question] Is there a way to return an api request response time?
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?
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.
Did you see this info? Maybe it can helps you https://playwright.dev/docs/api/class-request#request-timing
@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
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 😄
+1
i agree this feature should be implemented in request fixture , as we need to do the performance of the api
Another workaround is to use testStep.duration: https://playwright.dev/docs/api/class-teststep#test-step-duration
Feature ought to be integrated within the request fixture.
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?
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 thanks for getting back to me. I'm curious, are you performing load testing? Could you share a little bit more about your usecase?
@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.
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.
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.