cancel
Showing results for 
Search instead for 
Did you mean: 

Project Variable

SOLVED
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

1 ACCEPTED SOLUTION

Accepted Solutions
Contributor

Re: Project Variable

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...
.............. }
Regards,
Sathish Kumar K

View solution in original post

4 REPLIES 4
Community Hero

Re: Project Variable

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


Robert Martin
[Community Expert Group]
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
Extensions available
Contributor

Re: Project Variable

@tristaanogre ,

Thank youSmiley Happy

Let me try it.

 

Kind Regards,

Krishna

Contributor

Re: Project Variable

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...
.............. }
Regards,
Sathish Kumar K

View solution in original post

Contributor

Re: Project Variable

Hi @K_Sathish_Kumar ,

 

Thank you very much for the code sample.

i got the solution for my problem.

 

Kind Regards,

Krishna