cancel
Showing results for 
Search instead for 
Did you mean: 

Calling variable from another script

SOLVED
nedbacan
Contributor

Calling variable from another script

Can someone help me understand how to pass a variable to another test using JAVA SCRIPT in TEST COMPLETE?

 

How can I create another script (Unit2) that will use the value stored in MyFolderName created in Unit 1?

 

Use Case from Unit 1 

  1. User clicks on the create button on the GUI => a folder is created and a test.txt file is created.
  2. Find what folder name it is and store it in "MyfolderName" and search in that folder for test.txt
  3. Next call Unit2  (see below)

<Repeat test Unit 1>

  1. User re-clicks on the create button on the GUI  => a 2nd folder is created and a test.txt file is created.
  2. Find what folder name it is and store it in "MyfolderName" and search in that folder for test.txt
  3. Next call Unit2  (see below)
  4.  

User Case from Unit 2

  1. Take folder1, create a readme.txt and write to the file
  2. Take folder2, create a readme.txt and write to the file
  3.  

Please excuse me, I am just learning, and providing a sample will greatly help me understand it.   

 

Your help is greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
BenoitB
Community Hero

Re: Calling variable from another script

Hello,

 

I advice you to create a global object holding all of your variables and then using it by Globals.myvariable.

 

file 1: globals.js

var

  Globals = {};

  Globals.myFolderName = "d:\\rootdirectory\\";

 

file 2 : unit1.js

//USEUNIT globals

 

Globals.myFolderName = "c:\\temp\\";

 

file 3 :  unit2.js

//USEUNIT globals

//USEUNIT unit1

 

Log.Message("My folder is "  + Globals.myFolderName);  // -> c:\temp

 

 

 

Un sourire et ça repart

View solution in original post

1 REPLY 1
BenoitB
Community Hero

Re: Calling variable from another script

Hello,

 

I advice you to create a global object holding all of your variables and then using it by Globals.myvariable.

 

file 1: globals.js

var

  Globals = {};

  Globals.myFolderName = "d:\\rootdirectory\\";

 

file 2 : unit1.js

//USEUNIT globals

 

Globals.myFolderName = "c:\\temp\\";

 

file 3 :  unit2.js

//USEUNIT globals

//USEUNIT unit1

 

Log.Message("My folder is "  + Globals.myFolderName);  // -> c:\temp

 

 

 

Un sourire et ça repart

View solution in original post

New Here?
Join us and watch the welcome video:
Top Kudoed Authors