Forum Discussion

Jack_meng's avatar
Jack_meng
Occasional Contributor
6 years ago
Solved

the value of variable losses

I need some help,  In my script I use Runner.stop(true) to exit current script if something goes wrong,  but the value of  a previous variable which should be used in behiend script become empty. (I debugged the variable losses).

 

My question is how I can reserve its value for using in behiend sctipts.

 

Thanks

  • Adding OnStartTest Event for initializing my global variable to fix this issue

3 Replies

    • Jack_meng's avatar
      Jack_meng
      Occasional Contributor

      Hi AlexKaras,

      Thank you for your response. I did not describ my question clearly.  I don not use variables object in my script, I just create a variable(it is an object) in a script, init it at first ,  then other scripts use its value. 

      Fake code:

       

      script1
      let obj = {}; function initObj() { obj.xxx = yyy; .... } function getObj() { return obj; }
      module.exports.initObj= initObj;
      module.exports.getObj = getObj;

      other sctipts
      var script1 = require("script1");
      function test() {
      let obj = script1.getObj;
      ...
      }

       

      The question is once one script meet exception stopped by Runner.stop(true),    those script behind it can not get the value of obj.

       

      Why can not I get its value?

       

      Regards,
      Jack

       

       
      • Jack_meng's avatar
        Jack_meng
        Occasional Contributor

        Adding OnStartTest Event for initializing my global variable to fix this issue