tzurp / performance-total

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

Documentation/Example with @wdio/cucumber-framework #19

Closed ashishjindal13 closed 3 years ago

ashishjindal13 commented 3 years ago

Hi, Can you please add/point to the working example of @wdio/cucumber-framework with performance total. I have tried using latest version of performance with wdio v6 but unable to bring it in running state. Every-time the results are coming as empty. I also tried to find a working example but couldn't find any for cucumber.

tzurp commented 3 years ago

Hi @ashishjindal13

  1. Please tell which version of PerformanceTotal is installed in your project?
  2. Is the problem related to cucumber only? Have you tried it with mocha/jasmin?
  3. Can you attach the code that contains the plugin usage?
ashishjindal13 commented 3 years ago

Hi @tzurp,

First of all apologies for the late reply. Following are the details:

  1. I am using 1.0.10-2
  2. yes it is with cucumber only, worked fine with mocha.
  3. Sample code is here: perfTotal.zip
tzurp commented 3 years ago

@erwinheitzman in your previous PR we used the following code to get the Cucumber test status:

afterScenario({ result }: any) {
        let status = false;

        if (result.status === Status.PASSED) {
            status = true;
        }
// ...
    }

It is not working anymore and result is undefined inside the hook. I couldn't find a way to get the test status for Cucumber. Can you please check it?

erwinheitzman commented 3 years ago

I checked but this is something you could easily have done so by installing the latest version of WebdriverIO and run the CLI and select Cucumber. Adding a console log to the config and run it to see that instead of an object, it's now the world object for the first parameter and the second parameter is the result object so I think you should be able to fix this very easily :)

tzurp commented 3 years ago

Thanks @erwinheitzman. Indeed I can get the test status for cucumber Scenario for the latest wdio version 7, but couldn't find a way to make it work in wdio v6. This is probably the reason it didn't work for @ashishjindal13, because he is using wdio v6. Do you think that the wdio team would manage this issue or should I restrict my plugin to ver >=7.x ?

erwinheitzman commented 3 years ago

There's two ways to solve this:

Make your plugin restricted or support both by checking the objects and based on what you receive you know how to handle the incoming data

Major versions (almost) always contain breaking changes, else it could be a minor or fix version. If you rely on other software you have to keep in mind these things :)

tzurp commented 3 years ago

@ashishjindal13 as @erwinheitzman suggested I forked a version for WebdriverIO v6. If you're using WebdriverIO v6, install version 1.x.x (currently v1.1.1). If you're using WebdriverIO v7, install version 2.x.x (currently v2.0.2). Please give a feedback after you're testing it. Thanks.

ashishjindal13 commented 3 years ago

Thanks @tzurp, the results are getting generated when i use v1.1.1 but if i split my steps like below then only Startup transaction is coming in results and Startup-1 is not captured. I wanted to have a transaction start and them perform some steps (not in the same function) and then stop the txn. Is that something can be achieved as well ?

Steps from feature file: Given I performance test And I navigate And I end performance test

Steps def: const { Given, When, Then } = require("cucumber"); const {performancetotal} = require("wdio-performancetotal-service");

Given(/^I performance test$/, () => { performancetotal.sampleStart("Startup"); browser.url("https://github.com/"); performancetotal.sampleEnd("Startup"); performancetotal.sampleEnd("Startup-1");

});

Given(/^I navigate$/, () => { browser.url("https://www.npmjs.com/package/wdio-performancetotal-service/v/2.0.2");
});

Given(/^I end performance test$/, () => { performancetotal.sampleEnd("Startup-1");
});

Results: name,averageTime,sem,repeats,minValue,maxValue,earliestTime,latestTime Startup,2481,133,3,2234,2691,"7/21/2021, 10:42:40 PM","7/21/2021, 10:55:41 PM"

perfTotal.zip

tzurp commented 3 years ago

@ashishjindal13 Sure you can! what you missed is to start "Startup-1". If you have only sampleEnd(smapleName) without the corresponding sampleStart(sampleName) then performancetotal ignores it.

ashishjindal13 commented 3 years ago

HI @tzurp, Thanks for the reply. I started the "Startup-1" in first call I performance test as follows:

performancetotal.sampleStart("Startup"); browser.url("https://github.com/"); performancetotal.sampleEnd("Startup"); performancetotal.sampleEnd("Startup-1");

I also attached the repo in the earlier reply if you want to take a look.

tzurp commented 3 years ago

Follow this fix to your code:

// TODO: you missed this line...
performancetotal.sampleStart("Startup-1");

performancetotal.sampleStart("Startup");

browser.url("https://github.com/");

performancetotal.sampleEnd("Startup");

// TODO: more logic here

performancetotal.sampleEnd("Startup-1");
tzurp commented 3 years ago

@ashishjindal13 tell me if we can close this issue on your behalf

ashishjindal13 commented 3 years ago

Hi @tzurp , Thanks for getting back and the followup. Just to be on same page the above suggested approach still d'not generate the results for "Startup-1" as i am executing 3 steps as follows. I assume the context is lost as soon as the method is changed. However this is also fine, i can survive with one function approach as well.

Please feel free to close the issue as required.

Thanks for your time and efforts.

Given(/^I performance test$/, () => { performancetotal.sampleEnd("Startup-1"); performancetotal.sampleStart("Startup"); browser.url("https://github.com/"); performancetotal.sampleEnd("Startup");

});

Given(/^I navigate$/, () => { browser.url("https://www.npmjs.com/package/wdio-performancetotal-service/v/2.0.2");
});

Given(/^I end performance test$/, () => { performancetotal.sampleEnd("Startup-1");
});

tzurp commented 3 years ago

@ashishjindal13 you're right, you must stay in the same scenario context in order to measure performance samples. Thanks. I'm closing the issue.