CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

[Question] Steps file variable scope.

Open waryhermit opened this issue 9 years ago • 2 comments

What are you trying to achieve?

I am trying to make a login function in the steps file. The first time the login function is used, you are redirected to a page to fill out more information. I want to either check the URL or record the number of times the login function has been used so I know if the data page needs to be filled out.

Right now I am trying to use a variable to track the number of times the login function is called, but I can't figure out the variable scope of return actor(... What what be the best way to do this sort of thing in codeceptjs?

waryhermit avatar Jan 20 '17 15:01 waryhermit

actor is registered globally so it is a singeleton.

I think you can just store the counter inside a custom_steps.js and they should persist between tests.

DavertMik avatar Jan 21 '17 03:01 DavertMik

Yep, thought I had tried that but I had done it wrong, I had used this and not var.

module.exports = function () {
  this.runcounter1 = 0; // doesn't work
  var runcounter2 = 0; // works

Thanks

waryhermit avatar Jan 21 '17 13:01 waryhermit