How to export a function from one unit to another unit in JavaScript.
Hi Everyone, I'm trying to export a function from one unit to another unit, i used "module.exports.Test1 = Test1;" command in the unit1 to export Test1 function and used "var objin = require("Data1");" command to make it availble in unit2. i want to assign the Test1() funtion to a variable in the unit2. "let arrValues = objin.Test1();" i used this command to make it happen. but it's not working. can somebody help me export a funtion from external unit and how to use the function in another unit/funtion. Data1 (unit1): function Test1() { var driver = DDT.CSVDriver("C:\\Users\\75\\Desktop\\Data.csv"); var firstname_col = []; // var lastname_col = []; //let value1 = Project.Variables.Data.Value('FIRST NAME'); //let value2 = Project.Variables.Data.Value('LAST NAME'); for (i=0;i < driver.ColumnCount; i++) { firstname_col.push(driver.Value(i)); } DDT.CloseDriver(driver.Name); return firstname_col; } module.exports.Test1 = Test1; Data2(Unit2): var objin = require("Data1"); //USEUNIT Data1 function test() { var driver1 = DDT.CSVDriver("C:\\Users\\13175\\Desktop\\Data.csv"); let arrValues = objin.Test1(); //objin.Test1(); for (let l = 0;l < driver1.RowCount; l++) { let url = "http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_button_type"; Browsers.Item(btIExplorer).Run(url); let page = Sys.Browser("*").Page("*"); aqUtils.Delay(1000); let first_name = page.EvaluateXPath("//*[@id='fname']"); first_name[0].Click(); Sys.Keys(arrValues[l]); let last_name = page.EvaluateXPath("//*[@id='lname']"); last_name[0].Click(); Sys.Keys(arrValues[l+1]); // Call the function var arr = page.EvaluateXPath("//*[@type='submit']"); arr[0].Click(); aqObject.CheckProperty(Aliases.browser.pageTryitEditorV36.frameIframeresult.textnode, "contentText", cmpEqual, "The server has processed your input and returned this answer."); // DDT.CloseDriver(driver.Name); page.Close(); } } Thanks, BinnuSolved3KViews0likes6Comments