tzurp / performance-total

This WebdriverIO service is used to analyze performance of any test flow.
16 stars 2 forks source link

[Feature Request] Add method to get sample duration #30

Closed therealbrad closed 2 years ago

therealbrad commented 2 years ago

I'd like to make assertions that samples fall within a specific amount of time. Something like:

performancetotal.sampleStart("Log In");
await expect(HomePage).toBeDisplayedInViewport();
performancetotal.sampleEnd("Log In");
// Home Page is displayed within 1 second.
await expect(performancetotal.sampleTime("Log In")).toBeLessThan(1000)

Maybe there's already a way to do this and I'm missing it?

tzurp commented 2 years ago

@therealbrad thanks for your request! The power of performance-total is that it gives you full statistic results on a batch of data, which is the only true way to analyze performance of a scenario. What you're looking for is achievable, for example, by doing this:

const loginStart = Date.now();
await expect(HomePage).toBeDisplayedInViewport();
const loginEnd = Date.now();
// Home Page is displayed within 1 second.
await expect(loginEnd - loginStart).toBeLessThan(1000);

If you don't find this solution satisfying, we can try to refine the request.

therealbrad commented 2 years ago

@tzurp Yes, I am collecting the performance data in a report, but I also want to fail the test if a performance metric is outside of some bounds. Since the info already exists in the performancetotal object, I figured I could just access that instead of making my own.

tzurp commented 2 years ago

@therealbrad I added an option to get the timespan for a specific sample (in v2.1.2): const timeSpan = performancetotal.getSampleTime("YourPerformanceTag");.

If the tag is not found or the call is taking place before sampleEnd, it would return 0.

Thanks!

Tzur

therealbrad commented 2 years ago

@tzurp Thank you! Just what I was looking for.

jt-brevitaz commented 5 months ago

@tzurp

Actually I was stuck somewhere on this method and wanted to discuss with you before raising a bug to make sure am I missing anything by the output of this method: getSampleTime()

This are details from one of my performance test case: index: 1, test case label: abcd, brName: general, avgTime: 20346, sem: 10327, repeats: 3, minValue: 8698, maxValue: 40941

based on this values can you please provide me the o/p value by this method ? lemme know if you need more data. Thanks!

tzurp commented 5 months ago

@jt-brevitaz getSampleTime() gives you the current single performance measurement and it should be used for very specific needs. Most users don't use this feature because a single value can't be statistically analyzed.

jt-brevitaz commented 5 months ago

@tzurp Yeah, but I want to know how it calculates time.

tzurp commented 5 months ago

@jt-brevitaz sure, it simply returns the time gap of the current performance pair (start/end). Let's say you measured some event and want to get the value in your test, then you can simply use getSampleTime.