Ask a Question

Project Variable

SOLVED
Krishna_Kumar
Contributor

Project Variable

Hi Team,

i am trying to Create a object at run time and pass the same object for all other script.

for example,

in Method1 - i have created an excel object(Excel.Applilcation)

in Method2 - i want to access the object which is created in Method1 without creating the object again.

 

is it possible to store the created object in project variables and access them?

 

please help me out.

 

Kind Regards,

Krishna

4 REPLIES 4
tristaanogre
Esteemed Contributor

Yes.  Create a project variable of the "Object" type.  That should allow you to store the object.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

@tristaanogre ,

Thank you:)

Let me try it.

 

Kind Regards,

Krishna

Hi @Krishna_Kumar ,

 

initialize all your required objects in the OnStartTest Event handler and assign the same objects to a project variable in the same time, 

and after that were ever you want you van use the required object by assigning a new temperory variable,

 

please refer the below code snippet for your reference and let me know if your problem is solved.

//Event Handler
function GeneralEvents_OnStartTest(Sender){
    if(Project.Variables.VariableExists("MyObject"))
       Project.Variables.RemoveVariable("MyObject") 
    Project.Variables.AddVariable("MyObject", "Object");
    Project.Variables.MyObject = Sys.OleObject("Excel.Application")
}

//Accessing the Project Variable in different script Routine
function testingprojectVariable()
{
  excelApp = Project.Variables.VariableByName("MyObject")
  excelApp.Workbooks.Open("C:\\Users\\sathishkumark\\Desktop\\Source.xlsx")
  excelApp.DisplayAlerts = true
////Your Excel Operations...
.............. }

Hi @Mr_Bro ,

 

Thank you very much for the code sample.

i got the solution for my problem.

 

Kind Regards,

Krishna

cancel
Showing results for 
Search instead for 
Did you mean: