Accessing variable from 1 test file to other - is it possible? #2686
Replies: 1 comment 1 reply
-
HI, I do the following. I create a json file with a dummy variable then update that value using fs. Example var fs = require('fs');
}); basically this "opens/reads" the file named dataShared.js, then replaces the dummy variable "Invoice_Number" with the variable Invoice Here is a copy of the exampe dataShared file where Invoice_Number would get updated. You have to reset this file for every run, but if running on jenkins the base file would be checked into code anyway and always be used. module.exports = { value: { BankJournal:'Bank_Number',//Bank _Number } Then in other code you can read in that value as you would any value from a json file. Hope this helps. -J |
Beta Was this translation helpful? Give feedback.
-
Hi All,
Need to know if I can export a variable from 1 file and then use it in another?
I have flow like this :
My test file 1 (01_Test_tc_full.js):
module.exports = {
'Test1: Verify nodeid.': function (browser) {
var var1;
},
};
Here i checked by console.log statement, that the return value from the custom command is properly stored in var1.
But now i want to use this var1 in the second file also.
second file (02_Test_tc_full.js):
const sourceFile = require('./01_Test_tc_full');
module.exports = {
'Test2: Verify nodeid again from first file.': function (browser) {
console.log("From testcase2");
console.log(sourceFile.var1);
},
};
In the second test file, it prints undefined? how can I get value from the first file to be available in the second file? I'm running files sequentially, I mean i provide a test folder for execution, it runs script 1 after another.
Let me know? any help is appreciated.
Bhavesh
Beta Was this translation helpful? Give feedback.
All reactions