0

Basically what I need to do is to get a config file from a csv file and load it as an array into a global variable each time I am running tests in before function.

Lets say mynightwatch.conf.js contains following, example global variable myGlobalArr

 "globals": {
     myGlobalArr : []
 }

And in globals.js I am using readFileSync to read a file and get it's text as an array to a variable

before: function(done) {
   var file = fs.readFileSync('path').toString().split('\n')
}

How can I pass an array which is stored in file to myGlobalArr and then call it from inside a Page Object to use it?

Thanks

Kropek
  • 31
  • 1
  • 1
  • 3
  • Your requirement is that you have different global variables for each test and want to read them from respective files in before function and load them as globals. is that right? – Raju Feb 19 '20 at 19:22
  • Yes, that is correct - Right now I am using **require** in Page Objects for config files which data is static (like login or password) however I need a separate config file for data which I need for tests, however they are changed every week/month so I don't want to edit config files, but to put a generated config file with 'dynamic' data in selected path. – Kropek Feb 19 '20 at 19:31
  • any specific reason you want to have it as a csv file. I am sorry for asking too many questions. But I am trying to help you with easier solution. Please check https://stackoverflow.com/a/31274229/3879644 – Raju Feb 19 '20 at 21:13

0 Answers0