While running my protractor
tests , I came up with this scenario, where I had to export a variable from one of my POM file to another. For example, let us suppose file.js
is the file where the variable is defined as
file1.js
var xy = some_random_8chars;
...
...
module.exports={
//other module exports
exportvar1 : xy
}
Now, I need to import this in my file2.js
to access the value of xy
. So I'm doing this in my file2.js
var ximport = require('file1.js');
var use_new_value = ximport.exportvar1;
console.log(use_new_value) ;
As per my understanding, this should be printing some_random_8chars
. However my console shows undefined
, which I am failing to understand. Where I am going wrong?