Measuring time between steps
I need to measure time elapsed between some steps in a scenario.
I used plain functions to save and retrieve time, and tried to wrap them in a helper, but I'm really confused about steps executing order.
Looks like measuring steps are executed right after each other, not waiting for actions between them.
// something like
await I.doSomething()
I.saveTime() // my helper function
I.doSmthElse()
time = await I.grabDifference() // also my helper fn
I.say(time) // says 0, but sufficient time actully passes between actions.
But all of this got executed simultaneously, and only after all steps are called the actions in a browser are starting to occur. Except for async functions, they seem to execute just when called.
Can you help me to understand, how should I implement those measurments so it will occur just where I need them? Or maybe there is a solution already.
Why don’t you just extract the time in reports? I guess it would be elegant way to achieve what you need. :)
Thanks, I will try it Is it really impossible to do that with simple helper functions?
@iljao or you can use the exposed apis from codeceptjs that brings you the step objects. Extracting the time from there and calculating the time as you wish. More info can be seen here https://codecept.io/hooks#event-listeners
const event = require('codeceptjs').event;
event.dispatcher.on(event.step.finished, function (step) {
console.log(`this is startTime: ${step.startTime}`);
console.log(`this is endTime: ${step.endTime}`);
});
Thanks, I thought about using events too. But actually, my helper works fine, I just messed up some selectors in wiatForDetached :). Sorry :)
@iljao Do you have any more questions? Can I close this issue?